Metadata-Version: 2.4
Name: aio-openwrt
Version: 0.1.0
Summary: Async Python library for interfacing with OpenWRT via ubus
Project-URL: Homepage, https://github.com/xZise/aio-openwrt
Project-URL: Repository, https://github.com/xZise/aio-openwrt
Project-URL: Issues, https://github.com/xZise/aio-openwrt/issues
Author-email: Fabian Neundorf <CommodoreFabianus@gmx.de>
License: MIT License
        
        Copyright (c) 2026 Fabian Neundorf
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: aiohttp,async,homeassistant,openwrt,ubus
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Home Automation
Classifier: Topic :: System :: Networking
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.9
Provides-Extra: dev
Requires-Dist: aioresponses; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Description-Content-Type: text/markdown

# OpenWRT ubus API

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

## Requirements

* Python 3.10+
* `aiohttp`

## Quick Start
```python
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:

```python
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:


```python
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:
```python
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:
```python
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:
```python
await ubus.network.interface["wan"].status()
```

### Listing objects
To list the objects directly use `list()`:
```python
await ubus.list("hostapd.*")
```

## 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](https://openwrt.org/docs/techref/ubus) for details.