A Python library for managing OpenWRT configuration over SSH
Project description
WRTKit
A Python library for managing OpenWRT configuration over SSH using UCI (Unified Configuration Interface).
Features
- Declarative Configuration: Define OpenWRT configurations using Python objects with a simple builder pattern
- Remote Management: Connect to OpenWRT devices over SSH
- Configuration Diff: Compare local configuration with remote device configuration
- Safe Apply: Review changes before applying them to remote devices
- Type Safety: Strongly typed configuration objects for better IDE support
Installation
pip install wrtkit
Quick Start
from wrtkit import UCIConfig, Network, Wireless, DHCP, Firewall
from wrtkit import SSHConnection
# Define your configuration
config = UCIConfig()
# Configure network
lan_bridge = config.network.device("br_lan") \
.name("br-lan") \
.type("bridge") \
.add_port("lan1") \
.add_port("lan2") \
.add_port("lan3")
lan = config.network.interface("lan") \
.device("br-lan") \
.proto("static") \
.ipaddr("192.168.10.1") \
.netmask("255.255.255.0")
wan = config.network.interface("wan") \
.device("eth1") \
.proto("dhcp")
# Configure DHCP
dhcp_lan = config.dhcp.dhcp("lan") \
.interface("lan") \
.start(100) \
.limit(150) \
.leasetime("12h")
# Configure wireless
config.wireless.radio("radio0") \
.channel(11) \
.htmode("HT20") \
.country("US") \
.disabled(False)
config.wireless.wifi_iface("ap_two") \
.device("radio0") \
.mode("ap") \
.network("lan") \
.ssid("my-network") \
.encryption("psk2") \
.key("your-password")
# Connect to remote device
ssh = SSHConnection("192.168.1.1", username="root", password="your-password")
# Compare with remote configuration
diff = config.diff(ssh)
print(diff)
# Apply configuration if satisfied
if input("Apply changes? (y/n): ") == "y":
config.apply(ssh)
Supported UCI Components
Currently supported UCI packages and options:
Network
- Devices: bridges, VLANs (8021q)
- Interfaces: static, DHCP, batman-adv, batman-adv hardif
Wireless
- Radios: channel, htmode, country, txpower
- Interfaces: AP, mesh, station modes
- Features: 802.11r fast roaming, WPA2/WPA3 encryption
DHCP
- DHCP server configuration
- IP range, lease time, interface binding
Firewall
- Zones (input/output/forward policies)
- Forwarding rules
- Masquerading and MTU fix
Examples
Check out the examples directory for:
- simple_example.py - Basic router setup
- router_config.py - Advanced mesh network configuration
Development
Running Tests
pip install -e ".[dev]"
pytest
Code Quality
black src/ tests/ examples/
ruff check src/ tests/ examples/
mypy src/wrtkit
Publishing to PyPI
See PUBLISHING.md for detailed instructions on how to publish this package to PyPI.
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wrtkit-0.1.0.tar.gz.
File metadata
- Download URL: wrtkit-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c447cf2b12f89928e78bd638e0c0244073978617b308be88f7792f1812c2d9e
|
|
| MD5 |
1b0ba8e5baaeb5e8df4d891ffc393a2e
|
|
| BLAKE2b-256 |
8fa8199b253a00252f5fd5b88135916d12dbbc2cba6c36c6a4ca65410dc9ae2b
|
File details
Details for the file wrtkit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wrtkit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78b12e260c3a8773d4874bd28b7984579f510cc5aa3fb67be35f0d308181f170
|
|
| MD5 |
57c4b84d3d22494ef1d4ae9441ecec16
|
|
| BLAKE2b-256 |
5714b23f35c3d9f9544f71b3251f6e4b079aa224c001b3347c7de755bd5de44f
|