Skip to main content

A bunch of helpers for successfully running Pyramid on Heroku.

Project description


pyramid_heroku is a collection of tweens and helpers to successfully run Pyramid on Heroku

It provides the following:

  • ClientAddr tween that sets real user’s IP to request.client_addr
  • HerokuappAccess tween that denies access to your app’s <app> domain for any non-whitelisted IPs.
  • script for automatically running alembic migrations on deploy.


Just do

pip install pyramid_heroku


easy_install pyramid_heroku


pyramid_heroku runs with pyramid>=1.7 and python>=3.6. Other versions might also work.


Usage example for tweens:

def main(global_config, **settings):$ cat .heroku/
    config = Configurator(settings=settings)
    return config.make_wsgi_app()

The pyramid_heroku.herokuapp_access tween depends on pyramid_heroku.client_addr tween and it requires you to list whitelisted IPs in the pyramid_heroku.herokuapp_whitelist setting.

Usage example for automatic alembic migration script:

$ cat .heroku/
#!/usr/bin/env bash

set -e

echo "Running migrations"
python -m pyramid_heroku.migrate my_app etc/production.ini

echo "DONE!"

For migration script to work, you need to set the MIGRATE_API_SECRET_HEROKU env var in Heroku. This allows the migration script to use the Heroku API.

See tests for more examples.

If you use structlog, add the following configuration setting to your INI file to enable structlog-like logging:

pyramid_heroku.structlog = true


  1. Update CHANGES.rst.
  2. Update version.
  3. Run pipenv run python check -rs.
  4. Run pipenv run python sdist upload.

We’re hiring!

At Niteo we regularly contribute back to the Open Source community. If you do too, we’d like to invite you to join our team!




  • Prefer empty string than None. {‘VAL’: ‘${VAR}’} will expand into {‘VAL’: ‘’} instead of {‘VAL’: None} if the value of VAR is not exported or is an empty string. [sayanarijit]
  • To enforce that $VAR must be set, ${VAR:?custom error message} syntax can be used. [sayanarijit]


  • Supports bash style environment variable expansion. e.g. to declare default value, use ${DATABASE_URL:-sqlite:///database.db} [sayanarijit]


  • Shell now prints stderr/stdout even on non-zero exit code. [iElectric]


  • Fix auth bug in [zupo]


  • Drop support for zc.buildout environments. [zupo]


  • Expand all environment variables in the settings dictionary. This allows you to have, for example ${DATABASE_URL} to get db connection string from environment into your production.ini file. [zupo]
  • Use pipenv for setting up development. [zupo]
  • Add basic type hinting. [zupo]
  • Drop support for Python versions older than 3.7. [zupo]


  • Brown bag release. [karantan]


  • Fix return value in subprocess.check_output changed in python 3.6 and is now returning byte and not str. [karantan]



  • The request.client_addr cannot be set directly, so we need to go around. [zupo]


  • Fix tween paths. [zupo]


  • Initial release. [dz0ny, zupo]

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyramid_heroku, version 0.6.0
Filename, size File type Python version Upload date Hashes
Filename, size pyramid_heroku-0.6.0.tar.gz (7.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page