pyairnow: a thin Python wrapper for the AirNow API
pyairnow is a simple, tested, thin client library for interacting with the
AirNow United States EPA Air Quality Index API.
Python Versions
pyairnow is currently supported and tested on:
- Python 3.10
- Python 3.11
- Python 3.12
- Python 3.13
Installation
pip install pyairnow
API Key
You can get an AirNow API key from the AirNow API site. Ensure you read and understand the expectations and limitations of API usage, which can be found at the AirNow FAQ.
Usage
import asyncio
import datetime
from pyairnow import WebServiceAPI
async def main() -> None:
client = WebServiceAPI('your-api-key')
# Get current observational data based on a zip code
data = await client.observations.zipCode('90001')
# Get current observational data based on a latitude and longitude
data = await client.observations.latLong(34.053718, -118.244842)
# Get forecast data based on a zip code
data = await client.forecast.zipCode(
'90001',
# to get a forecast for a certain day, provide a date in yyyy-mm-dd,
# if not specified the current day will be used
date='2020-09-01',
)
# Get forecast data based on a latitude and longitude
data = await client.forecast.latLong(
# Lat/Long may be strings or floats
'34.053718', '-118.244842',
# forecast dates may also be datetime.date or datetime.datetime objects
date=datetime.date(2020, 9, 1),
)
asyncio.run(main())
By default, the library creates a new connection to AirNow with each coroutine.
If you are calling a large number of coroutines (or merely want to squeeze out
every second of runtime savings possible), an
aiohttp ClientSession can be used
for connection pooling:
import asyncio
import datetime
from aiohttp import ClientSession
from pyairnow import WebServiceAPI
async def main() -> None:
async with ClientSession() as session:
client = WebServiceAPI('your-api-key', session=session)
# ...
asyncio.run(main())
The library provides two convenience functions to convert between AQI and pollutant concentrations. See this EPA document for more details.
from pyairnow.conv import aqi_to_concentration, concentration_to_aqi
# Supported Pollutants
# --------------------
# Ozone ('O3'): ppm
# pm2.5 ('PM2.5'): ug/m^3
# pm10 ('PM10'): ug/m^3
# Carbon Monoxide ('CO'): ppm
# Sulfur Dioxide ('SO2'): ppm
# Nitrogen Dioxide ('NO2'): ppm
# Returns AQI = 144 for pm2.5 of 53.0 ug/m^3
aqi_to_concentration(144, 'PM2.5')
# Returns Cp = 53.0 ug/m^3
concentration_to_aqi(53.0, 'PM2.5')
Legacy API Format
AirNow announced in June 2026 that the forecast and current observation APIs would be
retired and replaced with new APIs with slightly changed output format. PyAirNow 1.4.0
uses the new API endpoints by default, and can provide data in the legacy format for
clients which expect it. To use the legacy format, pass legacy_format=True to the
API constructor:
import asyncio
import datetime
from pyairnow import WebServiceAPI
async def main() -> None:
client_legacy = WebServiceAPI('your-api-key', legacy_format=True)
client_current = WebServiceAPI('your-api-key')
# Get current observational data based on a zip code
data_legacy = await client_legacy.observations.zipCode('90001')
# data_legacy = [{
# 'DateObserved': ...,
# 'HourObserved': ...,
# ...,
# 'AQI': ...,
# ...,
# }]
data_current = await client_current.observations.zipCode('90001')
# data_current = [{
# 'dateObserved': ...,
# 'hourObserved': ...,
# ...,
# 'nowcastAQI': ...,
# ...,
# }]
Contributing
- Check for open features/bugs or start a discussion on one.
- Fork the repository.
- Install Poetry and set up the development workspace:
poetry install - Code your new feature or bug fix.
- Write tests that cover your new functionality.
- Run tests and ensure 100% code coverage:
make test - Run the linter to ensure 100% code style correctness:
make lint - Run the type checker to ensure type correctness:
make type-check - Update
README.mdwith any new documentation. - Add yourself to
AUTHORS.md. - Submit a pull request!
Metadata
Release files for pyairnow 1.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyairnow-1.4.1.tar.gz | 7.8 kB | Without provenance | Details for pyairnow-1.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyairnow-1.4.1-py3-none-any.whl | Python 3 | none | any | Details for pyairnow-1.4.1-py3-none-any.whl |
Total release size: 18.4 kB
Release files / pyairnow-1.4.1.tar.gz
| Download URL | pyairnow-1.4.1.tar.gz |
|---|---|
| Size | 7.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c11511dedb859488c06226f7f6ea4e9135e90715fa562cddf0fd534973849d22
|
|
BLAKE2b-256 checksum How to use checksums |
a25ad1e11986130302eaa866e71b33977d9359c41a07ce88c9c7a3f8cb179be2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.13 Darwin/25.5.0
|
Release files / pyairnow-1.4.1-py3-none-any.whl
| Download URL | pyairnow-1.4.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23f29280231639ff6ded5dd2f7968d60094c3e671324b7d3fe51c4fdab18267f
|
|
BLAKE2b-256 checksum How to use checksums |
337ae15acc3bd0196a590892910f805b20e7ffc0c3c47465ed3f1709626fc186
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.13.13 Darwin/25.5.0
|
Security for pyairnow 1.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.