Skip to main content

A simple API for AirVisual air quality data

Project description

☀️ pyairvisual: a thin Python wrapper for the AirVisual© API

.. image:: :target:

.. image:: :target:

.. image:: :target:

.. image:: :target:

.. image:: :target:

.. image:: :target: :alt: Maintainability

.. image::!-1EAEDB.svg :target:

pyairvisual is a simple, clean, well-tested library for interacting with AirVisual <>_ to retrieve air quality information.

☀️ PLEASE READ: 1.0.0 and Beyond

Version 1.0.0 of pyairvisual makes several breaking, but necessary changes:

  • Moves the underlying library from Requests <>_ to aiohttp <>_
  • Changes the entire library to use :code:asyncio
  • Makes 3.5 the minimum version of Python required

If you wish to continue using the previous, synchronous version of pyairvisual, make sure to pin version 1.0.0.

💧 Installation

.. code-block:: bash

$ pip install pyairvisual

💧 Example

pyairvisual starts within an aiohttp <>_ :code:ClientSession:

.. code-block:: python

import asyncio

from aiohttp import ClientSession

from pyairvisual import Client

async def main() -> None: """Create the aiohttp session and run the example.""" async with ClientSession() as websession: await run(websession)

async def run(websession): """Run.""" # YOUR CODE HERE


Create a client:

.. code-block:: python

client = Client('<YOUR AIRVISUAL API KEY>')

Then, get to work:

.. code-block:: python

Get data based on the city nearest to your IP address:

data = await

...or get data based on the city nearest to a latitude/longitude:

data = await latitude=39.742599, longitude=-104.9942557)

...or get it explicitly:

data = await city='Los Angeles', state='California', country='USA')

If you have the appropriate API key, you can also get data based on station

(nearest or explicit):

data = await data = await latitude=39.742599, longitude=-104.9942557) data = await station='US Embassy in Beijing', city='Beijing', state='Beijing', country='China')

With the appropriate API key, you can get an air quality ranking:

data =

Lastly, pyairvisual gives you several methods to look locations up:

countries = await client.supported.countries() states = await client.supported.states('USA') cities = await client.supported.cities('USA', 'Colorado') stations = await client.supported.stations('USA', 'Colorado', 'Denver')

Check out, the tests, and the source files themselves for method signatures and more examples.

💧 Contributing

#. Check for open features/bugs <>_ or initiate a discussion on one <>. #. Fork the repository <>. #. Install the dev environment: :code:make init. #. Enter the virtual environment: :code:pipenv shell #. Code your new feature or bug fix. #. Write a test that covers your new functionality. #. Run tests: :code:make test #. Build new docs: :code:make docs #. Add yourself to AUTHORS.rst. #. Submit a pull request!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pyairvisual-2.0.0-py2-none-any.whl (6.0 kB) Copy SHA256 hash SHA256 Wheel py2
pyairvisual-2.0.0.tar.gz (6.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page