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.0.tar.gz (27.7 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.0-py3-none-any.whl (35.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiounifiaccess-0.1.0.tar.gz
  • Upload date:
  • Size: 27.7 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.0.tar.gz
Algorithm Hash digest
SHA256 8a786ae87bf0b43789af77193cdb63255d2d2feeccdfe22cd57a4ee601867ee4
MD5 7976e166f0b69bd531de00e0a7bc0219
BLAKE2b-256 b8e632939f75c3feca264d10549dc718bfd22d2a40afee5b0b10775e8932a6d3

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: aiounifiaccess-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab3cbb7b24e9e866dff11c76dc1f51c2da39b620cd4d42f0a7e38b8e65859ea3
MD5 f4bd6e58ff7d4acb8d3ba6a29b1359b3
BLAKE2b-256 3127a6af4e2330c728276900c23a607191dc744f337d5af02c042e18e3373ce4

See more details on using hashes here.

Provenance

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