Skip to main content

Async Python client for the UniFi Access API

Project description

aiounifiaccess

Async Python client for the UniFi Access API.

  • Full REST API coverage — all endpoints from API v4.0.10
  • Real-time events — WebSocket listener with auto-reconnect and typed event models
  • Webhook support — HMAC-SHA256 signature verification utility
  • Pydantic v2 models — fully typed request/response objects
  • Async-native — built on aiohttp for composability with other async libraries

Installation

pip install aiounifiaccess

Quick Start

import asyncio
import os
from aiounifiaccess import UniFiAccessClient

async def main():
    async with UniFiAccessClient(
        host=os.environ["UNIFI_ACCESS_HOST"],
        api_token=os.environ["UNIFI_ACCESS_TOKEN"],
    ) as client:
        # List all users
        users, pagination = await client.users.list()
        for user in users:
            print(f"{user.first_name} {user.last_name} ({user.status})")

        # Get a specific door
        door = await client.doors.get("door-id-here")
        print(f"{door.name}: {door.door_lock_relay_status}")

        # Remote unlock
        await client.doors.unlock("door-id-here", actor_name="API Script")

asyncio.run(main())

Event Listener

import asyncio
import os
from aiounifiaccess import UniFiAccessClient, DoorPositionEvent, DoorUnlockEvent

async def main():
    async with UniFiAccessClient(
        host=os.environ["UNIFI_ACCESS_HOST"],
        api_token=os.environ["UNIFI_ACCESS_TOKEN"],
    ) as client:

        @client.on(DoorPositionEvent)
        async def handle_dps(event: DoorPositionEvent):
            status = event.data.object.status
            door = event.data.location.name
            print(f"{door} is now {status}")

        @client.on(DoorUnlockEvent)
        async def handle_unlock(event: DoorUnlockEvent):
            actor = event.data.actor.name
            door = event.data.location.name
            print(f"{actor} unlocked {door}")

        await client.listen()

asyncio.run(main())

Webhook Verification

from aiounifiaccess import verify_webhook_signature

is_valid = verify_webhook_signature(
    secret="your_webhook_secret",
    signature_header=request.headers["Signature"],
    body=await request.read(),
)

API Managers

Manager Attribute Endpoints
Users client.users 29
Visitors client.visitors 13
Access Policies client.access_policies 15
Credentials client.credentials 17
Doors client.doors 13
Devices client.devices 4
System Logs client.system_logs 4
Identity client.identity 6
Webhooks client.webhooks 4
Server client.server 2

Compatibility

Library Version API Reference Version
0.1.x 4.0.10

Requirements

  • Python 3.11+
  • aiohttp >= 3.9
  • pydantic >= 2.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiounifiaccess-0.1.3.tar.gz (27.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiounifiaccess-0.1.3-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file aiounifiaccess-0.1.3.tar.gz.

File metadata

  • Download URL: aiounifiaccess-0.1.3.tar.gz
  • Upload date:
  • Size: 27.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiounifiaccess-0.1.3.tar.gz
Algorithm Hash digest
SHA256 084f9d47141230454dffa8b6601652a9e387bc753da9d9d857746239e1999c22
MD5 9abde723dd44f10e28efa384a46cc913
BLAKE2b-256 c31e0b960790b0a7f960cd878e9d70315575f8e03d81ba3e67c68cdd9a835cfd

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiounifiaccess-0.1.3.tar.gz:

Publisher: publish.yml on realworldtech/aiounifiaccess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiounifiaccess-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: aiounifiaccess-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiounifiaccess-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2c3e45c476999bd36438dbb5231fe58c851ca6f39e6838fa60e5cd72a9a636f5
MD5 a79d5e28478164ebef19911ba43d07b5
BLAKE2b-256 5082855fcab4d3e1a6e0489a122671d92a826648d7d85dc34e9726d07ab39f02

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiounifiaccess-0.1.3-py3-none-any.whl:

Publisher: publish.yml on realworldtech/aiounifiaccess

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page