Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get Fast API working #642

Open
michaelachrisco opened this issue Mar 20, 2025 · 1 comment
Open

Unable to get Fast API working #642

michaelachrisco opened this issue Mar 20, 2025 · 1 comment

Comments

@michaelachrisco
Copy link

michaelachrisco commented Mar 20, 2025

See here:

I tried to get fast api working with codon. I like the idea of getting quite a bit of speed out of python.

fastapi/fastapi#10096

This is probably user error but I was not able to get their sample hello world running with codon. It might be a dependency issue?

Here is the simpliest code I could come up with:


from python import fastapi as fast

from typing import Union

#from fastapi import FastAPI

app = fast.FastAPI()


@app.get("/")
def read_root():
      return {"Hello": "World"}

I also tried without the decorator with the same error below:

from python import fastapi as fast

from typing import Union

app = fast.FastAPI()


def read_root(request):
    return {"Hello": "World"}

app.router.add_api_route("/", read_root, methods=["GET"])

Error:

codon run main.py
PyError: ((), ()) is not a callable object

Raised from: pyobj.exc_check:0
/root/.codon/lib/codon/stdlib/internal/python.codon:1198:13

Backtrace:
  [0x7f37143126b7] pyobj.exc_check:0.882 at /root/.codon/lib/codon/stdlib/internal/python.codon:1198:13
  [0x7f37143126f0] pyobj.exc_wrap:0[Ptr[byte],Ptr[byte]].883 at /root/.codon/lib/codon/stdlib/internal/python.codon:1201:9
  [0x7f3714313a60] pyobj:pyobj.__call__:0[pyobj,Tuple[Partial.N.read_root:0[read_root:0,Tuple,KwTuple.N0]],KwTuple.N0].1033 at /root/.codon/lib/codon/stdlib/internal/python.codon:1225:68
  [0x7f37143153d2] main.0 at /workspace/fast-api/main.py:11:1
Aborted

I made sure export CODON_PYTHON=/usr/lib/python3.12/config-3.12-x86_64-linux-gnu/libpython3.12.so is populated and other codon examples from the main site works on the machine. Im using ubuntu:latest docker container but was able to reproduce on a bare metal ubuntu machine as well.

Any ideas?

@arshajii
Copy link
Contributor

Hi @michaelachrisco -- thanks for the question. For this type of use case, it probably makes more sense to use Codon's JIT mode, which would allow you to decorate functions you want to accelerate with @codon.jit and then run the code normally through Python. Another option would be to use Codon's Python extension backend, which would avoid any compilation overhead at runtime. Let me know if this makes sense or if I can clarify anything further!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants