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.

Development

Install dependencies:

pip install -e ".[dev]"
pre-commit install

This will check and format using ruff the code before committing.

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.3.0.tar.gz (10.5 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.3.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aio_openwrt-0.3.0.tar.gz
  • Upload date:
  • Size: 10.5 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.3.0.tar.gz
Algorithm Hash digest
SHA256 b668c54407ae05879ac053f994983ee93a5d44f4caceb67419b2cc3ea01cbba8
MD5 1987b3ebffd6b81884043e2e67e04dbd
BLAKE2b-256 76c83dd5d59bbf6b696c739be020e33a012f2838d30eb8f14401fc03501d6ac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_openwrt-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: aio_openwrt-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 208fc1a210e1d5ceaf9196648dbe315b326f8eaf09a8530948bede17a461adfc
MD5 1933241d12137a7351e1e2ceea2f9639
BLAKE2b-256 4a0e572828de5a0ab68047682511a2bf1ef4a247ca243c930de85cedd3edca28

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_openwrt-0.3.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