This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.1.1 instead.
Reason given by maintainers: not compatible with macos
Opinionated Python bindings for the libyang library
Python bindings and packaging of libyang.
We're focusing on parsing, validating and accessing YANG-modeled JSON data trees.
Essentially, just enough to get gnpy going.
Want more?
Patches welcome.
Compared to the CFFI libyang bindings, this wrapper takes care of low-level memory management.
This means no more node.free() and ctx.destroy().
We also produce prebuilt binary wheels to make installation very simple.
Usage
Loading YANG data
import oopt_gnpy_libyang as ly
c = ly.Context('tests/yang', ly.ContextOptions.RefImplemented | ly.ContextOptions.NoYangLibrary)
for m in ('iana-if-type', 'ietf-interfaces', 'ietf-ip'):
c.load_module(m)
blob = '''{
"ietf-interfaces:interfaces": {
"interface": [
{
"name": "lo",
"type": "iana-if-type:softwareLoopback",
"ietf-ip:ipv4": {
"address": [
{
"ip": "127.0.0.1",
"prefix-length": 8
}
]
},
"ietf-ip:ipv6": {
"address": [
{
"ip": "::1",
"prefix-length": 128
}
]
}
},
{
"name": "eth0",
"type": "iana-if-type:ethernetCsmacd"
}
]
}
}'''
data = c.parse_data(blob,
ly.DataFormat.JSON, ly.ParseOptions.Strict | ly.ParseOptions.Ordered,
ly.ValidationOptions.Present | ly.ValidationOptions.NoState)
Working with data
Libyang works with forests (sets of trees), this is how to process all the data:
for x in data.siblings():
print(f'a sibling: {x.path}')
for xx in x.children_dfs():
print(f' {"term " if xx.is_term else "child"}: {xx.path}')
if xx.is_term:
print(f' {xx.as_term()} {" (default)" if xx.as_term().has_default_value else ""}')
Data can be accessed via their known paths, of course. Either as a full, multi-level XPath:
data["interface[name='lo']/ietf-ip:ipv6/address[ip='::1']/prefix-length"].as_term().value == 128
Or individually, one item per index:
data["interface[name='lo']"]["ietf-ip:ipv6"]["address[ip='::1']"]["prefix-length"].as_term().value
Everything is an XPath, so it's possible to take a shortcut and skip specifying keys for single-element lists:
data["interface[name='lo']"]["ietf-ip:ipv6"]["address"]["prefix-length"].as_term().value == 128
The data are provided as native Python types:
type(data["interface[name='lo']"]["ietf-ip:ipv6"]["address"]["prefix-length"]
.as_term().value) == int
Absolute paths and generic XPath expressions can be used to retrieve arbitrary parts of the data forest, and to iterate over them:
for iface in data.find("/ietf-interfaces:interfaces/interface"):
print iface["name"].as_term().value
Relative XPath conditions can be also used at the root level (which is represented as NULL in the C level):
for iface in search_at_root(data)("ietf-interfaces:interfaces/interface"):
print iface["name"].as_term().value
New values can be created; use None for non-terminals, or str when a value is needed:
node = ctx.create("/ietf-interfaces:interfaces/interface[name='666']")
another = ctx.create("/ietf-interfaces:interfaces/interface[name='666']/ietf-ip:ipv6/enabled", "true")
data["interface[name='lo']"]["ietf-ip:ipv6"]["address"]["prefix-length"] = "64"
Validation errors
In libyang, if an operation fails, error details are available via context.errors():
import json
wrong = json.loads(blob)
wrong["ietf-interfaces:interfaces"]["interface"][0]\
["ietf-ip:ipv6"]["address"][0]["prefix-length"] = 666
try:
data = c.parse_data(json.dumps(wrong),
ly.DataFormat.JSON, ly.ParseOptions.Strict | ly.ParseOptions.Ordered,
ly.ValidationOptions.Present | ly.ValidationOptions.NoState)
assert False
except ly.Error:
for error in c.errors():
assert error.schema_path is None
assert error.data_path == "/ietf-interfaces:interfaces/interface[name='lo']/ietf-ip:ipv6/address[ip='::1']/prefix-length"
assert error.line > 0
assert error.message == 'Value "666" is out of type uint8 min/max bounds.'
Installing
We're producing wheels for many popular platforms. The installation is as simple as:
$ pip install oopt-gnpy-libyang
Building from source
Since this library is a Python wrapper around a C++ wrapper around a C library, source-based builds are more complex. They require:
- a C++20 compiler (e.g., GCC 10+, clang 10+, MSVC 17.2+)
libyangand its dependencieslibyang-cppand its dependencies- CMake 3.21+
Unlike the wheels already bundle all the required libraries, when building from source, libyang, libyang-cpp and all their dependencies will have to be installed first.
Also, in a from-source build these won't be bundled into the resulting package.
For an inspiration, consult our GitHub packaging recipes.
License
Copyright © 2021-2023 Telecom Infra Project and GNPy contributors. Licensed under the 3-clause BSD license.
Metadata
Release files for oopt-gnpy-libyang 0.0.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| oopt_gnpy_libyang-0.0.15.tar.gz | 50.9 kB | Details |
Built distributions (wheels)
Total release size: 10.9 MB
Release files / oopt_gnpy_libyang-0.0.15.tar.gz
| Download URL | oopt_gnpy_libyang-0.0.15.tar.gz |
|---|---|
| Size | 50.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9b4ecddba3e5e2be09431f8db3fefdb1df1fac0c240575129cc962bf6310ed46
|
|
BLAKE2b-256 checksum How to use checksums |
1a892cb864981cb54b856ac8a540de60f03d128acd05e8694d22c8a4dd631964
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-win_amd64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3c4282568b02125f887acfcd4cca2433a1127cf892cfa06f75aa743d9461c170
|
|
BLAKE2b-256 checksum How to use checksums |
b75c88b40f35c48bc5d4dfa0d91fc5340bc0493e24fb82b9909aa19fb4a7fdd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 Linux glibc 2.35+ x86-64 |
|
SHA-256 checksum How to use checksums |
98cf140c7bd756b52671538caeac57668d1facb9ba0bccba0d52d595a8c5cbae
|
|
BLAKE2b-256 checksum How to use checksums |
f2c1f24542ab6ef1886263a22190fb6dcca5550ca4e9d12799e08b7fe17e4757
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_26_0_x86_64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_26_0_x86_64.whl |
|---|---|
| Size | 807.4 kB |
| Tags | CPython 3.13 macOS 26.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
ce5a81d04bd5f52d20fea52c0fb9aa6322f494930d403eb62181edaeedb91b18
|
|
BLAKE2b-256 checksum How to use checksums |
be5139bcc04475ddc531eaf4fa19106e319c195086f4916c6f81f0abdd5f36fd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_26_0_arm64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_26_0_arm64.whl |
|---|---|
| Size | 736.8 kB |
| Tags | CPython 3.13 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e23629ae09b8e48a2ee83d720b5cdd1858da1412588b9f08eeec3495b801a00e
|
|
BLAKE2b-256 checksum How to use checksums |
3f809e0c6143792ddf01fed9ef2ca4e5fe5c5fb805f99651fefa0fed2aef6925
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_15_0_x86_64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_15_0_x86_64.whl |
|---|---|
| Size | 808.2 kB |
| Tags | CPython 3.13 macOS 15.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
0a5162fb3642973cd08a91d4cbb242019158eb90e57da4844d0f131bd9cf83ee
|
|
BLAKE2b-256 checksum How to use checksums |
67032f44b13612fc422946fa3b5efdd227ed18fac45c74dc530623cccb22868f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_15_0_arm64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp313-cp313-macosx_15_0_arm64.whl |
|---|---|
| Size | 736.9 kB |
| Tags | CPython 3.13 macOS 15.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5998473db76589b2ff53a3cd2311f2f690931a23c326b5cad30fb74261d59478
|
|
BLAKE2b-256 checksum How to use checksums |
edfc420f420c80ed1869ff3b5f43c712f64e87b49f2a7dbf26c57210677f983d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp312-cp312-win_amd64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
dee1c1874ad4d2bc75720a5f30993c52c78b995cb7e7062f4411628679ad69e7
|
|
BLAKE2b-256 checksum How to use checksums |
95f12b5bb9af446ad98138a0529cb350a75df0ad0a932ff6c32ebd7085704161
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp312-cp312-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp312-cp312-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.34+ x86-64 Linux glibc 2.35+ x86-64 |
|
SHA-256 checksum How to use checksums |
cd5e31ac59a4a5e124fb945ff37afdaa90ec9899609bb1cc655a2a300c219d20
|
|
BLAKE2b-256 checksum How to use checksums |
85fecf32c622360cb99c5e8700ec45b9de732cb18f6c47e9a8b11140441b0bb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp311-cp311-win_amd64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
484317a1aa73429386f64ed22013ebfa6cb97aec29aafea4d12f1a9977ac9ecf
|
|
BLAKE2b-256 checksum How to use checksums |
e80e55af3af9eda2567c7163aaabdc4d0df1262e59620cf8992d90b4c43b1731
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency logRelease files / oopt_gnpy_libyang-0.0.15-cp311-cp311-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl
| Download URL | oopt_gnpy_libyang-0.0.15-cp311-cp311-manylinux_2_34_x86_64.manylinux_2_35_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 Linux glibc 2.34+ x86-64 Linux glibc 2.35+ x86-64 |
|
SHA-256 checksum How to use checksums |
506bb6fd460f8888384540a9cacf109fdcda59945c01259efdc22cc9a26ada1f
|
|
BLAKE2b-256 checksum How to use checksums |
4ab5d62e8d7847ee1c41068b48c27b8ab83d9b3adf57e5236c93167ba3fa7970
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 27, 2026.
Transparency log