py-unifi-access
Async Python client for the UniFi Access local API with WebSocket event support. Designed for Home Assistant Core integrations.
Features
- Async REST client (
aiohttp) for doors, lock rules, emergency status - WebSocket with auto-reconnect and exponential backoff
- Typed Pydantic v2 models for all API responses and 13 WebSocket event types
- Stateless design for Home Assistant's
DataUpdateCoordinatorpattern
Installation
pip install py-unifi-access
Usage
import aiohttp
from unifi_access_api import UnifiAccessApiClient
async with aiohttp.ClientSession() as session:
client = UnifiAccessApiClient("192.168.1.1", "your-api-token", session)
# Authenticate
await client.authenticate()
# Get all doors (keyed by ID for quick lookup)
doors = {d.id: d for d in await client.get_doors()}
for door in doors.values():
print(f"{door.name}: {door.door_position_status}")
# Unlock a specific door by ID
await client.unlock_door("your-door-id")
# WebSocket for real-time events
ws = client.start_websocket({
"access.data.device.update": lambda msg: print(msg),
})
Capturing WebSocket Messages
If you encounter parsing errors or unexpected behaviour with WebSocket events,
capturing the raw message stream helps narrow down the issue.
The CLI (included in the cli extra) writes two files to the current directory:
| File | Content |
|---|---|
events_<datetime>_raw.jsonl |
All raw events, written before parsing |
events_<datetime>_parsed.jsonl |
Successfully parsed events only |
# 1. Create and activate a virtual environment
python3 -m venv .venv
source .venv/bin/activate
# 2. Install the package with CLI dependencies
pip install "py-unifi-access[cli]"
# 3. Record events (60 seconds, for example)
unifi-access -H 192.168.1.1 -t <TOKEN> --no-verify-ssl listen -d 60
Trigger the action you want to inspect (e.g. an access request) during the
capture window, then review the events_*_raw.jsonl file before sharing it
when reporting an issue. Raw payloads may contain sensitive data such as
tokens or identifiers (for example MAC addresses and device/user names), so
please redact secrets/identifiers first or share the file privately if needed.
Development
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pre-commit install
pytest tests/ --cov
Releases
Merges to main now trigger an automatic release when the version in pyproject.toml
changes. The workflow will:
- run CI
- build the package
- publish it to PyPI
- create and push a matching Git tag
- create a GitHub release with generated notes
To make PyPI publishing work, configure a PyPI trusted publisher for this GitHub repository and environment:
- repository:
imhotep/py-unifi-access - workflow file:
ci.yml - environment:
pypi
Metadata
Release files for py-unifi-access 1.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_unifi_access-1.6.2.tar.gz | 38.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_unifi_access-1.6.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.2 kB
Release files / py_unifi_access-1.6.2.tar.gz
| Download URL | py_unifi_access-1.6.2.tar.gz |
|---|---|
| Size | 38.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
953fc8641ea1fdad5da5806f6711a50680042590dbf72122ee880f12b70e1e5a
|
|
BLAKE2b-256 checksum How to use checksums |
fce1a8d1fc40fb1193de8f6d68ac0057eb00864d5792f97c8419cd7eb3cedacc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency logRelease files / py_unifi_access-1.6.2-py3-none-any.whl
| Download URL | py_unifi_access-1.6.2-py3-none-any.whl |
|---|---|
| Size | 24.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64f601fd26fdb2d85a82867d5c486da57aa7d5da6b3c14c9c19e8f4a95b28a44
|
|
BLAKE2b-256 checksum How to use checksums |
f1fa34634a7b9fe4c97dcc673de6baf4f77ca634da670c4348203b74e90ce7c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.
Transparency log