Ubiquiti Unifi Controller API authorization class for python requests library. Takes care of authentification and CSRF handling.
Project description
requests-unifi-auth
Ubiquiti Unifi Controller API authorization class for python requests library. Takes care of authentification and CSRF handling.
Installation
pip install requests-unifi-auth
Examples
Read traffic policy-based routes
>>> import json
>>> import requests
>>> from requests_unifi_auth import UnifiControllerAuth
>>> auth = UnifiControllerAuth('your_username', 'your_password', '192.168.1.1')
>>> resp = requests.get('https://192.168.1.1/proxy/network/v2/api/site/default/trafficroutes', verify=False, auth=auth)
>>> print(json.dumps(resp.json(), indent=4))
[
{
"_id": "68fd349fcs1d3724f0021e3t",
"description": "My Cool Domains Rule",
"domains": [
{
"domain": "example.com",
"port_ranges": [],
"ports": []
}
],
"enabled": true,
"ip_addresses": [],
"ip_ranges": [],
"kill_switch_enabled": true,
"matching_target": "DOMAIN",
"network_id": "78fd3e21c31v5424f0021d25",
"next_hop": "",
"regions": [],
"target_devices": [
{
"type": "ALL_CLIENTS"
}
]
},
{
"_id": "68fd3ff1x31d2224d2023f56",
"description": "Yet Another Cool Domain Rule",
"domains": [
{
"domain": "foo.com",
"port_ranges": [],
"ports": []
},
{
"domain": "bar.com",
"port_ranges": [],
"ports": []
}
],
"enabled": true,
"ip_addresses": [],
"ip_ranges": [],
"kill_switch_enabled": false,
"matching_target": "DOMAIN",
"network_id": "78fd3e21c31v5424f0021d25",
"next_hop": "",
"regions": [],
"target_devices": [
{
"type": "ALL_CLIENTS"
}
]
}
]
Update traffic policy-based route
>>> import json
>>> import requests
>>> from requests_unifi_auth import UnifiControllerAuth
>>> s = requests.Session()
>>> s.auth = UnifiControllerAuth('your_username', 'your_password', '192.168.1.1')
>>> resp = s.get('https://192.168.1.1/proxy/network/v2/api/site/default/trafficroutes', verify=False)
>>> rules = resp.json()
>>> updated_rule = rules[0]
>>> updated_rule['domains'].append({"domain": "test.com", "port_ranges": [], "ports": []})
>>> resp = s.put('https://192.168.1.1/proxy/network/v2/api/site/default/trafficroutes/68fd349fcs1d3724f0021e3t', json=updated_rule, verify=False)
>>> print(json.dumps(resp.json(), indent=4))
{
"_id": "68fd349fcs1d3724f0021e3t",
"description": "My Cool Domains Rule",
"domains": [
{
"domain": "example.com",
"port_ranges": [],
"ports": []
},
{
"domain": "test.com",
"port_ranges": [],
"ports": []
}
],
"enabled": true,
"ip_addresses": [],
"ip_ranges": [],
"kill_switch_enabled": true,
"matching_target": "DOMAIN",
"network_id": "78fd3e21c31v5424f0021d25",
"next_hop": "",
"regions": [],
"target_devices": [
{
"type": "ALL_CLIENTS"
}
]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file requests_unifi_auth-0.1.4.tar.gz.
File metadata
- Download URL: requests_unifi_auth-0.1.4.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
49d86fe42bc7266d09e59f9b27801cad479a5a9e5c324ea899002e2d3a2c9580
|
|
| MD5 |
80e7e038953ca6856661cad69ee4075e
|
|
| BLAKE2b-256 |
1272c6b617c9e9a9a06da08f45c6e8401eaf79844efc7199e7097929cbe16a17
|
Provenance
The following attestation bundles were made for requests_unifi_auth-0.1.4.tar.gz:
Publisher:
publish.yml on akinfold/requests-unifi-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
requests_unifi_auth-0.1.4.tar.gz -
Subject digest:
49d86fe42bc7266d09e59f9b27801cad479a5a9e5c324ea899002e2d3a2c9580 - Sigstore transparency entry: 774218908
- Sigstore integration time:
-
Permalink:
akinfold/requests-unifi-auth@8ba5974c283fcbe81dfe4abd81b7692019fe9968 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/akinfold
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ba5974c283fcbe81dfe4abd81b7692019fe9968 -
Trigger Event:
release
-
Statement type:
File details
Details for the file requests_unifi_auth-0.1.4-py3-none-any.whl.
File metadata
- Download URL: requests_unifi_auth-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94c54e83415ebfb85fcb4c31b2efe3b378994ef743e4a16676e316570a2ba26
|
|
| MD5 |
6b50ace43ade1fd534a7b688372db611
|
|
| BLAKE2b-256 |
973a8a744cc47f07b7d9b875895f4500e700ea18692443201d9fa36c59ab8949
|
Provenance
The following attestation bundles were made for requests_unifi_auth-0.1.4-py3-none-any.whl:
Publisher:
publish.yml on akinfold/requests-unifi-auth
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
requests_unifi_auth-0.1.4-py3-none-any.whl -
Subject digest:
d94c54e83415ebfb85fcb4c31b2efe3b378994ef743e4a16676e316570a2ba26 - Sigstore transparency entry: 774218909
- Sigstore integration time:
-
Permalink:
akinfold/requests-unifi-auth@8ba5974c283fcbe81dfe4abd81b7692019fe9968 -
Branch / Tag:
refs/tags/v0.1.4 - Owner: https://github.com/akinfold
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ba5974c283fcbe81dfe4abd81b7692019fe9968 -
Trigger Event:
release
-
Statement type: