Skip to main content

Async Python library for interfacing with OpenWRT via ubus

Project description

OpenWRT ubus API

A Python library for asynchronous access to the ubus interface on OpenWRT devices.

Requirements

  • Python 3.10+
  • aiohttp

Quick Start

from aio_openwrt import Ubus

async with Ubus("192.168.1.1", "username", "password") as client:
    await client.login()
    dev = await client.network.device.status(name="lan1")
    print(dev)

Usage

Connection livetime

Use async with to automatically manage the session:

async with Ubus(host, user, password) as client:
    await client.login()
    dev = await client.network.device.status(name="lan1")

Without a with block, a session is created automatically on the first request. In that case, call close() manually when done:

client = Ubus(host, user, password)
try:
    await client.login()
    dev = await client.network.device.status(name="lan1")
finally:
    await client.close()

Making Calls

There are two ways to interact with the device:

Typed wrappers — available for common paths and methods:

await ubus.session.login(username="...", password="...")
await ubus.network.device.status(name="lan1")
await ubus.system.board()

Direct call() — for any path/method not covered by a typed wrapper:

await ubus.call("session", "login", {"username": "...", "password": "..."})
await ubus.call("network.device", "status", {"name": "lan1"})
await ubus.call("system", "board")

Both are equivalent. The typed wrappers are a convenience layer over call().

Subscript Access For dynamically named entries such as network interfaces, use subscript notation:

await ubus.network.interface["wan"].status()

Listing objects

To list the objects directly use list():

await ubus.list("hostapd.*")

Typed wrappers with subscript access can be iterated over using list_children():

await ubus.hostapd.list_children()

Permissions

Depending on the device configuration, most features require authentication first. The authenticated user must be configured in /etc/config/rpcd with a corresponding ACL file in /usr/share/rpcd/acl.d/ granting the necessary ubus permissions. See the OpenWRT wiki for details.

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

aio_openwrt-0.2.0.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

aio_openwrt-0.2.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file aio_openwrt-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for aio_openwrt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bb76a147af0a1d44666b45a6125ce7ddf15af7bb5b1e8a8f021faecd1040e1bd
MD5 80c7ef4e1c97910e1399916ddc6cb421
BLAKE2b-256 c27a765b42fa9fea674be059e267eb6d4422a592f813ee778c6c41794aa47e0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_openwrt-0.2.0.tar.gz:

Publisher: release.yml on xZise/aio-openwrt

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

File details

Details for the file aio_openwrt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aio_openwrt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aio_openwrt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a6532d628440e8180471ccabe43fe085d9aa22341aed4a4b121f60eda43051a
MD5 48e02a1410c066cd010a1534eadc8bcb
BLAKE2b-256 f59b863c8dc8d0e4bd65e1547bd337374e4483e2bb6172795b4848a242e10a35

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_openwrt-0.2.0-py3-none-any.whl:

Publisher: release.yml on xZise/aio-openwrt

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