> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python

> Get started creating Python apps on Upsun Cloud.

> [!TIP]
>
> You can now use composable image to install runtimes and tools in your application container. To find out more, see the [Composable image](https://developer.upsun.com/docs/configure-apps/app-reference/composable-image.md) topic.

Python is a general purpose scripting language often used in web development.
You can deploy Python apps on Upsun Cloud using a server or a project such as [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/).

## Supported versions

You can select the major and minor version.

Patch versions are applied periodically for bug fixes and other maintenance updates. By default, you get the latest available patches each time you deploy. If your project has a [maintenance window](https://developer.upsun.com/docs/core-concepts/build-deploy.md#maintenance-window) configured, Upsun Cloud applies patches only during that window. Upsun Cloud may still apply urgent or critical fixes outside of the maintenance window.

* 3.14

### Specify the language

To use Python, specify `python` as your [app's type](https://developer.upsun.com/docs/configure-apps/app-reference/single-runtime-image.md#type):


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     \<APP\_NAME>:
&#x20;       type: 'python:\<VERSION\_NUMBER>'
&#x20;&#x20;

For example:


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'

## Deprecated versions

The following versions are still available in your projects,
but they're at their end of life and are no longer receiving security updates from upstream.

* 3.13
* 3.12
* 3.11

To ensure your project remains stable in the future, switch to a [supported version](#supported-versions).

\* This version doesn't receive any updates at all.
You are strongly recommended to upgrade to a supported version.

## Retired versions

The following versions have been retired and are no longer available.
If your project uses a retired version, you must update to a [supported version](#supported-versions).

* 3.10
* 3.9
* 3.8
* 3.7
* 3.6
* 3.5
* 2.7

## Usage example

### Run your own server

You can define any server to handle requests.
Once you have it configured, add the following configuration to get it running on Upsun Cloud:

1. Specify one of the [supported versions](#supported-versions):


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'

2. Install the requirements for your app.


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       dependencies:
&#x20;         python3:
&#x20;           pipenv: "2024.4.1"
&#x20;       hooks:
&#x20;         build: |
&#x20;           set -eu
&#x20;           pipenv install --system --deploy

3. Define the command to start your web server:


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       web:
&#x20;         \# Start your app with the configuration you define
&#x20;         \# You can replace the file location with your location
&#x20;         commands:
&#x20;           start: python server.py

You can choose from many web servers such as Daphne, Gunicorn, Hypercorn, and Uvicorn.
See more about [running Python web servers](https://developer.upsun.com/docs/languages/python/server.md).

### Use uWSGI

You can also use [uWSGI](https://uwsgi-docs.readthedocs.io/en/latest/) to manage your server.
Follow these steps to get your server started.

1. Specify one of the [supported versions](#supported-versions):


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'

2. Define the conditions for your web server:


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       web:
&#x20;         upstream:
&#x20;           \# Send requests to the app server through a unix socket
&#x20;           \# Its location is defined in the SOCKET environment variable
&#x20;           socket\_family: "unix"

&#x20;         \# Start your app with the configuration you define
&#x20;         \# You can replace the file location with your location
&#x20;         commands:
&#x20;           start: "uwsgi --ini conf/uwsgi.ini"

&#x20;         locations:
&#x20;           \# The folder from which to serve static assets
&#x20;           "/":
&#x20;             root: "public"
&#x20;             passthru: true
&#x20;             expires: 1h

3. Create configuration for uWSGI such as the following:

   ```ini config/uwsgi.ini theme={null}
   [uwsgi]
   # Unix socket to use to talk with the web server
   # Uses the variable defined in the configuration in step 2
   socket = $(SOCKET)
   protocol = http

   # the entry point to your app
   wsgi-file = app.py
   ```

   Replace `app.py` with whatever your file is.

4. Install the requirements for your app.


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       dependencies:
&#x20;         python3:
&#x20;           pipenv: "2024.4.1"
&#x20;       hooks:
&#x20;         build: |
&#x20;           set -eu
&#x20;           pipenv install --system --deploy

5. Define the entry point in your app:

   ```python theme={null}
   # You can name the function differently and pass the new name as a flag
   # start: "uwsgi --ini conf/uwsgi.ini --callable <NAME>"
   def application(env, start_response):

       start_response('200 OK', [('Content-Type', 'text/html')])
       return [b"Hello world from Upsun Cloud"]
   ```

## Package management

Your app container comes with pip pre-installed.
For more about managing packages with pip, Pipenv, and Poetry,
see how to [manage dependencies](https://developer.upsun.com/docs/languages/python/dependencies.md).

To add global dependencies (packages available as commands),
add them to the `dependencies` in your [app configuration](https://developer.upsun.com/docs/configure-apps/app-reference/single-runtime-image.md#dependencies):


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       dependencies:
&#x20;         python3:
&#x20;           \<PACKAGE\_NAME>:\<PACKAGE\_VERSION>

For example, to use `pipenv` to manage requirements and a virtual environment, add the following:


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'python:\{\{version:python:latest}}'
&#x20;       dependencies:
&#x20;         python3:
&#x20;           pipenv: "2024.4.1"
&#x20;       hooks:
&#x20;         build: |
&#x20;           set -eu
&#x20;           pipenv install --system --deploy

## Connect to services

The following examples show how to access various [services](https://developer.upsun.com/docs/add-services) with Python.
For more information on configuring a given service, see the page for that service.

You can access service credentials to connect to [managed services](https://developer.upsun.com/docs/add-services) from environment variables present in the application container.
Consult each of the individual service documentation to see how to retrieve and surface credentials into your application.

* [ClickHouse](https://developer.upsun.com/docs/add-services/clickhouse.md#usage-example)
* [Elasticsearch](https://developer.upsun.com/docs/add-services/elasticsearch.md#usage-example)
* [Gotenberg](https://developer.upsun.com/docs/add-services/gotenberg.md#usage-example)
* [Headless Chrome](https://developer.upsun.com/docs/add-services/headless-chrome.md#usage-example)
* [InfluxDB](https://developer.upsun.com/docs/add-services/influxdb.md#usage-example)
* [Kafka](https://developer.upsun.com/docs/add-services/kafka.md#usage-example)
* [MariaDB/MySQL](https://developer.upsun.com/docs/add-services/mysql#usage-example)
* [Memcached](https://developer.upsun.com/docs/add-services/memcached.md#usage-example)
* [mercure](https://developer.upsun.com/docs/add-services/mercure.md#usage-example)
* [mongodb](https://developer.upsun.com/docs/add-services/mongodb.md#usage-example)
* [Network Storage](https://developer.upsun.com/docs/add-services/network-storage.md#usage-example)
* [OpenSearch](https://developer.upsun.com/docs/add-services/opensearch.md#usage-example)
* [PostgreSQL](https://developer.upsun.com/docs/add-services/postgresql#usage-example)
* [RabbitMQ](https://developer.upsun.com/docs/add-services/rabbitmq.md#usage-example)
* [Redis](https://developer.upsun.com/docs/add-services/redis.md#usage-example)
* [Solr](https://developer.upsun.com/docs/add-services/solr.md#usage-example)
* [Valkey](https://developer.upsun.com/docs/add-services/valkey.md#usage-example)
* [Varnish](https://developer.upsun.com/docs/add-services/varnish.md#usage-example)
* [Vault KMS](https://developer.upsun.com/docs/add-services/vault.md#usage-example)
* [Chroma](https://developer.upsun.com/tutorials/self-hosted/chroma.md#3-use-the-relationship-in-your-application)
* [Qdrant](https://developer.upsun.com/tutorials/self-hosted/qdrant.md#4-use-the-relationship-in-your-application)

## Sanitizing data

By default, data is inherited automatically by each child environment from its parent.
If you need to sanitize data in preview environments for compliance,
see how to [sanitize databases](https://developer.upsun.com/docs/development/sanitize-db).

## Frameworks

All major Python web frameworks can be deployed on Upsun Cloud.
See dedicated guides for deploying and working with them:

* [Django](https://developer.upsun.com/docs/get-started/stacks/django.md)
* [Flask](https://developer.upsun.com/docs/get-started/stacks/flask.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.