Package: pyairnow
pyairnow: a thin Python wrapper for the AirNow APIpyairnowis a simple, tested, thin client library for interacting with theAirNowUnited States EPA Air Quality Index API.Python VersionsInstallationAPI KeyUsageContributingPython Versionspyairnowis currently supported and tested on:Python 3.8Python 3.9Python 3.10Python 3.11InstallationpipinstallpyairnowAPI KeyYou can get an AirNow API key fromthe AirNow API site. Ensure you
read and understand the expectations and limitations of API usage, which can
be found atthe AirNow FAQ.UsageimportasyncioimportdatetimefrompyairnowimportWebServiceAPIasyncdefmain()->None:client=WebServiceAPI('your-api-key')# Get current observational data based on a zip codedata=awaitclient.observations.zipCode('90001',# if there are no observation stations in this zip code, optionally# provide a radius to search (in miles)distance=50,)# Get current observational data based on a latitude and longitudedata=awaitclient.observations.latLong(34.053718,-118.244842,# if there are no observation stations at this location, optionally# provide a radius to search (in miles)distance=50,)# Get forecast data based on a zip codedata=awaitclient.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 useddate='2020-09-01',# if there are no observation stations in this zip code, optionally# provide a radius to search (in miles)distance=50,)# Get forecast data based on a latitude and longitudedata=awaitclient.forecast.latLong(# Lat/Long may be strings or floats'34.053718','-118.244842',# forecast dates may also be datetime.date or datetime.datetime objectsdate=datetime.date(2020,9,1),# if there are no observation stations in this zip code, optionally# provide a radius to search (in miles)distance=50,)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), anaiohttpClientSessioncan be used
for connection pooling:importasyncioimportdatetimefromaiohttpimportClientSessionfrompyairnowimportWebServiceAPIasyncdefmain()->None:asyncwithClientSession()assession:client=WebServiceAPI('your-api-key',session=session)# ...asyncio.run(main())The library provides two convenience functions to convert between AQI and
pollutant concentrations. Seethis EPA documentfor more details.frompyairnow.convimportaqi_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^3aqi_to_concentration(144,'PM2.5')# Returns Cp = 53.0 ug/m^3concentration_to_aqi(53.0,'PM2.5')ContributingCheck for open features/bugsorstart a discussion on one.Fork the repository.InstallPoetryand set up the development workspace:poetry installCode your new feature or bug fix.Write tests that cover your new functionality.Run tests and ensure 100% code coverage:make testRun the linter to ensure 100% code style correctness:make lintUpdateREADME.mdwith any new documentation.Add yourself toAUTHORS.md.Submit a pull request!