Python library for interacting with UniFi’s Site Manager Integration API. Tested on a selfhosted local instance only. Downlod from here: https://pypi.org/project/unifi-sm-api/
Note
This library was mainly creted to be used with NetAlertX, as such, full API coverage is not planned. PRs are however more than welcome.
Navigate to Site Manager ⚙️ Settings -> Control Plane -> Integrations.
api_key: You can generate your API key under the Your API Keys section.base_url: You can find your base url in the API Request Format section.version: You can find your version as part of the url in the API Request Format section.
from unifi_sm_api.api import SiteManagerAPI
api = SiteManagerAPI(
api_key="fakeApiKey1234567890",
base_url="https://192.168.100.1/proxy/network/integration/",
version="v1",
verify_ssl=False
)
sites = api.get_sites()
for site in sites:
site_id = site["id"]
unifi_devices = api.get_unifi_devices(site_id=site_id)
clients = api.get_clients(site_id=site_id)/sites— list available sites/sites/{site_id}/devices— list UniFi devices for a site/sites/{site_id}/clients— list connected clients
- Python 3.8+
requestspytest(for running tests)- Local
.envfile with API credentials
Create a .env file in the project root with the following:
API_KEY=fakeApiKey1234567890
BASE_URL=https://192.168.100.1/proxy/network/integration/
VERSION=v1
VERIFY_SSL=FalseMake sure PYTHONPATH includes the project root, then run:
python3 -m venv venv && source venv/bin/activate
pip install pytest python-dotenv
cd unifi-sm-api/
pip install -e .
PYTHONPATH=.. pytest -s tests/test_api.py