mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] Add Django and FastAPI compatibility

Open marquesdavi opened this issue 1 year ago • 1 comments

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...

marquesdavi avatar May 04 '23 02:05 marquesdavi

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!

sa- avatar May 06 '23 08:05 sa-

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!

lattner avatar May 06 '23 18:05 lattner

so nice idea!

Bronya0 avatar Oct 10 '23 09:10 Bronya0

The man himself so happy about mojo and having great community 👏

west-github avatar Oct 24 '23 16:10 west-github

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

wasdee avatar Jan 19 '24 13:01 wasdee

Why this issue is closed?

danielegaliffa avatar Jan 26 '24 07:01 danielegaliffa

Why this issue is closed?

idk. i should reopen i guess.

wasdee avatar Jan 26 '24 13:01 wasdee

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.

k00000han avatar Jan 31 '24 22:01 k00000han

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.

wasdee avatar Feb 06 '24 04:02 wasdee

I am so excited for this 🔥

munjed-ab avatar Feb 16 '24 16:02 munjed-ab

Is this issue resolved ?

I'm transitioning from Python to Mojo and would like guidance on setting up an endpoint with Mojo.

GokuSy avatar Feb 26 '24 22:02 GokuSy

What's happening here? Why is this closed, does it work with both FastAPI and Django?

Pyroseza avatar Mar 19 '24 22:03 Pyroseza

API Endpoints are very important for ML/AI workflows or any web app for that matter. This should be prioritized IMHO.

alew3 avatar Mar 26 '24 03:03 alew3

This is high prio from my point of view

Warrio111 avatar Apr 03 '24 20:04 Warrio111

Looking forward to this!!!

tares003 avatar Apr 06 '24 00:04 tares003

looking forward to this too

leejongheon42 avatar Apr 22 '24 05:04 leejongheon42

Looking forward to this. It could entirely change the way we build backends. At least just FastAPI support will be great.

ArunJRK avatar May 02 '24 06:05 ArunJRK