-
It would be great if we could use from Python a function defined in a Mojo file. For example it could be possible to create a Python native extension importable from Python by compiling AOT a Mojo file. Alternatively, there could be a mechanism to import a mojo file in Python. Something like from mojo import import_module
my_mojo_mod = import_module("my_mojo_mod")
result = my_mojo_mod.my_great_mojo_func(...) It seems to me that such kinds of interactions would help a lot adoption of Mojo by Python users. Do you plan to support such features? Note that this question is related to #546 |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 5 replies
-
currently, I've red somewhere that it's possible ... thru ctype ... |
Beta Was this translation helpful? Give feedback.
-
found it : |
Beta Was this translation helpful? Give feedback.
-
I think to do this, you would need to use the python C API and convert the python.h types to mojo equivalents. This is effectively the same as writing a C shared library using the types declared in the header (and the implementation details required). It would be really interesting though, if there was a way to have |
Beta Was this translation helpful? Give feedback.
-
I would love to be able to call libraries written in Mojo from CPython. I'm about to start writing a library for high speed IO & compute for chunked, compressed, multi-dimensional data. Some of the library's users (including me) are ML folks. But many of the library's users aren't doing ML. And some users are on highly constrained compute environments, where installing new software requires many months of discussions with overworked and understaffed IT departments. So, even though I'm excited about Mojo, I know I can't force users of my library to use Mojo. If CPython can't call Mojo then Mojo becomes "viral" like the GPL license. Code that uses Mojo forces all downstream users of that code to also use Mojo. I think that will harm adoption of Mojo! And I'd love to see Mojo do well! I'd love to see a super simple way for CPython users to install and use libraries written in Mojo! |
Beta Was this translation helpful? Give feedback.
-
The answer is that there is not yet a good and robust mechanism to use Mojo from Python. It should be added but Mojo is not ready yet. There is an issue about adding this feature to Mojo roadmap #1423 In the mean time, one can use hacks using ctypes/cffi, but IMHO this can't be used "in production". Anyway, Mojo is not ready yet to be used "in production" outside Modular. |
Beta Was this translation helpful? Give feedback.
The answer is that there is not yet a good and robust mechanism to use Mojo from Python. It should be added but Mojo is not ready yet. There is an issue about adding this feature to Mojo roadmap #1423
In the mean time, one can use hacks using ctypes/cffi, but IMHO this can't be used "in production". Anyway, Mojo is not ready yet to be used "in production" outside Modular.