Skip to main content

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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

requests_unifi_auth-0.1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

requests_unifi_auth-0.1.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file requests_unifi_auth-0.1.3.tar.gz.

File metadata

  • Download URL: requests_unifi_auth-0.1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for requests_unifi_auth-0.1.3.tar.gz
Algorithm Hash digest
SHA256 2bdd1ba1531e6856e9552c37f249a6902807df9c423aa2ef5500f63f5a86d7aa
MD5 7718c81a737a028e379682a70b6eafb0
BLAKE2b-256 4c921907b3d88cd916ce02e96ea8fbc52157799deaaf7816f3a00a0f10456743

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_unifi_auth-0.1.3.tar.gz:

Publisher: publish.yml on akinfold/requests-unifi-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file requests_unifi_auth-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_unifi_auth-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b2e4e8d6ffe932a26bedb33d6282f6c0eba13626fe8955dc1d7a90f5b3896bfe
MD5 c84600ac8b072301cc3d38c58a2b54e0
BLAKE2b-256 8bf895d32d71441c8c244f49d1ac3e2a1f145c5037b7e04b5f27808ebe6f2508

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_unifi_auth-0.1.3-py3-none-any.whl:

Publisher: publish.yml on akinfold/requests-unifi-auth

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page