xknx
XKNX - A KNX library written in Python
An asynchronous KNX library written in Python
XKNX is an MIT-licensed Python library for talking to KNX home and building automation devices, and it underpins the KNX integration in Home Assistant.
What XKNX does
XKNX is an asynchronous KNX library written in Python. KNX is a standard for home and building automation that lets devices such as lights, switches, blinds, and thermostats communicate over a bus, and XKNX gives a Python program a clean way to join that bus and control those devices. The README points to xknx.io for full documentation and asks the community for help testing and improving the library through issues, Discord, or email. The project states that XKNX is the underlying library for the KNX integration in Home Assistant, which is a significant fact for estimating its real world reach: a large share of Home Assistant users who run KNX are indirectly relying on this code. The README also notes attributions to hardware partners, specifically Enertex Bayern, Weinzierl Engineering, and MDT technologies, who provided devices to support testing and development. That hardware access matters for a bus protocol library because correct behavior depends on talking to real devices, not only to specifications. The overall shape of the project is a focused, single-protocol library rather than a general home automation framework, and the documentation and examples reflect that narrow, deep scope. The badge row shows code coverage tracked through Codecov and static typing checked with mypy, two signals that the maintainers treat correctness as a continuing requirement for a library others import.
Development and testing setup
The README gives concrete setup steps for contributors. It requires at least Python 3.11 to use XKNX. The local environment is created with uv, the package manager, by running uv sync, and git hooks are installed with uv run prek install. Dependencies are declared in pyproject.toml and pinned in uv.lock. For quality checks, the README says to run uv run prek run with the all files flag to trigger linters, formatters, and the type checker together. Unit tests run with uv run pytest, and a single test can be targeted with a path and a filter, as shown by the example that runs one individual address serial number write failure test. Testing against another supported Python version is done with uv run followed by the Python version and pytest. The presence of mypy in the badge row and prek in the workflow suggests the maintainers care about static typing and consistent tooling, which is a good sign for a library meant to be imported by other projects. The Discord link and codecov badge indicate an active community and a tracked test coverage number, both of which help a new user judge whether the library is maintained at a level they can depend on.
A minimal control example
The README includes a short Python example that switches a light on and off, which is the clearest illustration of the library's async design. The code imports asyncio and the XKNX package, then imports the Light device from xknx dot devices. Inside an async main function, the example opens an XKNX context, creates a Light with a name and a group address switch of 1/0/9, adds it to the device list with async add, calls await light dot set on, sleeps for two seconds with asyncio, and then calls await light dot set off. Finally asyncio dot run starts the coroutine. The example shows the core patterns a user must learn: the library is asynchronous, devices are plain Python objects addressed by KNX group addresses, and the XKNX object is used as a context manager that connects to the KNX or IP bus. The sleep stands in for whatever real logic a program would run between actions. For someone new to KNX, the 1/0/9 address is a group address rather than a device address, which is the mental model the library expects. This small snippet, together with the Home Assistant note, gives a reader enough to decide whether XKNX fits their automation project before they read the longer documentation.
Editorial conclusion
XKNX is released under the MIT license, is written in Python, and was last updated on GitHub on 2026-08-24 with 341 stars recorded at the time of the snapshot.
Community notes