{"id":15685895,"url":"https://github.com/bachya/pyairvisual","last_synced_at":"2025-04-06T00:10:00.355Z","repository":{"id":24767068,"uuid":"101498333","full_name":"bachya/pyairvisual","owner":"bachya","description":"☀️ A simple, clean, well-tested Python library for interacting with AirVisual©","archived":false,"fork":false,"pushed_at":"2025-03-27T06:26:04.000Z","size":1608,"stargazers_count":10,"open_issues_count":5,"forks_count":4,"subscribers_count":2,"default_branch":"dev","last_synced_at":"2025-03-29T23:11:06.197Z","etag":null,"topics":["air-quality","asyncio","health","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bachya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-26T16:31:36.000Z","updated_at":"2024-11-12T18:01:15.000Z","dependencies_parsed_at":"2023-10-20T17:27:13.924Z","dependency_job_id":"48290d99-7cdf-43ec-ade4-60cc7fb10b2c","html_url":"https://github.com/bachya/pyairvisual","commit_stats":{"total_commits":507,"total_committers":8,"mean_commits":63.375,"dds":0.4536489151873767,"last_synced_commit":"98ede5c0fc9677af386697f129f32a8485bab8c5"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Fpyairvisual","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Fpyairvisual/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Fpyairvisual/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Fpyairvisual/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bachya","download_url":"https://codeload.github.com/bachya/pyairvisual/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247415972,"owners_count":20935387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["air-quality","asyncio","health","python3"],"created_at":"2024-10-03T17:32:38.857Z","updated_at":"2025-04-06T00:10:00.328Z","avatar_url":"https://github.com/bachya.png","language":"Python","funding_links":["https://www.buymeacoffee.com/bachya1208P"],"categories":[],"sub_categories":[],"readme":"# ☀️ pyairvisual: a thin Python wrapper for the AirVisual© API\n\n[![CI][ci-badge]][ci]\n[![PyPI][pypi-badge]][pypi]\n[![Version][version-badge]][version]\n[![License][license-badge]][license]\n[![Code Coverage][codecov-badge]][codecov]\n[![Maintainability][maintainability-badge]][maintainability]\n\n\u003ca href=\"https://www.buymeacoffee.com/bachya1208P\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/default-orange.png\" alt=\"Buy Me A Coffee\" height=\"41\" width=\"174\"\u003e\u003c/a\u003e\n\n`pyairvisual` is a simple, clean, well-tested library for interacting with\n[AirVisual][airvisual] to retrieve air quality information.\n\n- [Python Versions](#python-versions)\n- [Installation](#installation)\n- [API Key](#api-key)\n  - [Community](#community)\n  - [Startup](#startup)\n  - [Enterprise](#enterprise)\n- [Usage](#usage)\n  - [Using the Cloud API](#using-the-cloud-api)\n  - [Working with Node/Pro Units](#working-with-node-pro-units)\n- [Contributing](#contributing)\n\n# Python Versions\n\n`pyairvisual` is currently supported on:\n\n- Python 3.10\n- Python 3.11\n- Python 3.12\n\n# Installation\n\n```bash\npip install pyairvisual\n```\n\n# API Key\n\nYou can get an AirVisual API key from [the AirVisual API site][airvisual-api].\nDepending on the plan you choose, more functionality will be available from the API:\n\n## Community\n\nThe Community Plan gives access to:\n\n- List supported countries\n- List supported states\n- List supported cities\n- Get data from the nearest city based on IP address\n- Get data from the nearest city based on latitude/longitude\n- Get data from a specific city\n\n## Startup\n\nThe Startup Plan gives access to:\n\n- List supported stations in a city\n- Get data from the nearest station based on IP address\n- Get data from the nearest station based on latitude/longitude\n- Get data from a specific station\n\n## Enterprise\n\nThe Enterprise Plan gives access to:\n\n- Get a global city ranking of air quality\n\n# Usage\n\n## Using the Cloud API\n\n```python\nimport asyncio\n\nfrom pyairvisual.cloud_api import CloudAPI\n\n\nasync def main() -\u003e None:\n    \"\"\"Run!\"\"\"\n    cloud_api = CloudAPI(\"\u003cYOUR_AIRVISUAL_API_KEY\u003e\")\n\n    # Get data based on the city nearest to your IP address:\n    data = await cloud_api.air_quality.nearest_city()\n\n    # ...or get data based on the city nearest to a latitude/longitude:\n    data = await cloud_api.air_quality.nearest_city(\n        latitude=39.742599, longitude=-104.9942557\n    )\n\n    # ...or get it explicitly:\n    data = await cloud_api.air_quality.city(\n        city=\"Los Angeles\", state=\"California\", country=\"USA\"\n    )\n\n    # If you have the appropriate API key, you can also get data based on\n    # station (nearest or explicit):\n    data = await cloud_api.air_quality.nearest_station()\n    data = await cloud_api.air_quality.nearest_station(\n        latitude=39.742599, longitude=-104.9942557\n    )\n    data = await cloud_api.air_quality.station(\n        station=\"US Embassy in Beijing\",\n        city=\"Beijing\",\n        state=\"Beijing\",\n        country=\"China\",\n    )\n\n    # With the appropriate API key, you can get an air quality ranking:\n    data = await cloud_api.air_quality.ranking()\n\n    # pyairvisual gives you several methods to look locations up:\n    countries = await cloud_api.supported.countries()\n    states = await cloud_api.supported.states(\"USA\")\n    cities = await cloud_api.supported.cities(\"USA\", \"Colorado\")\n    stations = await cloud_api.supported.stations(\"USA\", \"Colorado\", \"Denver\")\n\n\nasyncio.run(main())\n```\n\nBy default, the library creates a new connection to AirVisual with each coroutine. If\nyou are calling a large number of coroutines (or merely want to squeeze out every second\nof runtime savings possible), an [`aiohttp`][aiohttp] `ClientSession` can be used for\nconnection pooling:\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom pyairvisual.cloud_api import CloudAPI\n\n\nasync def main() -\u003e None:\n    \"\"\"Run!\"\"\"\n    async with ClientSession() as session:\n        cloud_api = CloudAPI(\"\u003cYOUR_AIRVISUAL_API_KEY\u003e\", session=session)\n\n        # ...\n\n\nasyncio.run(main())\n```\n\n## Working with Node/Pro Units\n\n`pyairvisual` also allows users to interact with [Node/Pro units][airvisual-pro], both via\nthe cloud API:\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom pyairvisual.cloud_api import CloudAPI\n\n\nasync def main() -\u003e None:\n    \"\"\"Run!\"\"\"\n    cloud_api = CloudAPI(\"\u003cYOUR_AIRVISUAL_API_KEY\u003e\")\n\n    # The Node/Pro unit ID can be retrieved from the \"API\" section of the cloud\n    # dashboard:\n    data = await cloud_api.node.get_by_node_id(\"\u003cNODE_ID\u003e\")\n\n\nasyncio.run(main())\n```\n\n...or over the local network via Samba (the unit password can be found\n[on the device itself][airvisual-samba-instructions]):\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom pyairvisual.node import NodeSamba\n\n\nasync def main() -\u003e None:\n    \"\"\"Run!\"\"\"\n    async with NodeSamba(\"\u003cIP_ADDRESS_OR_HOST\u003e\", \"\u003cPASSWORD\u003e\") as node:\n        measurements = await node.async_get_latest_measurements()\n\n        # Can take some optional parameters:\n        #   1. include_trends: include trends (defaults to True)\n        #   2. measurements_to_use: the number of measurements to use when calculating\n        #      trends (defaults to -1, which means \"use all measurements\")\n        history = await node.async_get_history()\n\n\nasyncio.run(main())\n```\n\nCheck out the examples, the tests, and the source files themselves for method\nsignatures and more examples.\n\n# Contributing\n\nThanks to all of [our contributors][contributors] so far!\n\n1. [Check for open features/bugs][issues] or [initiate a discussion on one][new-issue].\n2. [Fork the repository][fork].\n3. (_optional, but highly recommended_) Create a virtual environment: `python3 -m venv .venv`\n4. (_optional, but highly recommended_) Enter the virtual environment: `source ./.venv/bin/activate`\n5. Install the dev environment: `script/setup`\n6. Code your new feature or bug fix on a new branch.\n7. Write tests that cover your new functionality.\n8. Run tests and ensure 100% code coverage: `poetry run pytest --cov pyairvisual tests`\n9. Update `README.md` with any new documentation.\n10. Submit a pull request!\n\n[aiohttp]: https://github.com/aio-libs/aiohttp\n[airvisual]: https://www.airvisual.com/\n[airvisual-api]: https://www.airvisual.com/user/api\n[airvisual-pro]: https://www.airvisual.com/air-quality-monitor\n[airvisual-samba-instructions]: https://support.airvisual.com/en/articles/3029331-download-the-airvisual-node-pro-s-data-using-samba\n[ci-badge]: https://img.shields.io/github/actions/workflow/status/bachya/pyairvisual/test.yml\n[ci]: https://github.com/bachya/pyairvisual/actions\n[codecov-badge]: https://codecov.io/gh/bachya/pyairvisual/branch/dev/graph/badge.svg\n[codecov]: https://codecov.io/gh/bachya/pyairvisual\n[contributors]: https://github.com/bachya/pyairvisual/graphs/contributors\n[fork]: https://github.com/bachya/pyairvisual/fork\n[issues]: https://github.com/bachya/pyairvisual/issues\n[license-badge]: https://img.shields.io/pypi/l/pyairvisual.svg\n[license]: https://github.com/bachya/pyairvisual/blob/main/LICENSE\n[maintainability-badge]: https://api.codeclimate.com/v1/badges/948e4e3c84e5c49826f1/maintainability\n[maintainability]: https://codeclimate.com/github/bachya/pyairvisual/maintainability\n[new-issue]: https://github.com/bachya/pyairvisual/issues/new\n[new-issue]: https://github.com/bachya/pyairvisual/issues/new\n[pypi-badge]: https://img.shields.io/pypi/v/pyairvisual.svg\n[pypi]: https://pypi.python.org/pypi/pyairvisual\n[version-badge]: https://img.shields.io/pypi/pyversions/pyairvisual.svg\n[version]: https://pypi.python.org/pypi/pyairvisual\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Fpyairvisual","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbachya%2Fpyairvisual","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Fpyairvisual/lists"}