Skip to content

How to run with Fastapi/Uvicorn #2629

Answered by pyx
ryanking8215 asked this question in Q&A
Discussion options

You must be logged in to vote

Any library with its own import magic (dynamic loading from string via "importlib") would not work with standalone .hy script, as hy have no chance to setup the import hook, afaik.

Either:

  1. put application script into its own package, e.g.

      |--- todo
             |--- __init__.py
             |--- app.hy
    

    __init__.py:

    import hy  # noqa
    

    This way, when the harness script (uvicorn in this case) load the package, hy's import hook will be triggered, so you can uvicorn todo.app:app --reload --reload-include '*.hy'

  2. Write a launch script,
    If in python, make sure import hy before you call uvicorn.run:

    import uvicorn
    import hy  # noqa
    ...
    uvicorn.run("app:app", reload=True)

    If in hy, you don't have to…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@ryanking8215
Comment options

Comment options

You must be logged in to vote
7 replies
@ryanking8215
Comment options

@pyx
Comment options

@ryanking8215
Comment options

@ryanking8215
Comment options

@pyx
Comment options

Answer selected by ryanking8215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #2628 on February 04, 2025 13:17.