Quick start template repository for Python 3 using ASGI
- WSGI: Web Server Gateway Interface
- ASGI: Asynchronous Server Gateway Interface
ASGI includes asynchronous serving methods while WSGI does not.
WSGI applications are a single, synchronous callable that takes a request and returns a response; this doesn’t allow for long-lived connections, like you get with long-poll HTTP or WebSocket connections.
Even if we made this callable asynchronous, it still only has a single path to provide a request, so protocols that have multiple incoming events (like receiving WebSocket frames) can’t trigger this.
You can read more on this per the following link: Full ASGI PDF Documentation
- Asynchronous
- Performance
- Easy to use
- Well documented
$ gunicorn main:app -k uvicorn.workers.UvicornWorker -c uvicorn.conf.py --reload
[YYYY-MM-DD 00:00:00 +0000] [PID] [INFO] Starting gunicorn X.X.X
[YYYY-MM-DD 00:00:00 +0000] [PID] [INFO] Listening at: http://0.0.0.0:8000 (PID)
[YYYY-MM-DD 00:00:00 +0000] [PID] [INFO] Using worker: uvicorn.workers.UvicornWorker
Using gunicorn as process manager and uvicorn worker, the ASGI server is able to detect a change on Python code and automatically reload the server based on changes.
There're modern dependency management for Python
TODO: Added content for pip
TODO: Added content for pipenv
TODO: Added content for poetry
TODO: Added content for uv
For the deployment process, this repository includes 3 prototypes which are production ready. All of prototypes are based on GoogleContainerTools/distroless container images.
With introduction of Python 3.9, distroless has not yet upgrade their Python to the current stable yet (currenly at 3.7), I've used slim-buster
as an alternative for now until the distroless registry has caught up.