modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.27k stars 2.59k forks source link

[Feature Request] Provide a way to call Mojo functions from Python #1210

Open shashankprasanna opened 1 year ago

shashankprasanna commented 1 year ago

Review Mojo's priorities

What is your request?

Mojo Python interop supports calling Python functions directly from Mojo. This is great for developers starting their projects in Mojo and leveraging the Python ecosystem to fill in the gaps for specific capabilities.

However, Python developers who want to accelerate compute intensive sections of their applications in Mojo don't have a clean or native way of doing this. This has been requested previously: https://stackoverflow.com/questions/77063677/how-to-pass-mojo-function-to-python-in-python-interop And as a doc clarification request: https://github.com/modularml/mojo/issues/621

What is your motivation for this change?

Reducing the barrier to leveraging Mojo's performance and capabilities without completely migrating projects.

Any other details?

No response

CloseChoice commented 1 year ago

This would be amazing. I am contributing to shap and and would like to move our C code to mojo in the future. The problem is that I would have to move the whole library to mojo which would basically be the end of it, since everybody else is using Python.

guidorice commented 1 year ago

🎉 this would be an awesome feature!

mrmattwright commented 1 year ago

Yes this would be absolutely terrific, We have couple of projects that have performance hot spots that swapping in a call to mojo would make an enormous difference, but the code base is large enough to mean a wholesale change to mojo would be a lengthy endeavour.

Also unrelated shout out @CloseChoice - very happy user of Shap! 🙏

morne commented 1 year ago

I would like this feature as well.

sa- commented 1 year ago

This is key to getting any adoption within the python community

gbtechnology commented 12 months ago

I think this is really needed if we want to really spread the adoption of Mojo to a faster rate. I bet majority of developers would like to have the possibility to use Mojo in their current python projects instead of importing python within Mojo.

haifeng-jin commented 11 months ago

This would be a killer feature! But would like to see what are the challenges of supporting this.

Prodesire commented 9 months ago

This is definitely a good idea! Although Python can be accelerated through methods such as using C and Rust, the languages are quite different and it is not easy to use. If this can be achieved, the syntax is very similar, and the development and operation efficiency can be greatly improved.

MamadouSDiallo commented 8 months ago

This is the feature that I am waiting for to jump on the mojo bandwagon. Can't wait to see this happen.

Moosems commented 7 months ago

Would be very useful when passing mojo functions as a callback

miili commented 3 months ago

This would be great! Some code bases are just too heavy to be moved completely to mojo, also those libraries are often utilized heavily downstream.

I would love to use Mojo to replace some heavy lifting CPython functions. First PoCs show a 3-4x speed up.

miili commented 2 months ago

@gabrieldemarmiesse, is there an update on this language feature?

MamadouSDiallo commented 2 months ago

@miili During the July 15th community meeting, they announced that it is the next big feature and it will start happening within the next three months. (https://www.youtube.com/watch?v=_QVs626Vn2k)