Skip to main content

pyramid_heroku

Introduction

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>.herokuapp.com domain for any non-whitelisted IPs.

  • migrate.py script for automatically running alembic migrations on deploy.

Installation

Just do

pip install pyramid_heroku

or

easy_install pyramid_heroku

Compatibility

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

Documentation

Usage example for tweens:

def main(global_config, **settings):$ cat .heroku/release.sh
    config = Configurator(settings=settings)
    config.include('pyramid_heroku.client_addr')
    config.include('pyramid_heroku.herokuapp_access')
    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/release.sh
#!/usr/bin/env bash

set -e

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

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

Releasing

  1. Update CHANGES.rst.

  2. Update setup.py version.

  3. Run pipenv run python setup.py check -rs.

  4. Run pipenv run python setup.py 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!

Changes

0.5.0

  • 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]

0.4.0

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

0.3.2

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

0.3.1

  • Fix auth bug in migrate.py. [zupo]

0.3

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

0.2

  • 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]

0.1.5

  • Brown bag release. [karantan]

0.1.4

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

0.1.3

0.1.2

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

0.1.1

  • Fix tween paths. [zupo]

0.1

  • Initial release. [dz0ny, zupo]

Metadata

Release files for pyramid_heroku 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyramid_heroku 0.5.0
File Size Uploaded
pyramid_heroku-0.5.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyramid_heroku 0.5.0
File Interpreter ABI Platform
pyramid_heroku-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / pyramid_heroku-0.5.0.tar.gz

Download URL pyramid_heroku-0.5.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e8c4a1e3381562dd4e0f7c4a47019222b9e1f9332cc165e28f2ae86c697311b1
BLAKE2b-256 checksum
How to use checksums
cde564bd2312100e7b631218f655955e31f49a32f2ce60bcd8fee7b99f7270a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release files / pyramid_heroku-0.5.0-py3-none-any.whl

Download URL pyramid_heroku-0.5.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e38b09c8ff88a9377e0a685185b1497a4a2171d43efbb091beefb12678763f7b
BLAKE2b-256 checksum
How to use checksums
b0f7b37b771f10af41537c706fa67260e4d785bbfeb0539a47c7f9faf51d560b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.5

Release history Release notifications | RSS feed

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

1 release file

This release

0.5.0 This release

2 release files

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page