Skip Navigation
Show nav
Dev Center
  • Get Started
  • Documentation
  • Changelog
  • Search
  • Get Started
    • Node.js
    • Ruby on Rails
    • Ruby
    • Python
    • Java
    • PHP
    • Go
    • Scala
    • Clojure
  • Documentation
  • Changelog
  • More
    Additional Resources
    • Home
    • Elements
    • Products
    • Pricing
    • Careers
    • Help
    • Status
    • Events
    • Podcasts
    • Compliance Center
    Heroku Blog

    Heroku Blog

    Find out what's new with Heroku on our blog.

    Visit Blog
  • Log inorSign up
View categories

Categories

  • Heroku Architecture
    • Compute (Dynos)
      • Dyno Management
      • Dyno Concepts
      • Dyno Behavior
      • Dyno Reference
      • Dyno Troubleshooting
    • Stacks (operating system images)
    • Networking & DNS
    • Platform Policies
    • Platform Principles
  • Command Line
  • Deployment
    • Deploying with Git
    • Deploying with Docker
    • Deployment Integrations
  • Continuous Delivery & Integration
    • Continuous Integration
  • Language Support
    • Node.js
    • Ruby
      • Rails Support
      • Working with Bundler
    • Python
      • Working with Django
      • Background Jobs in Python
    • Java
      • Working with Maven
      • Java Database Operations
      • Working with Spring Boot
      • Java Advanced Topics
    • PHP
    • Go
      • Go Dependency Management
    • Scala
    • Clojure
  • Databases & Data Management
    • Heroku Postgres
      • Postgres Basics
      • Postgres Getting Started
      • Postgres Performance
      • Postgres Data Transfer & Preservation
      • Postgres Availability
      • Postgres Special Topics
    • Heroku Key-Value Store
    • Apache Kafka on Heroku
    • Other Data Stores
  • Monitoring & Metrics
    • Logging
  • App Performance
  • Add-ons
    • All Add-ons
  • Collaboration
  • Security
    • App Security
    • Identities & Authentication
      • Single Sign-on (SSO)
    • Compliance
  • Heroku Enterprise
    • Private Spaces
      • Infrastructure Networking
    • Enterprise Accounts
    • Enterprise Teams
    • Heroku Connect (Salesforce sync)
      • Heroku Connect Administration
      • Heroku Connect Reference
      • Heroku Connect Troubleshooting
  • Patterns & Best Practices
  • Extending Heroku
    • Platform API
    • App Webhooks
    • Heroku Labs
    • Building Add-ons
      • Add-on Development Tasks
      • Add-on APIs
      • Add-on Guidelines & Requirements
    • Building CLI Plugins
    • Developing Buildpacks
    • Dev Center
  • Accounts & Billing
  • Troubleshooting & Support
  • Integrating with Salesforce
  • Language Support
  • Python
  • Heroku Python Support

Heroku Python Support

English — 日本語に切り替える

Last updated November 06, 2024

Table of Contents

  • Recognizing a Python App
  • Specifying a Python Version
  • Build Behavior
  • Database Auto-Provisioning
  • Checking the Python Buildpack Version

Heroku supports all popular web frameworks for Python including Django, Flask, and so on.

For a deployment tutorial that uses a sample Django app, see Getting Started on Heroku with Python.

Recognizing a Python App

Heroku automatically recognizes your app as a Python app if it includes a requirements.txt, poetry.lock, or Pipfile.lock file in its root directory.

When Heroku recognizes a deployed application as a Python application, you see this build output:

$ git push heroku master
-----> Python app detected

Specifying a Python Version

By default, newly created Python apps use the latest patch version of Python 3.12. Subsequent builds of the app will then be pinned to that initial Python version unless the build cache is cleared or you request a different version.

However, we recommend that you specify a Python version for your app using a .python-version file rather than relying on the default version.

Supported Runtimes

  • Python 3.13
  • Python 3.12
  • Python 3.11
  • Python 3.10

If you see a “Requested runtime is not available for this stack” error using one of the versions above, check that your app is using the latest version of the Python buildpack.

Deprecated Runtimes

  • Python 3.9
  • Python 3.8 (available on the Heroku-20 stack only; supported until December 4th, 2024)

Python versions older than those listed above are no longer supported. We drop support for Python versions once they reach their upstream end-of-life.

Build Behavior

The Python buildpack detects which package manager your app is using based on which package manager related files are included in the root directory of the app.

If your app includes a requirements.txt file, it will use pip to install your dependencies:

$ pip install -r requirements.txt

If your app includes a poetry.lock file, it will use Poetry to install your dependencies:

$ poetry install --sync --only main

If your app includes a Pipfile.lock file, it will use Pipenv to install your dependencies:

$ pipenv install --deploy

Database Auto-Provisioning

This section is only applicable to accounts created before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account.

A Heroku Postgres database automatically provisions on the first deploy of your app if:

  • You created your account before May 15, 2023 or if you asked Heroku Support to enable auto-provisioning for your account
  • A manage.py file exists in the root of the app source
  • Both the Django and psycopg2 packages are installed

Automatic provisioning of a database also populates your app’s DATABASE_URL config var.

A Heroku Postgres database is not automatically provisioned for other Python apps, but you can easily provision one manually.

Checking the Python Buildpack Version

The Python buildpack is what transforms your Python source code into a slug that can be deployed on Heroku.

For the best results, it’s recommended that you use the latest stable version of the buildpack, rather than pinning to a tag or branch or using a fork. Otherwise, some documented features don’t work, and you don’t benefit from future bug fixes or improvements made to the buildpack.

The stable heroku/python buildpack release is also pre-installed in the build environment, so using it improves build performance compared to GitHub URLs.

For more information see Buildpack References.

To check which buildpacks are configured on your app, use the heroku buildpacks CLI command:

$ heroku buildpacks
=== my-example-app Buildpack URL
https://github.com/heroku/heroku-buildpack-python.git

If you see a GitHub URL like in the example or one that’s pinned to a custom branch or tag, then it’s recommended to switch to the heroku/python buildpack. heroku/python is the curated stable buildpack registry release.

To switch buildpacks, first clear the existing buildpacks set on the app using:

$ heroku buildpacks:clear
Buildpacks cleared.

Then add the Python buildpack:

$ heroku buildpacks:add heroku/python
Buildpack added.

Finally, check that the configured buildpacks are correct:

$ heroku buildpacks
=== my-example-app Buildpack URL
heroku/python

If you originally set multiple buildpacks on your app, you must add them in the same order as they were listed in heroku buildpacks previously. For example:

$ heroku buildpacks
=== my-example-app Buildpack URLs
1. heroku-community/example-buildpack
2. https://github.com/heroku/heroku-buildpack-python.git
$ heroku buildpacks:clear
$ heroku buildpacks:add heroku-community/example-buildpack
$ heroku buildpacks:add heroku/python
$ heroku buildpacks
=== my-example-app Buildpack URLs
1. heroku-community/example-buildpack
2. heroku/python

Keep reading

  • Python

Feedback

Log in to submit feedback.

Specifying a Python Version Optimizing Python Application Concurrency

Information & Support

  • Getting Started
  • Documentation
  • Changelog
  • Compliance Center
  • Training & Education
  • Blog
  • Support Channels
  • Status

Language Reference

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala
  • Clojure

Other Resources

  • Careers
  • Elements
  • Products
  • Pricing
  • RSS
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku Blog
    • Heroku News Blog
    • Heroku Engineering Blog
  • Twitter
    • Dev Center Articles
    • Dev Center Changelog
    • Heroku
    • Heroku Status
  • Github
  • LinkedIn
  • heroku.com
  • Terms of Service
  • Privacy (日本語)
  • Cookies
  • Cookie Preferences
  • Your Privacy Choices
  • © 2024 Salesforce.com