Python
The Python language is officially supported on the platform.
Detection
To ensure our deployment system considers your application as a Python
application, a file Pipfile
, requirements.txt
or setup.py
should be
present at the root of your project, defining the dependencies of your app.
Python Versions
Availability
The following versions of Python are available:
Python Version | scalingo-20 | scalingo-22 |
---|---|---|
3.12 |
up to 3.12.2
|
up to 3.12.2
|
3.11 |
up to 3.11.8
|
up to 3.11.8
|
3.10 |
up to 3.10.13
|
up to 3.10.13
|
3.9 |
up to 3.9.18
|
up to 3.9.18
|
3.8 |
up to 3.8.18
|
unsupported |
Selecting a Version
The default Python version on both scalingo-20
and scalingo-22
is the
latest 3.12
version. You can, however, instruct the platform to use another
version.
Using pipenv
The preferred way to manage dependencies and python version is by using the
pipenv
tool. When creating a project with pipenv, the Python version is
frozen in the Pipfile
file, i.e.:
[requires]
python_version = "3.10"
The deployment system will use this information to install the last available
version respecting this constraint. In the previous example Python 3.10.13
would be installed.
The python_version
field only accepts minor versions of Python like 3.10
or
3.9
. If the project needs to use a specific Python patch (i.e.: 3.10.1
)
the Pipfile should contain a python_full_version
field, e.g.:
[requires]
python_full_version = "3.10.1"
Using runtime.txt
You can specify the runtime version in the runtime.txt
file at the root of
your repository.
Example of runtime.txt
which would install Python 3.9.16
:
python-3.9.16
Dependencies
Recommended: pipenv
When the project is using pipenv
and contains a Pipfile and a
Pipfile.lock files, the following command is used to install dependencies:
pipenv install
Legacy: requirements.txt
If a requirements.txt
file is present in your application, the dependencies
will be installed respecting this file with:
pip install -r requirements.txt
Frameworks
We handle most of the common frameworks. Obviously, Django is among them. You need to
configure your application to bind the port defined by the environment variable $PORT
.
Specific Python Buildpack Hooks
You may want to trigger custom actions after a successful deployment. The postdeploy hook is exactly what you need. But your application may require some actions to be executed during the deployment.
The Python buildpack can execute two hooks: before and after the installation of Python and its
dependencies. They must be located in the bin
root folder of your application and be named
pre_compile
and post_compile
.
Buildpack
More information at https://github.com/Scalingo/python-buildpack.