UnifiUtils (Python)
A Python utility library for interacting with Ubiquiti UniFi Controller REST APIs. This library provides a clean abstraction layer for HTTP communication with UniFi network controllers, handling authentication, endpoint management, and JSON request/response processing.
Ported from the Java UnifiUtils library.
Features
- Enumeration-based API interface - Type-safe API endpoint definitions with 129 UniFi endpoints
- Dynamic URL templating - Automatic placeholder substitution for site, MAC address, and other parameters
- Flexible HTTP methods - Support for GET, POST, PUT, DELETE, and HEAD operations
- Built-in authentication - API key header management for all requests
- Native JSON handling - Returns Python dicts directly
- Comprehensive logging - Python
loggingmodule integration for debugging and traceability
Requirements
- Python 3.10+
requestslibrary
Installation
From Source
git clone https://github.com/RogerJoys/unifi-utils-python.git
cd unifi-utils-python
pip install -e .
Development
pip install -e ".[dev]"
Usage
Basic Initialization
from unifi_utils import UnifiUtils, UnifiAPI
# Initialize with UniFi controller details
unifi = UnifiUtils(
endpoint="https://your-controller.url", # Controller endpoint
api_key="your-api-key", # API key
site="default", # Site name
)
Making API Calls
# Simple GET request
status = unifi.make_api_call(UnifiAPI.StatusGet)
# Get all active clients
clients = unifi.make_api_call(UnifiAPI.ActiveClientsGet)
# Get site health
health = unifi.make_api_call(UnifiAPI.HealthGet)
# POST request with JSON body
body = {"username": "admin", "password": "password"}
response = unifi.make_api_call(UnifiAPI.LoginPost, json_body=body)
# Device-specific command with MAC address
device_response = unifi.make_api_call(
UnifiAPI.DeviceLocateEnablePost,
mac_address="aa:bb:cc:dd:ee:ff",
)
# Full control with custom endpoint substitutions
from unifi_utils import UnifiEndpointSymbolics
substitutions = {UnifiEndpointSymbolics.ID: "device-id-here"}
update_body = {"name": "New Device Name"}
update_response = unifi.make_api_call(
UnifiAPI.DeviceUpdatePut,
json_body=update_body,
added_substitutions=substitutions,
)
Available API Endpoints
The library provides 129 API endpoints covering all UniFi Controller functionality:
| Category | Count |
|---|---|
| Controller APIs (auth, system) | 9 |
| Health & Status | 5 |
| Events & Alarms | 4 |
| Client Management | 11 |
| VPN | 1 |
| Device Management | 16 |
| Network Configuration | 9 |
| Firewall Configuration | 8 |
| Port Forwarding | 4 |
| WLAN Configuration | 5 |
| Site Settings | 2 |
| DPI & Analytics | 6 |
| RADIUS | 8 |
| Dynamic DNS | 3 |
| Switch Port Profiles | 4 |
| Rogue APs | 2 |
| Hotspot / Vouchers / Guests | 5 |
| Hotspot Operators | 4 |
| User Groups | 4 |
| Media Streaming | 2 |
| Backup Commands | 3 |
| Site Management | 6 |
| Event Management | 1 |
| SDN / Cloud Access | 1 |
| Miscellaneous (Tags, Counters, Dashboard, WLAN Groups) | 7 |
Project Structure
unifi-utils-python/
├── src/
│ └── unifi_utils/
│ ├── __init__.py # Public exports
│ ├── enums.py # HTTPCall, UnifiApiClass, UnifiCommandManager, UnifiEndpointSymbolics
│ ├── api.py # UnifiAPI enum (129 endpoint definitions)
│ └── client.py # UnifiUtils class (main HTTP client)
├── tests/
│ ├── test_enums.py
│ ├── test_api.py
│ └── test_client.py
├── pyproject.toml
├── LICENSE
└── README.md
Core Classes
UnifiUtils
The main class for interacting with the UniFi Controller API. Provides a single make_api_call() method with optional parameters:
api_call- TheUnifiAPIenum member to calljson_body- Optional dict for POST/PUT request bodiesmac_address- Optional MAC address for device-specific commandsadded_substitutions- Optional dict ofUnifiEndpointSymbolicsto string values for URL placeholders
UnifiAPI
Enumeration defining all supported API endpoints with their paths, HTTP methods, requirements, and manager types.
UnifiApiClass
Defines API classification types with their URL prefixes:
Controller- Root level endpointsSite- Site-specific endpoints (/api/s/{{site}})CallableCommand- Device command endpoints (/api/s/{{site}}/cmd/{{manager}})
UnifiCommandManager
Defines manager types for command routing: evtmgt, sitemgr, stamgr, devmgr, backup, system, stat.
Running Tests
pip install -e ".[dev]"
pytest
API Documentation
For detailed UniFi Controller API documentation, see:
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or pull request.
Metadata
Release files for unifi-utils-python 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| unifi_utils_python-1.0.0.tar.gz | 16.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| unifi_utils_python-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.7 kB
Release files / unifi_utils_python-1.0.0.tar.gz
| Download URL | unifi_utils_python-1.0.0.tar.gz |
|---|---|
| Size | 16.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e5f5711a4492ffed883a8f66e83b798629b4e1ec56dbede1609c7c019cd47d2a
|
|
BLAKE2b-256 checksum How to use checksums |
775cc75e7cfda9b41652700272ba6b93f414382f7d6a2ce0177f490b1d85a065
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.10
|
Release files / unifi_utils_python-1.0.0-py3-none-any.whl
| Download URL | unifi_utils_python-1.0.0-py3-none-any.whl |
|---|---|
| Size | 14.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b740aef6f8a902e6dadfb648e52685a86920aafe12204ed092fdd506d7f932c
|
|
BLAKE2b-256 checksum How to use checksums |
d1d459ff66dac1011a47f4137878ba1c046b8ed626da851f77517894e729905b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.10
|
Security for unifi-utils-python 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.