Skip to main content

Execute API calls to Omada Controller from python code

Project description

omada-client

PyPI Version

Python client for Tp-Link Omada Controller (Omada Software Controller). Execute API calls to Omada Controller from python code.

Installation

pip install omada-client

Examples

Create class

from omada_client import OmadaClient
omada = OmadaClient( "OMADA_DOMAIN", "OMADA_USER", "OMADA_PASSWORD" )

where:

  • OMADA_DOMAIN: URL of Omada WebUi page
  • OMADA_USER: Username of Omada WebUi
  • OMADA_PASSWORD: Password of Omada WebUi

or using environment variables "OMADA_DOMAIN" and "OMADA_USER" and "OMADA_PASSWORD":

from dotenv import load_dotenv
import os
from omada_client import OmadaClient
load_dotenv()

def main():
    omadaClient = OmadaClient( 
        os.getenv("OMADA_DOMAIN"), 
        os.getenv("OMADA_USER"), 
        os.getenv("OMADA_PASSWORD")
    )

    print( omadaClient.get_devices() )
if __name__ == "__main__":
    main() 

Methods

# Get a list of WAN ports
omadaClient.get_all_wan_ports()
# Get WAN port by its name
omadaClient.get_wan_ports_by_name("WAN/LAN1")
# Get WAN port by its name
omadaClient.get_wan_ports_by_desc("domru")
# Get a list of Wifi Networks
omadaClient.get_all_wlan()
# Get a Wlan by SSID
omadaClient.get_wlan_by_ssid("HomeNetwork")
# Create a static route
omadaClient.create_static_route(
    route_name="test",
    destinations=["8.8.8.8/24", "1.1.1.1/24"],
    interface_id=omadaClient.get_wan_ports_by_desc("openwrt").port_uuid,
    next_hop_ip="192.168.1.1",
    enable=False
)
# Get list of devices
omadaClient.get_devices()
# Get a client by their MAC address
omadaClient.get_client_by_mac("ff:ff:ff:ff:ff:ff")
# Get all clients
omadaClient.get_clients()
# Get a client by its IP address
omadaClient.get_client_by_ip("10.0.0.100")
# Assign a fixed IP address to the client based on its MAC address
omadaClient.set_client_fixed_address_by_mac("ff:ff:ff:ff:ff:ff", "10.0.0.100")
# Assign a fixed IP address to the client based on its IP address
omadaClient.set_client_fixed_address_by_ip("10.0.0.100")
# Assign a dynamic IP address to the client
omadaClient.set_client_dymanic_address_by_mac("ff:ff:ff:ff:ff:ff")

Advanced methods

Create a static route from a large amount of data

from dotenv import load_dotenv
import os
from omada_client import OmadaClient
load_dotenv()

def main():
    omadaClient = OmadaClient( 
        os.getenv("OMADA_DOMAIN"), 
        os.getenv("OMADA_USER"), 
        os.getenv("OMADA_PASSWORD")
    )

    data = [
        {
            "name" : "group_1",
            "ips" : "99.99.99.99/24, 88.88.88.88/24"
        },
        {
            "name" : "group_2",
            "ips" : "99.99.99.99/24, 88.88.88.88/24"
        }
    ]
    wan = omadaClient.get_wan_ports_by_desc("openwrt")
    omadaClient.create_static_route_to_inteface_with_big_data(
        data_static_routes=data,
        interface_id=wan.port_uuid,
        next_hop_ip=wan.wan_port_ipv4_setting.get("ipv4Static").get("gateway"),
        enable=False
    )
if __name__ == "__main__":
    main() 

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

omada_client-1.2.2.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file omada_client-1.2.2.tar.gz.

File metadata

  • Download URL: omada_client-1.2.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for omada_client-1.2.2.tar.gz
Algorithm Hash digest
SHA256 f4d8fcff05c2ec6af20b1025a48e447fa32eb9f90490a813a71984d9a08add89
MD5 49d4af511124e6c78435b637a86d4117
BLAKE2b-256 1c2a85b95a2926140747448ef875bb87d8776e01d9d8e5c6d99e07a0a031c1ae

See more details on using hashes here.

Supported by

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