Heroku3

raw JSON →
5.2.1 verified Mon Apr 27 auth: no python

Python wrapper for the Heroku API v3. Current version 5.2.1. Low release cadence; last stable release 5.2.0. Supports Python 3 only since v3.4.0.

pip install heroku3
error AttributeError: module 'heroku3' has no attribute 'Heroku'
cause Incorrect import: using `import heroku3` then `heroku3.Heroku` works, but some tutorials show `from heroku3 import Heroku` which is correct.
fix
Use from heroku3 import Heroku
error httpx.ConnectError: [Errno 61] Connection refused
cause Heroku API endpoint not reachable, typically due to network issues or incorrect API URL.
fix
Check network connectivity and verify Heroku API URL. The library defaults to https://api.heroku.com/
error TypeError: 'NoneType' object is not iterable
cause Calling `.releases()` on an app returns a paginated iterator; if no releases, it may return None.
fix
Check for None: releases = app.releases() or []
breaking In v5.2.0, the release endpoint changed to return a single instance instead of a list. Code expecting list will break.
fix Update code to handle single release object. E.g., `release = app.releases()[-1]` is now `release = app.releases()[-1]` still works but note behavior change.
deprecated Python 2.6 support dropped in v3.4.0. Python 2.7 support likely dropped in later versions.
fix Upgrade to Python 3.6+ and heroku3 >=3.4.0.
gotcha Heroku API keys are required. Only OAuth tokens are supported by heroku3; session cookies or other auth methods not available.
fix Generate an API key from Heroku dashboard: Account settings > API Key.

Initialize Heroku client and list apps.

import os
from heroku3 import Heroku

heroku = Heroku(token=os.environ.get('HEROKU_API_KEY', ''))
account = heroku.account()
print(f"Account email: {account.email}")
apps = heroku.apps()
print(f"Number of apps: {len(apps)}")