aioesphomeapi


Nameaioesphomeapi JSON
Version 28.0.0 PyPI version JSON
download
home_pagehttps://esphome.io/
SummaryPython API for interacting with ESPHome devices.
upload_time2024-12-06 01:42:39
maintainerNone
docs_urlNone
authorOtto Winter
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements aiohappyeyeballs async-interrupt protobuf zeroconf chacha20poly1305-reuseable cryptography noiseprotocol async-timeout
Travis-CI No Travis.
coveralls test coverage
            aioesphomeapi
=============

.. image:: https://github.com/esphome/aioesphomeapi/workflows/CI/badge.svg
   :target: https://github.com/esphome/aioesphomeapi?query=workflow%3ACI+branch%3Amain

.. image:: https://img.shields.io/pypi/v/aioesphomeapi.svg
    :target: https://pypi.python.org/pypi/aioesphomeapi

.. image:: https://codecov.io/gh/esphome/aioesphomeapi/branch/main/graph/badge.svg
   :target: https://app.codecov.io/gh/esphome/aioesphomeapi/tree/main

``aioesphomeapi`` allows you to interact with devices flashed with `ESPHome <https://esphome.io/>`_.

Installation
------------

The module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.

.. code:: bash

    $ pip3 install aioesphomeapi

An optional cython extension is available for better performance, and the module will try to build it automatically.

The extension requires a C compiler and Python development headers. The module will fall back to the pure Python implementation if they are unavailable.

Building the extension can be forcefully disabled by setting the environment variable ``SKIP_CYTHON`` to ``1``.

Usage
-----

It's required that you enable the `Native API <https://esphome.io/components/api.html>`_ component for the device.

.. code:: yaml

   # Example configuration entry
   api:
     password: 'MyPassword'

Check the output to get the local address of the device or use the ``name:``under ``esphome:`` from the device configuration.

.. code:: bash

   [17:56:38][C][api:095]: API Server:
   [17:56:38][C][api:096]:   Address: api_test.local:6053


The sample code below will connect to the device and retrieve details.

.. code:: python

   import aioesphomeapi
   import asyncio

   async def main():
       """Connect to an ESPHome device and get details."""

       # Establish connection
       api = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword")
       await api.connect(login=True)

       # Get API version of the device's firmware
       print(api.api_version)

       # Show device details
       device_info = await api.device_info()
       print(device_info)

       # List all entities of the device
       entities = await api.list_entities_services()
       print(entities)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

Subscribe to state changes of an ESPHome device.

.. code:: python

   import aioesphomeapi
   import asyncio

   async def main():
       """Connect to an ESPHome device and wait for state changes."""
       cli = aioesphomeapi.APIClient("api_test.local", 6053, "MyPassword")

       await cli.connect(login=True)

       def change_callback(state):
           """Print the state changes of the device.."""
           print(state)

       # Subscribe to the state changes
       await cli.subscribe_states(change_callback)

   loop = asyncio.get_event_loop()
   try:
       asyncio.ensure_future(main())
       loop.run_forever()
   except KeyboardInterrupt:
       pass
   finally:
       loop.close()

Other examples:

- `Camera <https://gist.github.com/micw/202f9dee5c990f0b0f7e7c36b567d92b>`_
- `Async print <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-print-async-py>`_
- `Simple print <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-print-simple-py>`_
- `InfluxDB <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-sensor-influxdb-py>`_

Development
-----------

For development is recommended to use a Python virtual environment (``venv``).

.. code:: bash

    # Setup virtualenv (optional)
    $ python3 -m venv .
    $ source bin/activate
    # Install aioesphomeapi and development depenencies
    $ pip3 install -e .
    $ pip3 install -r requirements_test.txt

    # Run linters & test
    $ script/lint
    # Update protobuf _pb2.py definitions (requires a protobuf compiler installation)
    $ script/gen-protoc

A cli tool is also available for watching logs:

.. code:: bash

   aioesphomeapi-logs --help

A cli tool is also available to discover devices:

.. code:: bash

   aioesphomeapi-discover

License
-------

``aioesphomeapi`` is licensed under MIT, for more details check LICENSE.

            

Raw data

            {
    "_id": null,
    "home_page": "https://esphome.io/",
    "name": "aioesphomeapi",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Otto Winter",
    "author_email": "esphome@nabucasa.com",
    "download_url": "https://files.pythonhosted.org/packages/18/a8/21b736df2ff8e291bdb499d2c1b5470d6a0b410135d901bfb0c5e041eb91/aioesphomeapi-28.0.0.tar.gz",
    "platform": null,
    "description": "aioesphomeapi\n=============\n\n.. image:: https://github.com/esphome/aioesphomeapi/workflows/CI/badge.svg\n   :target: https://github.com/esphome/aioesphomeapi?query=workflow%3ACI+branch%3Amain\n\n.. image:: https://img.shields.io/pypi/v/aioesphomeapi.svg\n    :target: https://pypi.python.org/pypi/aioesphomeapi\n\n.. image:: https://codecov.io/gh/esphome/aioesphomeapi/branch/main/graph/badge.svg\n   :target: https://app.codecov.io/gh/esphome/aioesphomeapi/tree/main\n\n``aioesphomeapi`` allows you to interact with devices flashed with `ESPHome <https://esphome.io/>`_.\n\nInstallation\n------------\n\nThe module is available from the `Python Package Index <https://pypi.python.org/pypi>`_.\n\n.. code:: bash\n\n    $ pip3 install aioesphomeapi\n\nAn optional cython extension is available for better performance, and the module will try to build it automatically.\n\nThe extension requires a C compiler and Python development headers. The module will fall back to the pure Python implementation if they are unavailable.\n\nBuilding the extension can be forcefully disabled by setting the environment variable ``SKIP_CYTHON`` to ``1``.\n\nUsage\n-----\n\nIt's required that you enable the `Native API <https://esphome.io/components/api.html>`_ component for the device.\n\n.. code:: yaml\n\n   # Example configuration entry\n   api:\n     password: 'MyPassword'\n\nCheck the output to get the local address of the device or use the ``name:``under ``esphome:`` from the device configuration.\n\n.. code:: bash\n\n   [17:56:38][C][api:095]: API Server:\n   [17:56:38][C][api:096]:   Address: api_test.local:6053\n\n\nThe sample code below will connect to the device and retrieve details.\n\n.. code:: python\n\n   import aioesphomeapi\n   import asyncio\n\n   async def main():\n       \"\"\"Connect to an ESPHome device and get details.\"\"\"\n\n       # Establish connection\n       api = aioesphomeapi.APIClient(\"api_test.local\", 6053, \"MyPassword\")\n       await api.connect(login=True)\n\n       # Get API version of the device's firmware\n       print(api.api_version)\n\n       # Show device details\n       device_info = await api.device_info()\n       print(device_info)\n\n       # List all entities of the device\n       entities = await api.list_entities_services()\n       print(entities)\n\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(main())\n\nSubscribe to state changes of an ESPHome device.\n\n.. code:: python\n\n   import aioesphomeapi\n   import asyncio\n\n   async def main():\n       \"\"\"Connect to an ESPHome device and wait for state changes.\"\"\"\n       cli = aioesphomeapi.APIClient(\"api_test.local\", 6053, \"MyPassword\")\n\n       await cli.connect(login=True)\n\n       def change_callback(state):\n           \"\"\"Print the state changes of the device..\"\"\"\n           print(state)\n\n       # Subscribe to the state changes\n       await cli.subscribe_states(change_callback)\n\n   loop = asyncio.get_event_loop()\n   try:\n       asyncio.ensure_future(main())\n       loop.run_forever()\n   except KeyboardInterrupt:\n       pass\n   finally:\n       loop.close()\n\nOther examples:\n\n- `Camera <https://gist.github.com/micw/202f9dee5c990f0b0f7e7c36b567d92b>`_\n- `Async print <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-print-async-py>`_\n- `Simple print <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-print-simple-py>`_\n- `InfluxDB <https://gist.github.com/fpletz/d071c72e45d17ba274fd61ca7a465033#file-esphome-sensor-influxdb-py>`_\n\nDevelopment\n-----------\n\nFor development is recommended to use a Python virtual environment (``venv``).\n\n.. code:: bash\n\n    # Setup virtualenv (optional)\n    $ python3 -m venv .\n    $ source bin/activate\n    # Install aioesphomeapi and development depenencies\n    $ pip3 install -e .\n    $ pip3 install -r requirements_test.txt\n\n    # Run linters & test\n    $ script/lint\n    # Update protobuf _pb2.py definitions (requires a protobuf compiler installation)\n    $ script/gen-protoc\n\nA cli tool is also available for watching logs:\n\n.. code:: bash\n\n   aioesphomeapi-logs --help\n\nA cli tool is also available to discover devices:\n\n.. code:: bash\n\n   aioesphomeapi-discover\n\nLicense\n-------\n\n``aioesphomeapi`` is licensed under MIT, for more details check LICENSE.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python API for interacting with ESPHome devices.",
    "version": "28.0.0",
    "project_urls": {
        "Download": "https://github.com/esphome/aioesphomeapi/archive/28.0.0.zip",
        "Homepage": "https://esphome.io/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "df82e545bf8bc9da1b6b84ca36ebc0b7282ddeb26615de3d14f5e36a767d9571",
                "md5": "64ba198c2aae494a5c93aca363f082fb",
                "sha256": "868307672abf2c955565406b8a7b3315e27979e9de9a6d0bfe2252736d4ac9c3"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "64ba198c2aae494a5c93aca363f082fb",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9",
            "size": 2399162,
            "upload_time": "2024-12-06T01:42:19",
            "upload_time_iso_8601": "2024-12-06T01:42:19.887312Z",
            "url": "https://files.pythonhosted.org/packages/df/82/e545bf8bc9da1b6b84ca36ebc0b7282ddeb26615de3d14f5e36a767d9571/aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5e99cf4e54921a95741489a2be5950bf8b8bd4561007f9b24af78062e36cc5e",
                "md5": "f98bdbb8e229468e020d1334f4a3199d",
                "sha256": "b0b427659556fd646d31cbc3b8ae749f76d5de6f9751a07d6c407796b8ac597f"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "f98bdbb8e229468e020d1334f4a3199d",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9",
            "size": 2395996,
            "upload_time": "2024-12-06T01:42:22",
            "upload_time_iso_8601": "2024-12-06T01:42:22.260194Z",
            "url": "https://files.pythonhosted.org/packages/a5/e9/9cf4e54921a95741489a2be5950bf8b8bd4561007f9b24af78062e36cc5e/aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d7a396d6dca34a9fd73e5a96ff63356c88898fb685878e2515b1652dcecb909b",
                "md5": "4eb9379d0832eefcd004944d188c3921",
                "sha256": "a7d915906f8b8eefd54dba832d417676ca7c3c704d7041e49ae91a9b258b3ece"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "4eb9379d0832eefcd004944d188c3921",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9",
            "size": 2294982,
            "upload_time": "2024-12-06T01:42:24",
            "upload_time_iso_8601": "2024-12-06T01:42:24.442586Z",
            "url": "https://files.pythonhosted.org/packages/d7/a3/96d6dca34a9fd73e5a96ff63356c88898fb685878e2515b1652dcecb909b/aioesphomeapi-28.0.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a03fca46063df2c581fdf329e7fc065af4b7a01f38e8cb860d98724f25d4a5e",
                "md5": "d7afb6c23a5281ad989173499c25a393",
                "sha256": "e0e9488e7ec64ac59b7e6acb7d51eb749b1a064a6ba5eba1c9e79cb27b82f1a9"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "d7afb6c23a5281ad989173499c25a393",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9",
            "size": 2419607,
            "upload_time": "2024-12-06T01:42:27",
            "upload_time_iso_8601": "2024-12-06T01:42:27.020934Z",
            "url": "https://files.pythonhosted.org/packages/7a/03/fca46063df2c581fdf329e7fc065af4b7a01f38e8cb860d98724f25d4a5e/aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "96cd329d4fbd0ad70e433c02d5c6c65c62c4b4a9f4b2bb3e653284dbe5dc6546",
                "md5": "fe6d86b536ade10fb4de789f621bb3cf",
                "sha256": "261b8421e0a3526de17f93fa3e57abcbbb42f086a425fb9e2c299ec3b3bfc7e0"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "fe6d86b536ade10fb4de789f621bb3cf",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9",
            "size": 2446624,
            "upload_time": "2024-12-06T01:42:29",
            "upload_time_iso_8601": "2024-12-06T01:42:29.220212Z",
            "url": "https://files.pythonhosted.org/packages/96/cd/329d4fbd0ad70e433c02d5c6c65c62c4b4a9f4b2bb3e653284dbe5dc6546/aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed85cd222d3b5c0c29f7545888e7ec33b70188f9e4a6435f6f9e4e6d2e851fc3",
                "md5": "d60a6a9f8f27066701d82095a4afb0a4",
                "sha256": "6692675a2d7253e652809d3e5c59bc5b048a595a6f5d6a3081bca0abd3ad6613"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "d60a6a9f8f27066701d82095a4afb0a4",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9",
            "size": 2302760,
            "upload_time": "2024-12-06T01:42:31",
            "upload_time_iso_8601": "2024-12-06T01:42:31.388787Z",
            "url": "https://files.pythonhosted.org/packages/ed/85/cd222d3b5c0c29f7545888e7ec33b70188f9e4a6435f6f9e4e6d2e851fc3/aioesphomeapi-28.0.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a987ae1bc185165c5abd6ee59ce4cf9a0048fd6b0bd655b27c2eefacbbb0b29",
                "md5": "fe9fe6b8e9bd8917c0d07b10dd081b4b",
                "sha256": "833b615d50dc4653bb53e22800714bd4725649e994e2516c015e9b2389ba2a3a"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "has_sig": false,
            "md5_digest": "fe9fe6b8e9bd8917c0d07b10dd081b4b",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.9",
            "size": 2393911,
            "upload_time": "2024-12-06T01:42:33",
            "upload_time_iso_8601": "2024-12-06T01:42:33.554007Z",
            "url": "https://files.pythonhosted.org/packages/3a/98/7ae1bc185165c5abd6ee59ce4cf9a0048fd6b0bd655b27c2eefacbbb0b29/aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79034b40f1347627ae2aad96b946bf974c53d348195d67c806f907d8b3d847af",
                "md5": "a7f2c932861908c2366282abf6034317",
                "sha256": "b448fb11370a9027ef6b1d83f0375dc56f54af97cb722e9abc9547d03f8fa482"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a7f2c932861908c2366282abf6034317",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.9",
            "size": 2420817,
            "upload_time": "2024-12-06T01:42:35",
            "upload_time_iso_8601": "2024-12-06T01:42:35.234544Z",
            "url": "https://files.pythonhosted.org/packages/79/03/4b40f1347627ae2aad96b946bf974c53d348195d67c806f907d8b3d847af/aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "452f2e51cd321a8dd53ae0c858684f6e5df07650dabbda0f264c0a0a018e33c1",
                "md5": "0ff6804c1545b83d1765f64058e06704",
                "sha256": "8b9c22f550562acb837ba37cfbadcbfd778485da65db07ecc567171ac1b6d61b"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "has_sig": false,
            "md5_digest": "0ff6804c1545b83d1765f64058e06704",
            "packagetype": "bdist_wheel",
            "python_version": "cp313",
            "requires_python": ">=3.9",
            "size": 2275145,
            "upload_time": "2024-12-06T01:42:37",
            "upload_time_iso_8601": "2024-12-06T01:42:37.501343Z",
            "url": "https://files.pythonhosted.org/packages/45/2f/2e51cd321a8dd53ae0c858684f6e5df07650dabbda0f264c0a0a018e33c1/aioesphomeapi-28.0.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "18a821b736df2ff8e291bdb499d2c1b5470d6a0b410135d901bfb0c5e041eb91",
                "md5": "24676c399646047bfa5cc27f136600b5",
                "sha256": "2ba5377ad519e81e93cdfccef0f5eb80f861fd016e96a35696d854ece6bb6601"
            },
            "downloads": -1,
            "filename": "aioesphomeapi-28.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "24676c399646047bfa5cc27f136600b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 100612,
            "upload_time": "2024-12-06T01:42:39",
            "upload_time_iso_8601": "2024-12-06T01:42:39.111632Z",
            "url": "https://files.pythonhosted.org/packages/18/a8/21b736df2ff8e291bdb499d2c1b5470d6a0b410135d901bfb0c5e041eb91/aioesphomeapi-28.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-06 01:42:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "esphome",
    "github_project": "aioesphomeapi",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohappyeyeballs",
            "specs": [
                [
                    ">=",
                    "2.3.0"
                ]
            ]
        },
        {
            "name": "async-interrupt",
            "specs": [
                [
                    ">=",
                    "1.2.0"
                ]
            ]
        },
        {
            "name": "protobuf",
            "specs": [
                [
                    ">=",
                    "4"
                ]
            ]
        },
        {
            "name": "zeroconf",
            "specs": [
                [
                    ">=",
                    "0.132.2"
                ],
                [
                    "<",
                    "1.0"
                ]
            ]
        },
        {
            "name": "chacha20poly1305-reuseable",
            "specs": [
                [
                    ">=",
                    "0.13.2"
                ]
            ]
        },
        {
            "name": "cryptography",
            "specs": [
                [
                    ">=",
                    "43.0.0"
                ]
            ]
        },
        {
            "name": "noiseprotocol",
            "specs": [
                [
                    "<",
                    "1.0"
                ],
                [
                    ">=",
                    "0.3.1"
                ]
            ]
        },
        {
            "name": "async-timeout",
            "specs": [
                [
                    ">=",
                    "4.0"
                ]
            ]
        }
    ],
    "lcname": "aioesphomeapi"
}
        
Elapsed time: 2.73734s