How do we import and use something like flask
Attempting to replicate this snippet of Flask/Python code in Mojo:
But I'm unsure how we replicate this in Mojo with the decorators and top level functions like this? Is it possible yet?
2 Replies
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:
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.GitHub
GitHub - msaelices/py2mojo: Automated Python to Mojo code translation
Automated Python to Mojo code translation. Contribute to msaelices/py2mojo development by creating an account on GitHub.
Modular Docs - Mojo🔥 programming manual
A tour of major Mojo language features with code examples.
Congrats @Quantum Nebula, you just advanced to level 1!