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.1.tar.gz (27.8 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.1-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiounifiaccess-0.1.1.tar.gz
  • Upload date:
  • Size: 27.8 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.1.tar.gz
Algorithm Hash digest
SHA256 6a6333e5c2e75e29fe778e7135d6951ca2ee2c5df12477c554fa464b346d6161
MD5 02cb1a5dad7aee821b849c9d970259c6
BLAKE2b-256 6b928192024afe37372e89fec210364e9de5cc944179b92852ebef284b8172b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiounifiaccess-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: aiounifiaccess-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 108c61e9968917c27b65c054518dff54752259feae0654372852dddaf1e5b7d3
MD5 9431ea49f8415210bc8e051612294879
BLAKE2b-256 4b8a9a9293c13b7028b4e23ffa0eb55d0baa88448eb05835483078c01550d69f

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiounifiaccess-0.1.1-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