Python
Railpack builds and deploys Python applications with support for various package managers and dependency management tools.
Detection
Section titled “Detection”Your project will be detected as a Python application if any of these conditions are met:
- A
main.pyfile exists in the root directory - A
requirements.txtfile exists - A
pyproject.tomlfile exists - A
Pipfileexists
Versions
Section titled “Versions”Railpack supports Python 3.10 and later. We only officially support Python versions that are actively maintained by the Python Software Foundation (not EOL). See Python release status for current support status.
The Python version is determined in the following order:
- Set via the
RAILPACK_PYTHON_VERSIONenvironment variable - Read from mise-compatible version files (
.python-version,.tool-versions,mise.toml) - Read from the
runtime.txtfile - Read from the
Pipfileif present - Defaults to
3.13.2
Runtime Variables
Section titled “Runtime Variables”These variables are available at runtime:
PYTHONFAULTHANDLER=1PYTHONUNBUFFERED=1PYTHONHASHSEED=randomPYTHONDONTWRITEBYTECODE=1PIP_DISABLE_PIP_VERSION_CHECK=1PIP_DEFAULT_TIMEOUT=100Configuration
Section titled “Configuration”Railpack builds your Python application based on your project structure. The build process:
- Installs Python and required system dependencies
- Installs project dependencies using your preferred package manager
- Configures the Python environment for production
The start command is determined by:
- Framework specific start command (see below)
- Main Python file in the root directory (checked in order:
main.py,app.py,bot.py,hello.py,server.py)
Package Managers
Section titled “Package Managers”Railpack supports multiple Python package managers:
- pip - Uses
requirements.txtfor dependencies - poetry - Uses
pyproject.tomlandpoetry.lock - pdm - Uses
pyproject.tomlandpdm.lock - uv - Uses
pyproject.tomlanduv.lock - pipenv - Uses
Pipfile
Config Variables
Section titled “Config Variables”| Variable | Description | Example |
|---|---|---|
RAILPACK_PYTHON_VERSION | Override the Python version | 3.11 |
RAILPACK_DJANGO_APP_NAME | Django app name | myapp.wsgi |
System Dependencies
Section titled “System Dependencies”Railpack installs system dependencies for common Python packages:
- pycairo: Installs
libcairo2-dev(build time) andlibcairo2(runtime) - pdf2image: Installs
poppler-utils - pydub: Installs
ffmpeg - pymovie: Installs
ffmpeg,qt5-qmake, and related Qt packages
Framework Support
Section titled “Framework Support”Railpack detects and configures start commands for popular frameworks:
FastHTML
Section titled “FastHTML”Railpack detects FastHTML projects when python-fasthtml is listed as a
dependency. When detected:
- Starts with
uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000}ifuvicornis a dependency
Railpack detects Flask projects when flask is listed as a dependency. When
detected:
- Starts with
gunicorn --bind 0.0.0.0:${PORT:-8000} main:appifgunicornis a dependency
FastAPI
Section titled “FastAPI”Railpack detects FastAPI projects when fastapi is listed as a dependency.
When detected and uvicorn is available as a dependency:
- Starts with
uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000}
Django
Section titled “Django”Railpack detects Django projects by:
- Presence of
manage.py - Django being listed as a dependency
The start command is determined by:
RAILPACK_DJANGO_APP_NAMEenvironment variable- Scanning Python files for
WSGI_APPLICATIONsetting - Runs
python manage.py migrate && gunicorn {appName}:application
Databases
Section titled “Databases”Railpack automatically installs system dependencies for common databases:
- PostgreSQL: Installs
libpq-devat build time andlibpq5at runtime - MySQL: Installs
default-libmysqlclient-devat build time anddefault-mysql-clientat runtime
BuildKit Caching
Section titled “BuildKit Caching”The Python provider will cache /opt/pip-cache under the cache key pip, and, for uv-based apps, /opt/uv-cache under the key uv.