unifi-controller-api 0.1.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unifi_controller_api-0.2.1/PKG-INFO +142 -0
- unifi_controller_api-0.2.1/README.md +116 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/pyproject.toml +9 -13
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/__init__.py +10 -1
- unifi_controller_api-0.2.1/unifi_controller_api/api_client.py +850 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/__init__.py +26 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/alarm.py +38 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/client.py +48 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/device.py +200 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/event.py +37 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/networkconf.py +51 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/rogueap.py +45 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/site.py +147 -0
- unifi_controller_api-0.2.1/unifi_controller_api/models/wlanconf.py +146 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/utils.py +0 -1
- unifi_controller_api-0.2.1/unifi_controller_api.egg-info/PKG-INFO +142 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api.egg-info/SOURCES.txt +10 -1
- unifi_controller_api-0.1.0/PKG-INFO +0 -27
- unifi_controller_api-0.1.0/README.md +0 -1
- unifi_controller_api-0.1.0/unifi_controller_api/api_client.py +0 -481
- unifi_controller_api-0.1.0/unifi_controller_api.egg-info/PKG-INFO +0 -27
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/LICENSE +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/setup.cfg +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/device-models.json +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/exceptions.py +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/export.py +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api/logging.py +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api.egg-info/dependency_links.txt +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api.egg-info/requires.txt +0 -0
- {unifi_controller_api-0.1.0 → unifi_controller_api-0.2.1}/unifi_controller_api.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: unifi-controller-api
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: A (read only) Python library for interacting with the Unifi Controller API
|
|
5
|
+
Author-email: Tyler Woods <tyler@tylermade.net>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/tnware/unifi-controller-api
|
|
8
|
+
Project-URL: Bug Tracker, https://github.com/tnware/unifi-controller-api/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Topic :: Utilities
|
|
15
|
+
Requires-Python: >=3.8
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: requests
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pytest-cov>=2.12; extra == "dev"
|
|
22
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
23
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff>=0.1.1; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# unifi-controller-api
|
|
28
|
+
|
|
29
|
+
A Python client library for interacting with Ubiquiti UniFi Network Controllers.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Core Features
|
|
33
|
+
|
|
34
|
+
* **Read-Only Access:** Designed for insights and reporting, so no changes can or will be made.
|
|
35
|
+
* **Structured Data Models:** Parses API responses into typed Python objects (e.g., `UnifiDevice`, `UnifiSite`, `UnifiClient`, `LLDPEntry`, `UnifiWlanConf`).
|
|
36
|
+
* **Automatic Model Mapping:** Translates model codes (e.g., `U7PG2`) to friendly names ("UniFi® AC Pro AP") via the `model_name` attribute.
|
|
37
|
+
* **Convenience Methods:** Includes helpers for data export (`export_csv`, `export_json`).
|
|
38
|
+
* **Minimal Dependencies:** Requires only `requests`.
|
|
39
|
+
* **Python >= 3.8**
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install unifi-controller-api
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
---
|
|
50
|
+
|
|
51
|
+
## Quick Start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from unifi_controller_api import UnifiController
|
|
55
|
+
|
|
56
|
+
# 1. Initialize & Authenticate
|
|
57
|
+
controller = UnifiController(
|
|
58
|
+
controller_url="https://<CONTROLLER_IP_OR_HOSTNAME>", # Use :8443 for dedicated controller
|
|
59
|
+
username="<LOCAL_ADMIN_USER>",
|
|
60
|
+
password="<PASSWORD>",
|
|
61
|
+
is_udm_pro=True, # Set True for UniFi OS devices, False for legacy
|
|
62
|
+
verify_ssl=False # Or path to CA bundle
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
# 2. Fetch Data (Example: Devices for the 'default' site)
|
|
66
|
+
site_name = "default" # Use the internal site name
|
|
67
|
+
try:
|
|
68
|
+
devices = controller.get_unifi_site_device(site_name=site_name, detailed=True)
|
|
69
|
+
|
|
70
|
+
# 3. Use the Typed Data
|
|
71
|
+
for device in devices:
|
|
72
|
+
print(f"- {device.name} ({device.model_name}): {device.ip} / {device.mac}")
|
|
73
|
+
if device.lldp_info:
|
|
74
|
+
print(f" LLDP: {len(device.lldp_info)} neighbors")
|
|
75
|
+
|
|
76
|
+
except Exception as e:
|
|
77
|
+
print(f"Error fetching devices for site '{site_name}': {e}")
|
|
78
|
+
|
|
79
|
+
# Other available methods:
|
|
80
|
+
# sites = controller.get_unifi_site()
|
|
81
|
+
# clients = controller.get_clients(site_name)
|
|
82
|
+
# wlans = controller.get_wlan_conf(site_name)
|
|
83
|
+
# alarms = controller.get_alarms(site_name)
|
|
84
|
+
# events = controller.get_events(site_name)
|
|
85
|
+
# rogue_aps = controller.get_rogue_aps(site_name)
|
|
86
|
+
# networks = controller.get_network_conf(site_name)
|
|
87
|
+
# report = controller.devices_report(site_names=['site1', 'site2'])
|
|
88
|
+
|
|
89
|
+
# Exporting data:
|
|
90
|
+
# from unifi_controller_api.export import export_csv, export_json
|
|
91
|
+
# if devices:
|
|
92
|
+
# export_csv(devices, "devices.csv")
|
|
93
|
+
# export_json(devices, "devices.json")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## Connectivity Notes
|
|
99
|
+
|
|
100
|
+
* Requires direct network access to the controller.
|
|
101
|
+
* Uses **HTTPS port 443** for UniFi OS devices (UDM, Cloud Key 2.x+, etc.).
|
|
102
|
+
* Uses **HTTPS port 8443** for legacy controllers (Software, Cloud Key Gen1/Gen2 pre-2.x).
|
|
103
|
+
* Requires a **local controller account**, not a UniFi Cloud/SSO account.
|
|
104
|
+
* Set `is_udm_pro=True` for UniFi OS, `False` for dedicated controller.
|
|
105
|
+
* Use `verify_ssl=False` or provide a CA bundle path for self-signed certificates.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Data Models
|
|
110
|
+
|
|
111
|
+
The library automatically maps JSON API responses to Python data classes located in `unifi_controller_api.models`. Key models include:
|
|
112
|
+
|
|
113
|
+
* `UnifiSite`: Represents a controller site.
|
|
114
|
+
* `UnifiDevice`: Represents a network device (AP, Switch, Gateway).
|
|
115
|
+
* `LLDPEntry`: Holds LLDP neighbor details (nested within `UnifiDevice`).
|
|
116
|
+
* `UnifiClient`: Represents a connected client (wired or wireless).
|
|
117
|
+
* `UnifiWlanConf`: Represents a Wireless LAN configuration.
|
|
118
|
+
* `UnifiNetworkConf`: Represents a Network configuration.
|
|
119
|
+
* `UnifiAlarm`: Represents a controller alarm.
|
|
120
|
+
* `UnifiEvent`: Represents a controller event.
|
|
121
|
+
* `UnifiRogueAp`: Represents a detected rogue access point.
|
|
122
|
+
|
|
123
|
+
Use standard object attribute access (e.g., `device.ip`, `site.desc`) to work with the data.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## Logging
|
|
128
|
+
|
|
129
|
+
Uses standard Python `logging`. Configure the `unifi_controller_api` logger:
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
import logging
|
|
133
|
+
logging.getLogger("unifi_controller_api").setLevel(logging.DEBUG)
|
|
134
|
+
# Ensure you have a handler configured (e.g., via logging.basicConfig)
|
|
135
|
+
logging.basicConfig(level=logging.INFO) # Example: Show INFO level and above
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Disclaimer
|
|
141
|
+
|
|
142
|
+
This is an unofficial library using APIs that may change without notice. Not affiliated with Ubiquiti Inc. Use at your own risk.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# unifi-controller-api
|
|
2
|
+
|
|
3
|
+
A Python client library for interacting with Ubiquiti UniFi Network Controllers.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## Core Features
|
|
7
|
+
|
|
8
|
+
* **Read-Only Access:** Designed for insights and reporting, so no changes can or will be made.
|
|
9
|
+
* **Structured Data Models:** Parses API responses into typed Python objects (e.g., `UnifiDevice`, `UnifiSite`, `UnifiClient`, `LLDPEntry`, `UnifiWlanConf`).
|
|
10
|
+
* **Automatic Model Mapping:** Translates model codes (e.g., `U7PG2`) to friendly names ("UniFi® AC Pro AP") via the `model_name` attribute.
|
|
11
|
+
* **Convenience Methods:** Includes helpers for data export (`export_csv`, `export_json`).
|
|
12
|
+
* **Minimal Dependencies:** Requires only `requests`.
|
|
13
|
+
* **Python >= 3.8**
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install unifi-controller-api
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from unifi_controller_api import UnifiController
|
|
29
|
+
|
|
30
|
+
# 1. Initialize & Authenticate
|
|
31
|
+
controller = UnifiController(
|
|
32
|
+
controller_url="https://<CONTROLLER_IP_OR_HOSTNAME>", # Use :8443 for dedicated controller
|
|
33
|
+
username="<LOCAL_ADMIN_USER>",
|
|
34
|
+
password="<PASSWORD>",
|
|
35
|
+
is_udm_pro=True, # Set True for UniFi OS devices, False for legacy
|
|
36
|
+
verify_ssl=False # Or path to CA bundle
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# 2. Fetch Data (Example: Devices for the 'default' site)
|
|
40
|
+
site_name = "default" # Use the internal site name
|
|
41
|
+
try:
|
|
42
|
+
devices = controller.get_unifi_site_device(site_name=site_name, detailed=True)
|
|
43
|
+
|
|
44
|
+
# 3. Use the Typed Data
|
|
45
|
+
for device in devices:
|
|
46
|
+
print(f"- {device.name} ({device.model_name}): {device.ip} / {device.mac}")
|
|
47
|
+
if device.lldp_info:
|
|
48
|
+
print(f" LLDP: {len(device.lldp_info)} neighbors")
|
|
49
|
+
|
|
50
|
+
except Exception as e:
|
|
51
|
+
print(f"Error fetching devices for site '{site_name}': {e}")
|
|
52
|
+
|
|
53
|
+
# Other available methods:
|
|
54
|
+
# sites = controller.get_unifi_site()
|
|
55
|
+
# clients = controller.get_clients(site_name)
|
|
56
|
+
# wlans = controller.get_wlan_conf(site_name)
|
|
57
|
+
# alarms = controller.get_alarms(site_name)
|
|
58
|
+
# events = controller.get_events(site_name)
|
|
59
|
+
# rogue_aps = controller.get_rogue_aps(site_name)
|
|
60
|
+
# networks = controller.get_network_conf(site_name)
|
|
61
|
+
# report = controller.devices_report(site_names=['site1', 'site2'])
|
|
62
|
+
|
|
63
|
+
# Exporting data:
|
|
64
|
+
# from unifi_controller_api.export import export_csv, export_json
|
|
65
|
+
# if devices:
|
|
66
|
+
# export_csv(devices, "devices.csv")
|
|
67
|
+
# export_json(devices, "devices.json")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Connectivity Notes
|
|
73
|
+
|
|
74
|
+
* Requires direct network access to the controller.
|
|
75
|
+
* Uses **HTTPS port 443** for UniFi OS devices (UDM, Cloud Key 2.x+, etc.).
|
|
76
|
+
* Uses **HTTPS port 8443** for legacy controllers (Software, Cloud Key Gen1/Gen2 pre-2.x).
|
|
77
|
+
* Requires a **local controller account**, not a UniFi Cloud/SSO account.
|
|
78
|
+
* Set `is_udm_pro=True` for UniFi OS, `False` for dedicated controller.
|
|
79
|
+
* Use `verify_ssl=False` or provide a CA bundle path for self-signed certificates.
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Data Models
|
|
84
|
+
|
|
85
|
+
The library automatically maps JSON API responses to Python data classes located in `unifi_controller_api.models`. Key models include:
|
|
86
|
+
|
|
87
|
+
* `UnifiSite`: Represents a controller site.
|
|
88
|
+
* `UnifiDevice`: Represents a network device (AP, Switch, Gateway).
|
|
89
|
+
* `LLDPEntry`: Holds LLDP neighbor details (nested within `UnifiDevice`).
|
|
90
|
+
* `UnifiClient`: Represents a connected client (wired or wireless).
|
|
91
|
+
* `UnifiWlanConf`: Represents a Wireless LAN configuration.
|
|
92
|
+
* `UnifiNetworkConf`: Represents a Network configuration.
|
|
93
|
+
* `UnifiAlarm`: Represents a controller alarm.
|
|
94
|
+
* `UnifiEvent`: Represents a controller event.
|
|
95
|
+
* `UnifiRogueAp`: Represents a detected rogue access point.
|
|
96
|
+
|
|
97
|
+
Use standard object attribute access (e.g., `device.ip`, `site.desc`) to work with the data.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Logging
|
|
102
|
+
|
|
103
|
+
Uses standard Python `logging`. Configure the `unifi_controller_api` logger:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
import logging
|
|
107
|
+
logging.getLogger("unifi_controller_api").setLevel(logging.DEBUG)
|
|
108
|
+
# Ensure you have a handler configured (e.g., via logging.basicConfig)
|
|
109
|
+
logging.basicConfig(level=logging.INFO) # Example: Show INFO level and above
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Disclaimer
|
|
115
|
+
|
|
116
|
+
This is an unofficial library using APIs that may change without notice. Not affiliated with Ubiquiti Inc. Use at your own risk.
|
|
@@ -4,26 +4,22 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "unifi-controller-api"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "A (read only) Python library for interacting with the Unifi Controller API"
|
|
9
9
|
readme = "README.md"
|
|
10
|
-
authors = [
|
|
11
|
-
|
|
12
|
-
]
|
|
13
|
-
license = {text = "MIT"}
|
|
10
|
+
authors = [{ name = "Tyler Woods", email = "tyler@tylermade.net" }]
|
|
11
|
+
license = { text = "MIT" }
|
|
14
12
|
classifiers = [
|
|
15
13
|
"Programming Language :: Python :: 3",
|
|
16
14
|
"License :: OSI Approved :: MIT License",
|
|
17
15
|
"Operating System :: OS Independent",
|
|
18
16
|
"Topic :: System :: Networking :: Monitoring",
|
|
19
17
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
|
-
"Topic :: Utilities"
|
|
18
|
+
"Topic :: Utilities",
|
|
21
19
|
]
|
|
22
20
|
requires-python = ">=3.8"
|
|
23
21
|
|
|
24
|
-
dependencies = [
|
|
25
|
-
"requests",
|
|
26
|
-
]
|
|
22
|
+
dependencies = ["requests"]
|
|
27
23
|
|
|
28
24
|
[project.urls]
|
|
29
25
|
"Homepage" = "https://github.com/tnware/unifi-controller-api"
|
|
@@ -32,8 +28,8 @@ dependencies = [
|
|
|
32
28
|
[tool.setuptools]
|
|
33
29
|
packages = ["unifi_controller_api"]
|
|
34
30
|
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
[tool.setuptools.package-data]
|
|
32
|
+
"unifi_controller_api" = ["models/*", "device-models.json"]
|
|
37
33
|
|
|
38
34
|
[project.optional-dependencies]
|
|
39
35
|
dev = [
|
|
@@ -41,5 +37,5 @@ dev = [
|
|
|
41
37
|
"pytest-cov>=2.12",
|
|
42
38
|
"pytest-mock>=3.10.0",
|
|
43
39
|
"python-dotenv>=1.0.0",
|
|
44
|
-
"ruff>=0.1.1"
|
|
45
|
-
]
|
|
40
|
+
"ruff>=0.1.1",
|
|
41
|
+
]
|
|
@@ -6,7 +6,10 @@ allowing read-only access to sites, devices, and other network information.
|
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
8
|
from .api_client import UnifiController
|
|
9
|
-
from .models import
|
|
9
|
+
from .models import (
|
|
10
|
+
UnifiSite, UnifiDevice, LLDPEntry, UnifiClient,
|
|
11
|
+
UnifiEvent, UnifiAlarm, UnifiWlanConf, UnifiRogueAp, UnifiNetworkConf
|
|
12
|
+
)
|
|
10
13
|
from .export import export_csv, export_json, to_dict_list
|
|
11
14
|
from .exceptions import (
|
|
12
15
|
UnifiControllerError,
|
|
@@ -21,6 +24,12 @@ __all__ = [
|
|
|
21
24
|
"UnifiSite",
|
|
22
25
|
"UnifiDevice",
|
|
23
26
|
"LLDPEntry",
|
|
27
|
+
"UnifiClient",
|
|
28
|
+
"UnifiEvent",
|
|
29
|
+
"UnifiAlarm",
|
|
30
|
+
"UnifiWlanConf",
|
|
31
|
+
"UnifiRogueAp",
|
|
32
|
+
"UnifiNetworkConf",
|
|
24
33
|
"export_csv",
|
|
25
34
|
"export_json",
|
|
26
35
|
"to_dict_list",
|