Python 3.10 is now available in preview.

Specifying Dependencies

Declaring and managing dependencies

Dependencies for Python applications are declared in a standard requirements.txt file. For example:


When you deploy to App Engine, the dependencies specified in the requirements.txt file will be installed automatically with your deployed app. You can use any Linux-compatible Python package, including packages that require native C extensions.

By default, App Engine caches fetched dependencies to reduce build times. To install an uncached version of the dependency, use the command:

gcloud app deploy --no-cache

Private dependencies with Artifact Registry

If you need to host private dependencies for your Python app, you can use an Artifact Registry Python repository. When deploying your app, the build process automatically generates Artifact Registry credentials for the Cloud Build service account so you won't need to generate additional credentials. To include private dependencies, add the Artifact Registry URL and the relevant packages in your requirements.txt file. For example:

--extra-index-url REPOSITORY_URL

Replace REPOSITORY_URL with the registry address, such as:

Private dependencies with other repositories

Dependencies are installed in a Cloud Build environment that does not provide access to SSH keys. Packages hosted on repositories that require SSH-based authentication must be copied into your project directory and uploaded alongside your project's code using the pip package manager.

To use private dependencies:

  1. Run pip install -t lib my_module to copy dependencies into a local folder named lib.

  2. Add an empty file to the lib directory to make it a module.

  3. Import the module in your app. For example:

    import lib.my_module

Installing dependencies locally

When developing and testing your application locally, we recommended you use venv to isolate your application's dependencies from your system packages. This also ensures that your dependencies will be the same version on your local machine and the deployed application.

To use venv to install dependencies, complete the following steps:

Mac OS / Linux

  1. Create an isolated Python environment:
    python3 -m venv env
    source env/bin/activate
  2. If you're not in the directory that contains the sample code, navigate to the directory that contains the hello_world sample code. Then install dependencies:
    pip install -r requirements.txt


Use PowerShell to run your Python packages.

  1. Locate your installation of PowerShell.
  2. Right-click on the shortcut to PowerShell and start it as an administrator.
  3. Create an isolated Python environment.
    python -m venv env
  4. Navigate to your project directory and install dependencies. If you're not in the directory that contains the sample code, navigate to the directory that contains the hello_world sample code. Then, install dependencies:
    pip install -r requirements.txt

This ensures that when you run your app locally, only the dependencies that are declared in the requirements.txt file are available. The dependencies installed by App Engine during deployment are based on the contents of the requirements.txt file, not the contents of the env/ directory.

Installing a web framework

You'll need to use a web framework to enable your app to serve web requests. You can use any Python web framework including the following:

To use a particular web framework, just add it to your requirements.txt:


Installing a WSGI server

Some web frameworks have built-in WSGI servers; however, few of them are suitable for serving production traffic. Most web applications use a standalone WSGI server such as Gunicorn, uWSGI or Waitress. For more information on installing, configuring, and using a WSGI server see application startup.