=============== LIBRARY RULES =============== From library maintainers: - All I/O operations must be async using aiohttp and must use await - Always use context managers (async with) for client session lifecycle management - Use Pydantic v2 models with Field(alias=...) for camelCase API responses - Implement endpoints by inheriting from client and accessing _get, _post, _put, _patch, _delete methods - Never hardcode or log API keys - Let exceptions propagate from the exceptions module rather than swallowing them - Include comprehensive docstrings with Args, Returns, and Raises sections - Maintain minimum Python 3.11 compatibility ### Install and Use Pre-commit Hooks Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install pre-commit and its git hooks. Optionally, run all hooks against all files to ensure code quality. ```bash pip install pre-commit pre-commit install pre-commit run --all-files ``` -------------------------------- ### Install UniFi Official API Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install the base UniFi Official API library using pip. This is the primary installation command. ```bash pip install unifi-official-api ``` -------------------------------- ### Install UniFi Official API with Documentation Dependencies Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install the library with documentation generation tools. This is for users who want to build or modify the documentation. ```bash pip install unifi-official-api[docs] ``` -------------------------------- ### Install UniFi Official API with Test Dependencies Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install the library along with test dependencies. This is useful for running tests or contributing to the project. ```bash pip install unifi-official-api[test] ``` -------------------------------- ### Install UniFi Official API with All Development Dependencies Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install the library with all available development dependencies, including test, linting, and documentation tools. ```bash pip install unifi-official-api[dev] ``` -------------------------------- ### Clone Repository and Install Dependencies Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Clone the Unifi Official API repository and install development dependencies including pre-commit hooks. ```bash git clone https://github.com/ruaan-deysel/unifi-official-api.git cd unifi-official-api pip install -e ".[dev]" pre-commit install ``` -------------------------------- ### Install UniFi Official API with Linting Dependencies Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Install the library with linting and type checking tools. This helps maintain code quality. ```bash pip install unifi-official-api[lint] ``` -------------------------------- ### Interact with UniFi Protect API Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Utilize the UniFi Protect API to manage cameras and retrieve event data. Requires an API key and site ID. This snippet demonstrates getting camera information, snapshots, and motion events. ```python import asyncio from unifi_official_api import ApiKeyAuth from unifi_official_api.protect import UniFiProtectClient async def main(): async with UniFiProtectClient( auth=ApiKeyAuth(api_key="your-api-key"), ) as client: # Get available hosts hosts = await client.get_hosts() host_id = hosts[0]["id"] site_id = "your-site-id" # List all cameras cameras = await client.cameras.get_all(host_id, site_id) for camera in cameras: print(f"Camera: {camera.name} - Recording: {camera.is_recording}") # Get a camera snapshot if cameras: snapshot = await client.cameras.get_snapshot( host_id, site_id, cameras[0].id ) with open("snapshot.jpg", "wb") as f: f.write(snapshot) # List recent motion events events = await client.events.list_motion_events( host_id, site_id, limit=10 ) asyncio.run(main()) ``` -------------------------------- ### UniFi Protect API - Cameras Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect cameras, including listing, retrieving, updating, getting snapshots, controlling PTZ, and managing RTSP streams and talkback sessions. ```APIDOC ## Cameras ### Description Endpoints for managing UniFi Protect cameras. ### Methods - list - get - update - get_snapshot - ptz_patrol_start - ptz_patrol_stop - ptz_goto_preset - create_rtsps_stream - delete_rtsps_stream - create_talkback_session ``` -------------------------------- ### UniFi Network API - Networks Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network networks, including listing, retrieving, creating, updating, deleting, and getting network references. ```APIDOC ## Networks ### Description Endpoints for managing UniFi Network networks. ### Methods - list - get - create - update - delete - get_references ``` -------------------------------- ### Configure Local UniFi Protect Client Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Instantiate a UniFiProtectClient for direct local connections to UniFi Protect. Disable SSL verification if using self-signed certificates. ```python from unifi_official_api import LocalAuth from unifi_official_api.protect import UniFiProtectClient client = UniFiProtectClient( auth=LocalAuth( api_key="local-api-key", verify_ssl=False, # Disable SSL verification for self-signed certs ), base_url="https://192.168.1.1:7443", ) ``` -------------------------------- ### Configure Local UniFi Network Client Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Set up a UniFiNetworkClient for local connections, specifying authentication, base URL, connection type, and timeouts. SSL verification can be disabled for self-signed certificates. ```python from unifi_official_api import LocalAuth, ConnectionType from unifi_official_api.network import UniFiNetworkClient # Local connection client = UniFiNetworkClient( auth=LocalAuth( api_key="your-local-api-key", verify_ssl=False, # For self-signed certificates ), base_url="https://192.168.1.1", # Your device IP connection_type=ConnectionType.LOCAL, timeout=30, # Request timeout in seconds connect_timeout=10, # Connection timeout in seconds ) ``` -------------------------------- ### Run Linting and Type Checking Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Execute linting with Ruff and type checking with Mypy on the project's source and test files. ```bash ruff check src tests mypy src ``` -------------------------------- ### Configure Remote UniFi Network Client Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Configure a UniFiNetworkClient for remote/cloud connections using an API key and console ID. Set request and connection timeouts as needed. ```python from unifi_official_api import ApiKeyAuth client = UniFiNetworkClient( auth=ApiKeyAuth(api_key="your-cloud-api-key"), connection_type=ConnectionType.REMOTE, console_id="your-console-id", # Required for REMOTE connections timeout=30, connect_timeout=10, ) ``` -------------------------------- ### Run Tests Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Execute all project tests using pytest. Coverage reports can be generated, and specific test files can be targeted. ```bash pytest pytest --cov=unifi_official_api --cov-report=html pytest tests/network/test_client.py ``` -------------------------------- ### UniFi Protect API - Live Views Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect live views, including listing, retrieving, creating, updating, and deleting them. ```APIDOC ## Live Views ### Description Endpoints for managing UniFi Protect live views. ### Methods - list - get - create - update - delete ``` -------------------------------- ### UniFi Protect API - Lights Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect lights, including listing, retrieving, and updating light settings. ```APIDOC ## Lights ### Description Endpoints for managing UniFi Protect lights. ### Methods - list - get - update ``` -------------------------------- ### UniFi Protect API - Application Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for retrieving UniFi Protect application information, files, uploading files, and triggering webhooks. ```APIDOC ## Application ### Description Endpoints for UniFi Protect application management. ### Methods - get_info - get_files - upload_file - trigger_alarm_webhook ``` -------------------------------- ### UniFi Network API - Vouchers Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network WiFi vouchers, including listing, retrieving, creating, and deleting vouchers. ```APIDOC ## Vouchers ### Description Endpoints for managing UniFi Network WiFi vouchers. ### Methods - list - get - create - delete - delete_multiple ``` -------------------------------- ### Local Connection to UniFi Device Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Connect directly to your UniFi device (UDM, UDM-Pro, etc.) using its IP address. Disable SSL verification if using self-signed certificates. Requires a local API key. ```python import asyncio from unifi_official_api import LocalAuth, ConnectionType from unifi_official_api.network import UniFiNetworkClient async def main(): async with UniFiNetworkClient( auth=LocalAuth( api_key="your-local-api-key", verify_ssl=False, # Disable SSL verification for self-signed certs ), base_url="https://192.168.1.1", # Your device IP connection_type=ConnectionType.LOCAL, ) as client: # List all sites sites = await client.sites.get_all() site_id = sites[0].id # Use the actual site ID # List all devices devices = await client.devices.get_all(site_id) for device in devices: print(f"Device: {device.name} ({device.mac})") # List connected clients clients = await client.clients.get_all(site_id) for client_info in clients: print(f"Client: {client_info.display_name} - {client_info.ip}") asyncio.run(main()) ``` -------------------------------- ### UniFi Network API - Devices Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network devices, including listing, retrieving, restarting, adopting, forgetting, locating, and executing actions on devices. ```APIDOC ## Devices ### Description Endpoints for managing UniFi Network devices. ### Methods - list - get - restart - adopt - forget - locate - get_statistics - execute_action ``` -------------------------------- ### UniFi Protect API - Viewers Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect viewers, including listing, retrieving, updating, and setting live views for viewers. ```APIDOC ## Viewers ### Description Endpoints for managing UniFi Protect viewers. ### Methods - list - get - update - set_liveview ``` -------------------------------- ### UniFi Network API - Firewall Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network firewall zones and rules, including listing, retrieving, creating, updating, and deleting them. ```APIDOC ## Firewall ### Description Endpoints for managing UniFi Network firewall zones and rules. ### Methods - list_zones - get_zone - create_zone - update_zone - delete_zone - list_rules - get_rule - create_rule - update_rule - delete_rule ``` -------------------------------- ### UniFi Protect API - Events Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for retrieving UniFi Protect events, including motion events, smart detection events, thumbnails, and heatmaps. ```APIDOC ## Events ### Description Endpoints for retrieving UniFi Protect events. ### Methods - list - get - get_thumbnail - get_heatmap - list_motion_events - list_smart_detect_events ``` -------------------------------- ### UniFi Protect API - WebSocket Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for subscribing to UniFi Protect device and event updates via WebSocket. ```APIDOC ## WebSocket ### Description Endpoints for subscribing to UniFi Protect updates via WebSocket. ### Methods - subscribe_devices - subscribe_events ``` -------------------------------- ### UniFi Network API - Clients Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network clients, including listing, retrieving, blocking, unblocking, reconnecting, forgetting, and executing actions on clients. ```APIDOC ## Clients ### Description Endpoints for managing UniFi Network clients. ### Methods - list - get - block - unblock - reconnect - forget - execute_action ``` -------------------------------- ### UniFi Network API - Sites Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network sites, including listing and retrieving site details. ```APIDOC ## Sites ### Description Endpoints for managing UniFi Network sites. ### Methods - list - get ``` -------------------------------- ### UniFi Network API - WiFi Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network WiFi settings, including listing, retrieving, creating, updating, and deleting WiFi networks. ```APIDOC ## WiFi ### Description Endpoints for managing UniFi Network WiFi settings. ### Methods - list - get - create - update - delete ``` -------------------------------- ### UniFi Network API - Resources Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for retrieving various UniFi Network resource information, such as WAN interfaces, VPNs, RADIUS profiles, and device tags. ```APIDOC ## Resources ### Description Endpoints for retrieving various UniFi Network resource information. ### Methods - get_wan_interfaces - get_vpn_tunnels - get_vpn_servers - get_radius_profiles - get_device_tags ``` -------------------------------- ### Remote Connection via Ubiquiti Cloud API Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Connect to your UniFi devices through Ubiquiti's cloud API. This method requires an API key and a console ID. It is suitable for remote access. ```python import asyncio from unifi_official_api import ApiKeyAuth, ConnectionType from unifi_official_api.network import UniFiNetworkClient async def main(): async with UniFiNetworkClient( auth=ApiKeyAuth(api_key="your-cloud-api-key"), connection_type=ConnectionType.REMOTE, console_id="your-console-id", # Required for REMOTE ) as client: # List all sites sites = await client.sites.get_all() site_id = sites[0].id # List all devices devices = await client.devices.get_all(site_id) for device in devices: print(f"Device: {device.name} ({device.mac})") asyncio.run(main()) ``` -------------------------------- ### UniFi Protect API - NVR Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for retrieving and updating UniFi Protect Network Video Recorder (NVR) settings. ```APIDOC ## NVR ### Description Endpoints for retrieving and updating UniFi Protect NVR settings. ### Methods - get - update ``` -------------------------------- ### UniFi Protect API - Chimes Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect chimes, including listing, retrieving, and updating chime settings. ```APIDOC ## Chimes ### Description Endpoints for managing UniFi Protect chimes. ### Methods - list - get - update ``` -------------------------------- ### UniFi Protect API - Sensors Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Protect sensors, including listing, retrieving, and updating sensor information. ```APIDOC ## Sensors ### Description Endpoints for managing UniFi Protect sensors. ### Methods - list - get - update ``` -------------------------------- ### Handle Specific Unifi API Errors Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Catch and handle various UniFi API exceptions, including authentication, connection, rate limiting, and not found errors. Use a general UniFiError for other API-related issues. ```python from unifi_official_api import ( UniFiError, UniFiAuthenticationError, UniFiConnectionError, UniFiNotFoundError, UniFiRateLimitError, UniFiTimeoutError, ) try: devices = await client.devices.get_all(host_id) except UniFiAuthenticationError: print("Invalid API key") except UniFiConnectionError: print("Failed to connect to API") except UniFiRateLimitError as e: print(f"Rate limited. Retry after {e.retry_after} seconds") except UniFiNotFoundError: print("Resource not found") except UniFiError as e: print(f"API error: {e.message}") ``` -------------------------------- ### UniFi Network API - ACL Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network Access Control Lists (ACLs), including listing, retrieving, creating, updating, and deleting ACLs. ```APIDOC ## ACL ### Description Endpoints for managing UniFi Network Access Control Lists (ACLs). ### Methods - list - get - create - update - delete ``` -------------------------------- ### UniFi Network API - Traffic Source: https://github.com/ruaan-deysel/unifi-official-api/blob/main/README.md Endpoints for managing UniFi Network traffic settings, including lists, DPI categories, applications, and countries. ```APIDOC ## Traffic ### Description Endpoints for managing UniFi Network traffic settings. ### Methods - list_matching_lists - create_list - update_list - delete_list - get_dpi_categories - get_dpi_applications - get_countries ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.