How to run with Fastapi/Uvicorn #2629
-
a small hy script by Fastapi and uvicorn
When run it, got
uvicorn runs failed, seems it can't recognize "app:app" I guess, I have no idea how to fix it since the python version is ok. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
I haven't used these libraries, but if they expect a Python script, try giving them a minimal Python script that imports your Hy code. |
Beta Was this translation helpful? Give feedback.
-
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:
Off topic: |
Beta Was this translation helpful? Give feedback.
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:
put application script into its own package, e.g.
__init__.py
: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'
Write a launch script,
If in python, make sure
import hy
before you calluvicorn.run
:If in hy, you don't have to…