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

cov

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


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.4.tar.gz (6.5 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.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

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

Hashes for requests_unifi_auth-0.1.4.tar.gz
Algorithm Hash digest
SHA256 49d86fe42bc7266d09e59f9b27801cad479a5a9e5c324ea899002e2d3a2c9580
MD5 80e7e038953ca6856661cad69ee4075e
BLAKE2b-256 1272c6b617c9e9a9a06da08f45c6e8401eaf79844efc7199e7097929cbe16a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for requests_unifi_auth-0.1.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for requests_unifi_auth-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d94c54e83415ebfb85fcb4c31b2efe3b378994ef743e4a16676e316570a2ba26
MD5 6b50ace43ade1fd534a7b688372db611
BLAKE2b-256 973a8a744cc47f07b7d9b875895f4500e700ea18692443201d9fa36c59ab8949

See more details on using hashes here.

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

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