{"id":15723156,"url":"https://github.com/bachya/aionotion","last_synced_at":"2025-04-30T22:24:28.413Z","repository":{"id":34839924,"uuid":"184301636","full_name":"bachya/aionotion","owner":"bachya","description":"A simple, asyncio-friendly Python3 library for Notion® Home Monitoring","archived":false,"fork":false,"pushed_at":"2025-02-04T20:50:13.000Z","size":1617,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-03-30T20:33:42.249Z","etag":null,"topics":["asyncio","home-automation","python3","sensor"],"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":"2019-04-30T17:10:23.000Z","updated_at":"2025-02-04T20:50:14.000Z","dependencies_parsed_at":"2023-10-20T17:08:17.713Z","dependency_job_id":"ff7f0963-9ddf-4330-a65b-5dd51fe5b5fb","html_url":"https://github.com/bachya/aionotion","commit_stats":{"total_commits":436,"total_committers":6,"mean_commits":72.66666666666667,"dds":0.3990825688073395,"last_synced_commit":"e9e8278804f0f63107dfc77d93bf34b89cb8b3e6"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faionotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faionotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faionotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bachya%2Faionotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bachya","download_url":"https://codeload.github.com/bachya/aionotion/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251790513,"owners_count":21644228,"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":["asyncio","home-automation","python3","sensor"],"created_at":"2024-10-03T22:10:30.166Z","updated_at":"2025-04-30T22:24:28.393Z","avatar_url":"https://github.com/bachya.png","language":"Python","funding_links":["https://www.buymeacoffee.com/bachya1208P"],"categories":[],"sub_categories":[],"readme":"# 📟 aionotion: a Python3, asyncio-friendly library for Notion® Home Monitoring\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`aionotion` is a Python 3, asyncio-friendly library for interacting with [Notion][notion]\nhome monitoring sensors.\n\n- [Installation](#installation)\n- [Python Versions](#python-versions)\n- [Usage](#usage)\n- [Contributing](#contributing)\n\n# Installation\n\n```bash\npip install aionotion\n```\n\n# Python Versions\n\n`aionotion` is currently supported on:\n\n- Python 3.11\n- Python 3.12\n- Python 3.13\n\n# Usage\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom aionotion import async_get_client_with_credentials\n\n\nasync def main() -\u003e None:\n    \"\"\"Create the aiohttp session and run the example.\"\"\"\n    client = await async_get_client_with_credentials(\n        \"\u003cEMAIL\u003e\", \"\u003cPASSWORD\u003e\", session=session\n    )\n\n    # Get the UUID of the authenticated user:\n    client.user_uuid\n    # \u003e\u003e\u003e xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\n\n    # Get the current refresh token of the authenticated user (BE CAREFUL):\n    client.refresh_token\n    # \u003e\u003e\u003e abcde12345\n\n    # Get all \"households\" associated with the account:\n    systems = await client.system.async_all()\n    # \u003e\u003e\u003e [System(...), System(...), ...]\n\n    # Get a system by ID:\n    system = await client.system.async_get(12345)\n    # \u003e\u003e\u003e System(...)\n\n    # Get all bridges associated with the account:\n    bridges = await client.bridge.async_all()\n    # \u003e\u003e\u003e [Bridge(...), Bridge(...), ...]\n\n    # Get a bridge by ID:\n    bridge = await client.bridge.async_get(12345)\n    # \u003e\u003e\u003e Bridge(...)\n\n    # Get all sensors:\n    sensors = await client.sensor.async_all()\n    # \u003e\u003e\u003e [Sensor(...), Sensor(...), ...]\n\n    # Get a sensor by ID:\n    sensor = await client.sensor.async_get(12345)\n    # \u003e\u003e\u003e Sensor(...)\n\n    # Get \"listeners\" (conditions that a sensor is monitoring) for all sensors:\n    listeners = await client.listener.async_all()\n    # \u003e\u003e\u003e [Listener(...), Listener(...), ...]\n\n    # Get all listener definitions supported by Notion:\n    definitions = await client.listener.async_definitions()\n    # \u003e\u003e\u003e [ListenerDefinition(...), ListenerDefinition(...), ...]\n\n    # Get user info:\n    user_info = await client.user.async_info()\n    # \u003e\u003e\u003e User(...)\n\n    # Get user preferences:\n    user_preferences = await client.user.async_preferences()\n    # \u003e\u003e\u003e UserPreferences(...)\n\n\nasyncio.run(main())\n```\n\n## Using a Refresh Token\n\nDuring the normal course of operations, `aionotion` will automatically maintain a refresh\ntoken and use it when needed. At times, you may wish to manage that token yourself (so\nthat you can use it later)–`aionotion` provides a few useful capabilities there.\n\n### Refresh Token Callbacks\n\n`aionotion` allows implementers to defining callbacks that get called when a new refresh\ntoken is generated. These callbacks accept a single string parameter (the refresh\ntoken):\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom aionotion import async_get_client_with_credentials\n\n\nasync def main() -\u003e None:\n    \"\"\"Create the aiohttp session and run the example.\"\"\"\n    client = await async_get_client_with_credentials(\n        \"\u003cEMAIL\u003e\", \"\u003cPASSWORD\u003e\", session=session\n    )\n\n    def do_somethng_with_refresh_token(refresh_token: str) -\u003e None:\n        \"\"\"Do something interesting.\"\"\"\n        pass\n\n    # Attach the callback to the client:\n    remove_callback = client.add_refresh_token_callback(do_somethng_with_refresh_token)\n\n    # Later, if you want to remove the callback:\n    remove_callback()\n\n\nasyncio.run(main())\n```\n\n### Getting a Client via a Refresh Token\n\nAll of previous examples retrieved an authenticated client with\n`async_get_client_with_credentials`. However, implementers may also create an\nauthenticated client by providing a previously retrieved user UUID and refresh token:\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom aionotion import async_get_client_with_refresh_token\n\n\nasync def main() -\u003e None:\n    \"\"\"Create the aiohttp session and run the example.\"\"\"\n    async with ClientSession() as session:\n        # Create a Notion API client:\n        client = await async_get_client_with_refresh_token(\n            \"\u003cUSER UUID\u003e\", \"\u003cREFRESH TOKEN\u003e\", session=session\n        )\n\n        # Get to work...\n\n\nasyncio.run(main())\n```\n\n## Connection Pooling\n\nBy default, the library creates a new connection to Notion with each coroutine. If you\nare calling a large number of coroutines (or merely want to squeeze out every second of\nruntime savings possible), an [`aiohttp`][aiohttp] `ClientSession` can be used for\nconnection pooling:\n\n```python\nimport asyncio\n\nfrom aiohttp import ClientSession\n\nfrom aionotion import async_get_client_with_credentials\n\n\nasync def main() -\u003e None:\n    \"\"\"Create the aiohttp session and run the example.\"\"\"\n    async with ClientSession() as session:\n        # Create a Notion API client:\n        client = await async_get_client_with_credentials(\n            \"\u003cEMAIL\u003e\", \"\u003cPASSWORD\u003e\", session=session\n        )\n\n        # Get to work...\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 aionotion 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/aionotion/test.yml\n[ci]: https://github.com/bachya/aionotion/actions\n[codecov-badge]: https://codecov.io/gh/bachya/aionotion/branch/dev/graph/badge.svg\n[codecov]: https://codecov.io/gh/bachya/aionotion\n[contributors]: https://github.com/bachya/aionotion/graphs/contributors\n[fork]: https://github.com/bachya/aionotion/fork\n[issues]: https://github.com/bachya/aionotion/issues\n[license-badge]: https://img.shields.io/pypi/l/aionotion.svg\n[license]: https://github.com/bachya/aionotion/blob/main/LICENSE\n[maintainability-badge]: https://api.codeclimate.com/v1/badges/bd79edca07c8e4529cba/maintainability\n[maintainability]: https://codeclimate.com/github/bachya/aionotion/maintainability\n[new-issue]: https://github.com/bachya/aionotion/issues/new\n[notion]: https://getnotion.com\n[pypi-badge]: https://img.shields.io/pypi/v/aionotion.svg\n[pypi]: https://pypi.python.org/pypi/aionotion\n[version-badge]: https://img.shields.io/pypi/pyversions/aionotion.svg\n[version]: https://pypi.python.org/pypi/aionotion\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Faionotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbachya%2Faionotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbachya%2Faionotion/lists"}