Running FastAPI and Flask Web Services with Uvicorn/Gunicorn | NodeFlux.eu Docs
Deploy high-performance Python web applications and REST APIs using ASGI/WSGI production servers.
Steps
- For FastAPI: install fastapi and uvicorn in requirements.txt.
- For Flask: install flask and gunicorn in requirements.txt.
- Read PORT environment variable: port = int(os.environ.get("PORT", 8000)).
- For FastAPI, set uvicorn entry point: uvicorn.run("main:app", host="0.0.0.0", port=port).
- For Flask, set gunicorn start command: gunicorn -w 2 -b 0.0.0.0:$PORT main:app.
- Upload project files to your NodeFlux Python service.
- Start service and test web endpoints using your assigned host IP and port.
Notes
- Binding to 0.0.0.0 is required so container port mapping routes traffic to Python web workers.
- FastAPI natively generates interactive OpenAPI /docs documentation endpoints automatically.
Related NodeFlux pages
- Hosting Discord.py and Pycord Bots on NodeFlux — Deploy asynchronous Python Discord bots using discord.py or Pycord with environment variable security.
- Virtual Environments and requirements.txt Best Practices — Manage Python package dependencies efficiently using virtualenv, pip freeze, and pinned versions.
- Optimizing Python Memory Usage and Garbage Collection — Reduce Python RAM footprints on shared host containers by optimizing data structures and garbage collection.