{"id":15723065,"url":"https://github.com/bachya/aiowatttime","last_synced_at":"2025-09-13T13:16:14.090Z","repository":{"id":40415917,"uuid":"404892498","full_name":"bachya/aiowatttime","owner":"bachya","description":"An asyncio-based Python3 library for interacting with WattTime","archived":false,"fork":false,"pushed_at":"2025-03-27T06:13:21.000Z","size":1740,"stargazers_count":3,"open_issues_count":6,"forks_count":0,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-03-28T02:14:27.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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":"2021-09-09T23:00:29.000Z","updated_at":"2024-11-12T17:57:48.000Z","dependencies_parsed_at":"2023-12-08T15:29:39.090Z","dependency_job_id":"76996f1e-39bb-4eae-9ca9-3ba1c1e1a57c","html_url":"https://github.com/bachya/aiowatttime","commit_stats":{"total_commits":121,"total_committers":4,"mean_commits":30.25,"dds":0.5206611570247934,"last_synced_commit":"fc03a94d941c5ae0bb4d7d4b655de6b8ae50f2c8"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faiowatttime","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faiowatttime/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faiowatttime/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faiowatttime/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bachya","download_url":"https://codeload.github.com/bachya/aiowatttime/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248886324,"owners_count":21177643,"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":[],"created_at":"2024-10-03T22:10:12.444Z","updated_at":"2025-04-14T13:11:55.784Z","avatar_url":"https://github.com/bachya.png","language":"Python","funding_links":["https://www.buymeacoffee.com/bachya1208P"],"categories":[],"sub_categories":[],"readme":"# 🌎 aiowatttime: an asyncio-based, Python3 library for WattTime emissions data\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`aiowatttime` is a Python 3, asyncio-friendly library for interacting with\n[WattTime](https://www.watttime.org) emissions data.\n\n- [Python Versions](#python-versions)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Contributing](#contributing)\n\n# Python Versions\n\n`aiowatttime` 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 aiowatttime\n```\n\n# Usage\n\n## Getting an API Key\n\nSimply clone this repo and run the included interactive script:\n\n```bash\n$ script/register\n```\n\nNote that WattTime offers three plans: Visitors, Analyst, and Pro. The type you use\nwill determine which elements of this library are available to use. You can read more\ndetails [here][watttime-data-plans].\n\n## Creating and Using a Client\n\nThe `Client` is the primary method of interacting with the API:\n\n```python\nimport asyncio\n\nfrom aiowatttime import Client\n\n\nasync def main() -\u003e None:\n    client = await Client.login(\"\u003cUSERNAME\u003e\", \"\u003cPASSWORD\u003e\")\n    # ...\n\n\nasyncio.run(main())\n```\n\nBy default, the library creates a new connection to the API 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 aiowatttime import Client\n\n\nasync def main() -\u003e None:\n    async with ClientSession() as session:\n        client = await Client.login(\"\u003cUSERNAME\u003e\", \"\u003cPASSWORD\u003e\", session=session)\n        # ...\n\n\nasyncio.run(main())\n```\n\n## Programmatically Requesting a Password Reset\n\n```python\nawait client.async_request_password_reset()\n```\n\n## Getting Emissions Data\n\n### Grid Region\n\nIt may be useful to first get the \"grid region\" (i.e., geographical info) for the area\nyou care about:\n\n```python\nawait client.emissions.async_get_grid_region(\n    \"\u003cLATITUDE\u003e\", \"\u003cLONGITUDE\u003e\", \"\u003cSIGNAL_TYPE\u003e\"\n)\n# \u003e\u003e\u003e { \"region\": \"PSCO\", \"region_full_name\": \"Public Service Co of Colorado\", \"signal_type\": \"co2_moer\" }\n```\n\nGetting emissions data will require the region abbreviation (`PSCO` in the example above).\n\n### Realtime Data\n\n```python\nawait client.emissions.async_get_realtime_emissions(\"\u003cREGION\u003e\")\n# \u003e\u003e\u003e\n{\"data\": [...]}\n```\n\n### Forecasted Data\n\n```python\nfrom datetime import datetime\n\nawait client.emissions.async_get_forecasted_emissions(\n    \"\u003cREGION\u003e\", \"\u003cSIGNAL_TYPE\u003e\", datetime(2021, 1, 1), datetime(2021, 2, 1)\n)\n# \u003e\u003e\u003e { \"data\": [ ... ] }\n```\n\n### Historical Data\n\n```python\nawait client.emissions.async_get_forecasted_emissions(\n    \"\u003cREGION\u003e\", \"\u003cSIGNAL_TYPE\u003e\", datetime(2021, 1, 1), datetime(2021, 2, 1)\n)\n# \u003e\u003e\u003e [ { \"point_time\": \"2019-02-21T00:15:00.000Z\", \"value\": 844, ... } ]\n```\n\n## Retry Logic\n\nBy default, `aiowatttime` will handle expired access tokens for you. When a token expires,\nthe library will attempt the following sequence 3 times:\n\n- Request a new token\n- Pause for 1 second (to be respectful of the API rate limiting)\n- Execute the original request again\n\nBoth the number of retries and the delay between retries can be configured when\ninstantiating a client:\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom aiowatttime import Client\n\n\nasync def main() -\u003e None:\n    async with ClientSession() as session:\n        client = await Client.async_login(\n            \"user\",\n            \"password\",\n            session=session,\n            # Make 7 retry attempts:\n            request_retries=7,\n            # Delay 4 seconds between attempts:\n            request_retry_delay=4,\n        )\n\n\nasyncio.run(main())\n```\n\nAs always, an invalid username/password combination will immediately throw an exception.\n\n## Custom Logger\n\nBy default, `aiowatttime` provides its own logger. If you should wish to use your own, you\ncan pass it to the client during instantiation:\n\n```python\nimport asyncio\nimport logging\n\nfrom aiohttp import ClientSession\n\nfrom aiowatttime import Client\n\nCUSTOM_LOGGER = logging.getLogger(\"my_custom_logger\")\n\n\nasync def main() -\u003e None:\n    async with ClientSession() as session:\n        client = await Client.async_login(\n            \"user\",\n            \"password\",\n            session=session,\n            logger=logger,\n        )\n\n\nasyncio.run(main())\n```\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 aiowatttime tests`\n9. Update `README.md` with any new documentation.\n10. Submit a pull request!\n\n[aiohttp]: https://github.com/aio-libs/aiohttp\n[ci-badge]: https://img.shields.io/github/actions/workflow/status/bachya/aiowatttime/test.yml\n[ci]: https://github.com/bachya/aiowatttime/actions\n[codecov-badge]: https://codecov.io/gh/bachya/aiowatttime/branch/dev/graph/badge.svg\n[codecov]: https://codecov.io/gh/bachya/aiowatttime\n[contributors]: https://github.com/bachya/aiowatttime/graphs/contributors\n[fork]: https://github.com/bachya/aiowatttime/fork\n[issues]: https://github.com/bachya/aiowatttime/issues\n[license-badge]: https://img.shields.io/pypi/l/aiowatttime.svg\n[license]: https://github.com/bachya/aiowatttime/blob/main/LICENSE\n[maintainability-badge]: https://api.codeclimate.com/v1/badges/781e64940b1302ae9ac3/maintainability\n[maintainability]: https://codeclimate.com/github/bachya/aiowatttime/maintainability\n[new-issue]: https://github.com/bachya/aiowatttime/issues/new\n[new-issue]: https://github.com/bachya/aiowatttime/issues/new\n[pypi-badge]: https://img.shields.io/pypi/v/aiowatttime.svg\n[pypi]: https://pypi.python.org/pypi/aiowatttime\n[version-badge]: https://img.shields.io/pypi/pyversions/aiowatttime.svg\n[version]: https://pypi.python.org/pypi/aiowatttime\n[watttime]: https://www.watttime.org\n[watttime-data-plans]: https://www.watttime.org/get-the-data/data-plans/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Faiowatttime","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbachya%2Faiowatttime","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Faiowatttime/lists"}