mojo
mojo copied to clipboard
[Feature Request] Add Django and FastAPI compatibility
Request
Add to Mojo, support for Python backend development frameworks like Django and FastAPI
Motivation
The same reason people use Python for backend development! You don't need to learn another programming language to be able to put your ideas on the internet
Description and Requirements
Be able to create RestAPIs, manage relational databases...
Or providing an alternative webserver implementation (so that you don't have to use python unless you want to/have to) would also work. Happy to contribute here if needed!
This is a great idea, but I'm not sure it is super actionable right now. Mojo can already talk to all the existing python apis, so these should (in principle) already work. I think the more interesting thing will be to develop mojo native apis for this use-case, which will be pretty epic. OTOH, this will be true for /tons/ of domains, and I don't think we should track all of them. We should keep building out the language and as it gets more filled out, we can explore these things.
Thank you for filing this though, super exciting time!
so nice idea!
The man himself so happy about mojo and having great community 👏
setup
python install via mise use [email protected]
i used it directly since poetry
.venv
don't create .so
. ref https://github.com/modularml/mojo/issues/551
then pip install fastapi
result
today i can run
from python import Python
import sys
def main():
fa = Python.import_module("fastapi")
app = fa.FastAPI()
print("FastAPI __version__:", fa.__version__)
~/UnixDev/fastapi-mojo is 📦 v0.1.0 via 🐍 v3.11.7
❯ '/home/nam/.modular/pkg/packages.modular.com_mojo/bin/mojo' '/home/nam/UnixDev/fastapi-mojo/main.mojo'
FastAPI __version__: 0.109.0
on my WSL2 latest.
adding a route
from python import Python
import sys
def main():
fa = Python.import_module("fastapi")
app = fa.FastAPI()
print("FastAPI __version__:", fa.__version__)
@app.get("/")
def read_root():
return {"Hello": "World"}
this is not working. Below are errors.
'/home/nam/.modular/pkg/packages.modular.com_mojo/bin/mojo' '/home/nam/UnixDev/fastapi-mojo/main.mojo'
/home/nam/UnixDev/fastapi-mojo/main.mojo:2:5: error: unexpected tokens after decorator, each need to be on their own line
def read_root():
^
/home/nam/UnixDev/fastapi-mojo/main.mojo:3:16: error: TODO: cannot emit dictionary literals yet
return {"Hello": "World"}
^~~~~~~~~~~~~~~~~~
/home/nam/UnixDev/fastapi-mojo/main.mojo:1:2: error: use of unknown declaration 'app'
@app.get("/")
^~~
/home/nam/.modular/pkg/packages.modular.com_mojo/bin/mojo: error: failed to parse the provided Mojo
Why this issue is closed?
Why this issue is closed?
idk. i should reopen i guess.
It's will be great if we could to use Mojo for backend development with FastAPI/Django the way people use Typescript with React/Vue/Node/ etc.
It's will be great if we could to use Mojo for backend development with FastAPI/Django the way people use Typescript with React/Vue/Node/ etc.
I am expecting similar phenomenal like Elysia typescript on bun-zig.
I want to see/make a new pythonic fastest web framework on planet.
I am so excited for this 🔥
Is this issue resolved ?
I'm transitioning from Python to Mojo and would like guidance on setting up an endpoint with Mojo.
What's happening here? Why is this closed, does it work with both FastAPI and Django?
API Endpoints are very important for ML/AI workflows or any web app for that matter. This should be prioritized IMHO.
This is high prio from my point of view
Looking forward to this!!!
looking forward to this too
Looking forward to this. It could entirely change the way we build backends. At least just FastAPI support will be great.
Why is this closed?
Looking forward to this too. The reason have been already enriched by above peoples.
+1!!!
I'm currently planning to migrate my FastAPI servers into Mojo too.
any updates ?