Skip to main content

UCI Parse Library

pypi license wheel python Test Suite docs coverage

Python 3 library and command line tools to parse, diff, and normalize OpenWRT UCI configuration files.

These tools were written to ease OpenWRT upgrades, making it easier to see the differences between two config files. As of this writing (mid-2020), OpenWRT upgrades often don't normalize upgraded config files in the same way from version to version. For instance, the new version from opkg upgrade (saved off with a -opkg filename) might use single quotes on all lines, while the original version on disk might not use quotes at all. This makes it very difficult understand the often-minimal differences between an upgraded file and the original file.

Statement on free-threading: This code is single-threaded by design. Starting with Python 3.14, the matrix build CI workflow in GitHub Actions ensures that the test suite passes for both standard and free-threaded interpreters.

Installing the Package

Installing this package on your OpenWRT router is not as simple as it could be. A lot of routers do not have enough space available to install a full version of Python including pip or setuptools. If yours does have lots of space, it's as simple as this:

$ opkg update
$ opkg install python3-pip
$ pip3 install uciparse

If not, it gets a little ugly. First, install wget with support for HTTPS:

$ opkg update
$ opkg install wget ca-bundle ca-certificates

Then, go to PyPI and copy the URL for the source package .tar.gz file. Retrieve the source package with wget and then manually extract it:

$ wget https://files.pythonhosted.org/.../uciparse-0.1.2.tar.gz
$ tar zxvf uciparse-0.1.2.tar.gz
$ cd uciparse-0.1.2

Finally, run the custom install script provided with the source package:

$ sh ./scripts/install

This installs the OpenWRT python3-light package, then copies the Python packages into the right site-packages directory and the uciparse and ucidiff scripts to /usr/bin.

Using the Tools

Once you have installed the package as described above, the uciparse and ucidiff tools will be available in your path.

ucidiff

The ucidiff tool is probably the tool you'll use most often when updating your router. It reads two UCI configuration files from disk, normalizes both in memory (without making changes on disk), and then compares them. The result is a unified diff, like diff -Naur. This gives you a way to understand the real differences between two files without ever having to change anything on disk.

$ ucidiff --help
usage: ucidiff [-h] a b

Diff two UCI configuration files.

positional arguments:
  a           Path to the first UCI file to compare
  b           Path to the second UCI file to compare

optional arguments:
  -h, --help  show this help message and exit

The comparison is equivalent to a 'diff -Naur' between the normalized versions
of the files. If either file can't be parsed, then an error will be returned
and no diff will be shown.

uciparse

If you would prefer to clean up and normalize your configuration files on disk, then you can use the uciparse tool. It reads a UCI config file from disk or from stdin, parses it, and prints normalized output to stdout.

$ uciparse --help
usage: uciparse [-h] uci

Parse and normalize a UCI configuration file.

positional arguments:
  uci         Path to the UCI file to normalize, or '-' for stdin

optional arguments:
  -h, --help  show this help message and exit

Results will be printed to stdout. If the file can't be parsed then an error
will be returned and no output will be generated.

Before using uciparse, you should make a backup of any config file that you are going to normalized.

Metadata

Release files for uciparse 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for uciparse 0.3.1
File Size Uploaded
uciparse-0.3.1.tar.gz 38.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for uciparse 0.3.1
File Interpreter ABI Platform
uciparse-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 52.6 kB

Release files / uciparse-0.3.1.tar.gz

Download URL uciparse-0.3.1.tar.gz
Size 38.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3cee6bbb7fb0967cf6ba0d766d4651b5f0cd9cca9b88e7684b7a96311a970c30
BLAKE2b-256 checksum
How to use checksums
877dff198ab7f63202288e767b48d20e58bfd8fe9745e9a5df352a81691f3f40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / uciparse-0.3.1-py3-none-any.whl

Download URL uciparse-0.3.1-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bbfa4540406ccca47463bee7251dbef97eabd0c8409a67319eb0f783193121d
BLAKE2b-256 checksum
How to use checksums
9ca0f7b05ec1b764c6e1f27878f9fdccba4158a54b37e89ba9686a3b4774f539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.24

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.20

2 release files

0.1.17

2 release files

0.1.16

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page