BmoVibe
BmoVibe
MModular
Created by denden on 9/15/2023 in #questions
Will imported python modules eventually be compiled by Mojo instead of relying on the python env?
I feel like once it becomes open source, we will see a rise in developers who can't sit around and wait for compatibility. That's just my opinion.
10 replies
MModular
Created by Innominus on 9/17/2023 in #questions
How do we import and use something like flask
I'm afraid at this moment, your options are unsurprisingly limited; but they may get you as far as you need depending on your project: A. If you're looking to import a python package without converting it to mojo, you can just call Python.import_module() with the module name:
from python import Python

# This is equivalent to Python's import numpy as np
let np = Python.import_module("numpy")

# Now use numpy as if writing in Python
array = np.array([1, 2, 3])
print(array)
from python import Python

# This is equivalent to Python's import numpy as np
let np = Python.import_module("numpy")

# Now use numpy as if writing in Python
array = np.array([1, 2, 3])
print(array)
Source: https://docs.modular.com/mojo/programming-manual.html#importing-python-modules B. If you want to convert a Python library to Mojo, a promising side project was started just 5 days ago by one of the developers that automates this process by converting Python 3.10 to Mojo. Since it's very new, you'll probably need to debug afterwards; but I would imagine the performance gains would be monumental. A link to that project can be found here: https://github.com/msaelices/py2mojo Keep in mind that you'll need to convert all of the dependencies too, so it might not even be worth it for projects like Flask. With that being said, I hope this at least answered some questions. Let me know how it goes.
3 replies