Issue with the "Run a FastAPI app" doc
Closed this issue · 10 comments
I found an issue with this document.
Title: Run a FastAPI app
Location: https://fly.io/docs/python/frameworks/fastapi/
Source: https://github.com/superfly/docs/blob/main/python/frameworks/fastapi.html.markerb
Describe the issue
For me poetry add fastapi
doesn't seem to activate the virtualenv that's created and as a result I get this:
$ fastapi dev
zsh: command not found: fastapi
Addtional info
I think this is the missing step that needs to be added after poetry add
to all Python tutorials?
$ poetry shell
I'm not a poetry user, so not sure.
Also I think it would be nice if you did at least one of the tutorials just with the standard tools python -m venv
and pip install
. I presume fly works just fine with them. Will try now .
hey! thanks for the feedback! I'll make this change soon'ish - the consideration here is that there should be no surprises across different frameworks. Right now we stick to poetry
in the docs as it seems like the most popular and modern dependency management tool; but you are totally right about the fact that there's loads of people that use something else.
I'll see how difficult it is to get something like a toggle box for every dependency manager that we support - that seems like the ideal solution to me :)
Hi, thanks!
I think in Python there's too many Python package managers - more than 10 in active use in the community.
See e.g. https://packaging.python.org/en/latest/guides/tool-recommendations/ but there's more just https://pixi.sh/ to name a good one.
So I wouldn't recommend to try to write and support all as variants in the fly docs.
My suggestion here was to fix the poetry docs with the missing command, and to add one example / page how to use the standard tool - which is since 10+ years pip.
At https://fly.io/docs/python/the-basics/multi-stage-builds/ you write:
With this setup our image will be around 200MB most of the time (depending on what else you include). This setup is used for nearly all Python apps you deploy on Fly.io.
If I follow the official docs examples for Django, FastAPI, etc pp with almost empty "hello world" app I get 400-700 MB depending on the framework I use.
Am I doing something wrong or is that simply the required size from the Python frameworks to get them working?
So I wouldn't recommend to try to write and support all as variants in the fly docs.
Agreed! I think it'd be nice if we could show the top 3 or 4 ones based on the super-representative metric of github stars though.
Am I doing something wrong or is that simply the required size from the Python frameworks to get them working?
I'd need a bit more info to answer that:
- can you link me the repo? (some frameworks indeed have a bigger footprint, but I don't think it should ever be that big of a difference)
- can you tell me which version of flyctl you are running? (the dockerfile optimization came a bit after introducing python support)
I'm running this:
$ fly version
fly v0.2.94 darwin/arm64 Commit: 1bdffec08d15cc402927fa42eef47eec7e851dbf BuildDate: 2024-07-22T18:52:06Z
I was just following the steps in your docs for now e.g. at https://fly.io/docs/python/frameworks/fastapi/#deploy-a-fastapi-app-from-scratch to get hell-world apps in the Python frameworks.
I do have one example at https://github.com/cdeil/fly-panel with pip and Panel which has 700 MB docker image.
Maybe I'm just doing something wrong.
If you mention sizes you get for some examples I could check - I mean should be identical and if can be few 100 MB would be very nice in terms of speed and cost for users and you from Fly platform, right?
From what I know Alpine is not a good option for Python or at least didn't used to be ( https://pythonspeed.com/articles/alpine-docker-python/ )
I deployed the app as-is from your repo and got this:
--> Pushing image done
image: registry.fly.io/fly-panel-test-shy-resonance-2950:deployment-01J3FY9GJNZWEGE7055HMJFG81
image size: 464 MB
from what I can tell, panel
comes with a pretty big dependency footprint, which is what you're seeing. I'm unsure why we have a 300mb difference though.
From what I know Alpine is not a good option for Python
the runtime image we use is bookworm-slim
- that seems like the best option at the moment
I got 721 MB image: https://fly.io/apps/fly-panel-test/machines/9185e01c7e4e38
Is it possible that there are some files that you do not track in git that get added to the docker image?
For instance, if there's a local .venv
folder or something alike, that could explain the difference in size. You could omit these files using a .dockerignore
file
With regards to this issue, I will close it as per #1716
The setup docs now specify the 2 ways in which you can either activate the shell or run a one-off command from the shell: https://fly.io/docs/python/the-basics/initial-setup/#dependency-management