- Use Our Data
- Integrations
- Python
Power Outage Data in Python
To get power outage data in Python, call the PowerOutage.us v2 REST API with requests, send your key in an Authorization: Bearer header, and load the JSON into pandas or geopandas. Every endpoint returns plain JSON or GeoJSON, so there is no SDK to install. This guide builds a small client that reads the key from an environment variable and waits out rate limits, then uses it for county outage counts, outage polygons and a check of whether specific coordinates are in an outage.
What you'll have
- A DataFrame of customers out and customers tracked for every county in a state, with the percentage out.
- A GeoDataFrame of active outage polygons you can filter, map or write to GeoJSON.
- A batch check of up to 100 coordinates against live outage polygons in one request.
- A client that retries on 429 and honors the
Retry-Afterheader.
What you need
An API key (request one with the form below) and these endpoints. Full details are in the API reference.
| Endpoint | Method | Used for | Package |
|---|---|---|---|
/outages/counties | GET | County-level customersOut and customersTracked, filtered with stateId. | Core |
/geojson/outages | GET | Outage polygons as GeoJSON, filtered with stateId and minCustomersOut. | Standard |
/geojson/at-point | POST | Tells you whether each lat/lon you send sits inside an active outage, up to 100 points per request. | Standard + Locations |
Step 1: Install the libraries and set your key
Install requests, pandas and geopandas with pip. Store your API key in an environment variable named POWEROUTAGE_API_KEY (from your shell profile, a .env loader, or your deployment platform), never in the script. The key goes in the Authorization header only; the API does not accept it in the URL.
pip install requests pandas geopandas
export POWEROUTAGE_API_KEY='...' # set from your secret store, not committed Step 2: Write a client that handles rate limits
The API allows 10 requests per 10 seconds and answers 429 with a Retry-After header when you go over. This helper sends the bearer header on every request, times out after 30 seconds, and sleeps for Retry-After seconds before trying again. Reuse it for every call below.
import os
import time
import requests
session = requests.Session()
session.headers['Authorization'] = f"Bearer {os.environ['POWEROUTAGE_API_KEY']}"
def call(method, url, **kwargs):
"""Call the API, waiting out a 429 for as long as Retry-After says."""
for _ in range(3):
response = session.request(method, url, timeout=30, **kwargs)
if response.status_code != 429:
response.raise_for_status()
return response.json()
time.sleep(int(response.headers.get('Retry-After', '10')))
raise RuntimeError(f'Still rate limited after 3 tries: {url}') Step 3: Load county outage counts into pandas
Look up a state id with GET /outages/states, then pass it as stateId to /outages/counties. Each row has name, customersOut, customersTracked and lastUpdatedAt. Compare lastUpdatedAt with meta.generatedAt to see how stale a county is; a lastUpdatedAt of null means no utility has reported for it.
import pandas as pd
# 45 is Georgia's stateId. List ids with GET /outages/states.
payload = call('GET', 'https://poweroutage.us/api/v2/outages/counties', params={'stateId': 45})
df = pd.DataFrame(payload['data'])
df['pctOut'] = (df['customersOut'] / df['customersTracked'] * 100).round(2)
print(f"Generated at {payload['meta']['generatedAt']}")
print(df.sort_values('customersOut', ascending=False)
.head(10)[['name', 'customersOut', 'customersTracked', 'pctOut']]) Step 4: Load outage polygons into geopandas
/geojson/outages returns a GeoJSON FeatureCollection, which GeoDataFrame.from_features reads directly. Use minCustomersOut to drop small outages. Identify an outage across polls by utilityId plus outageId, not by the feature id. cause and estimatedRestorationAt are passed through as the utility reports them and are often null.
import geopandas as gpd
collection = call(
'GET',
'https://poweroutage.us/api/v2/geojson/outages',
params={'stateId': 45, 'minCustomersOut': 100},
)
outages = gpd.GeoDataFrame.from_features(collection['features'], crs='EPSG:4326')
# Track an outage by utilityId + outageId. The feature id is not stable.
outages['key'] = outages['utilityId'].astype(str) + ':' + outages['outageId']
print(outages[['key', 'customersOut', 'cause', 'estimatedRestorationAt']])
outages.to_file('outages.geojson', driver='GeoJSON') Step 5: Check coordinates against live outages
POST up to 100 points as {"points": [{"lat": ..., "lon": ...}]} to /geojson/at-point. Results come back in the same order as the points you sent. Each has outageAtPoint, the matching outages, and the utilities serving that location. A utility that does not publish outage polygons cannot confirm an outage, so check the providesGeospatialData flag on each utility before reading outageAtPoint: false as all clear.
sites = [
{'name': 'Atlanta office', 'lat': 33.749, 'lon': -84.388},
{'name': 'Savannah depot', 'lat': 32.0809, 'lon': -81.0912},
]
result = call(
'POST',
'https://poweroutage.us/api/v2/geojson/at-point',
json={'points': [{'lat': s['lat'], 'lon': s['lon']} for s in sites]},
)
for site, point in zip(sites, result['data']['points']):
if point['outageAtPoint']:
worst = max(point['outages'], key=lambda o: o['customersOut'] or 0)
print(site['name'], 'OUT', worst['customersOut'], worst['estimatedRestorationAt'])
else:
print(site['name'], 'ok') Step 6: Run it on a schedule
The data updates every minute. Polling every 10 to 15 minutes from a loop, cron or a scheduler such as Airflow or GitHub Actions is enough for most uses; for the latest numbers, poll every 1 to 2 minutes from a loop or cron, well within the limit of 10 requests per 10 seconds. There are no webhooks, so polling is the only way to pick up changes.
import time
POLL_SECONDS = 15 * 60 # the data updates every minute; use 60 or 120 for the latest numbers
while True:
payload = call('GET', 'https://poweroutage.us/api/v2/outages/counties', params={'stateId': 45})
# ... update your table, file or dashboard here
time.sleep(POLL_SECONDS) Tips for Python
- Reuse one
requests.Sessionso connections are kept alive across calls. - Responses are not paginated. A statewide
/geojson/outagescall can be large, so filter withstateIdorminCustomersOutinstead of downloading everything. - Set a
timeouton every request.requestswaits forever by default, which stalls a scheduled job. geopandasneeds GDAL-backed wheels; on a slim container image install it from a wheel-friendly base or with conda./geojson/at-pointis part of the Standard + Locations package. Your key must include it.
Used by
Related integrations
FAQ
Here are some commonly asked questions
Request API access
Tell us what you're building and we'll set you up with a trial key.