package/python-libyang: new package

Python CFFI bindings for the libyang YANG library, providing the
'libyang' Python module for YANG data modeling operations.

This package is used by higher-level tooling such as python-sysrepo.

https://github.com/CESNET/libyang-python
Signed-off-by: Vincent Jardin <vjardin@free.fr>
Signed-off-by: Vincent Cruz <mooz@blockos.org>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
This commit is contained in:
Vincent Jardin
2026-04-16 12:24:21 +02:00
committed by Thomas Petazzoni
parent 50d017a2d6
commit 3872cf8a75
7 changed files with 104 additions and 0 deletions

View File

@@ -3368,6 +3368,7 @@ F: package/dpdk/
F: package/libecoli/
F: package/libnss-ato/
F: package/libyang-cpp/
F: package/python-libyang/
F: package/sysrepo-cpp/
N: Vincent Prince <vincent.prince.fr@gmail.com>

View File

@@ -1211,6 +1211,7 @@ menu "External python modules"
source "package/python-libevdev/Config.in"
source "package/python-librt/Config.in"
source "package/python-libusb1/Config.in"
source "package/python-libyang/Config.in"
source "package/python-lmdb/Config.in"
source "package/python-lockfile/Config.in"
source "package/python-log-rate-limit/Config.in"

View File

@@ -0,0 +1,18 @@
config BR2_PACKAGE_PYTHON_LIBYANG
bool "python-libyang"
depends on BR2_TOOLCHAIN_HAS_SYNC_4 # libyang
depends on BR2_TOOLCHAIN_HAS_THREADS # libyang
depends on !BR2_STATIC_LIBS # libyang
select BR2_PACKAGE_LIBYANG
select BR2_PACKAGE_PYTHON_CFFI # runtime
help
Python CFFI bindings for the libyang YANG library.
This package provides the 'libyang' Python module, used by
higher-level tooling such as python-sysrepo.
https://github.com/CESNET/libyang-python
comment "python-libyang needs a toolchain w/ threads, dynamic library"
depends on !BR2_TOOLCHAIN_HAS_SYNC_4
depends on !BR2_TOOLCHAIN_HAS_THREADS || BR2_STATIC_LIBS

View File

@@ -0,0 +1,5 @@
# From https://pypi.org/pypi/libyang/3.3.0/json
sha256 97da2c908a8a3607ac834f2acec224ea53a4b9e9770c13e5598513641decf637 libyang-3.3.0.tar.gz
# Locally computed
sha256 c8d554f918d32b1467f35829e1cfb753764dd683c6edcecc877a4d7e9f05b2a7 LICENSE

View File

@@ -0,0 +1,21 @@
################################################################################
#
# python-libyang
#
################################################################################
PYTHON_LIBYANG_VERSION = 3.3.0
PYTHON_LIBYANG_SOURCE = libyang-$(PYTHON_LIBYANG_VERSION).tar.gz
PYTHON_LIBYANG_SITE = https://files.pythonhosted.org/packages/source/l/libyang
PYTHON_LIBYANG_LICENSE = MIT
PYTHON_LIBYANG_LICENSE_FILES = LICENSE
# pyproject.toml (PEP517)
PYTHON_LIBYANG_SETUP_TYPE = pep517
PYTHON_LIBYANG_DEPENDENCIES = \
libyang \
host-python-cffi
$(eval $(python-package))

View File

@@ -0,0 +1,46 @@
# test from https://github.com/CESNET/libyang-python/blob/master/README.rst
import libyang
from xml.etree import ElementTree
ctx = libyang.Context()
module = ctx.parse_module_str('''
module example {
namespace "urn:example";
prefix "ex";
container data {
list interface {
key name;
leaf name {
type string;
}
leaf address {
type string;
}
}
leaf hostname {
type string;
}
}
}
''')
node = module.parse_data_dict({
'data': {
'hostname': 'foobar',
'interface': [
{'name': 'eth0', 'address': '1.2.3.4/24'},
{'name': 'lo', 'address': '127.0.0.1'},
],
},
})
xml = node.print_mem('xml', pretty=True)
tree = ElementTree.fromstringlist(xml)
assert tree.tag == '{urn:example}data'
assert tree.find('.//{*}hostname').text == 'foobar'
assert len(tree.find('.//{*}interface')) == 2
node.free()
ctx.destroy()

View File

@@ -0,0 +1,12 @@
from tests.package.test_python import TestPythonPackageBase
class TestPythonLibyang(TestPythonPackageBase):
__test__ = True
config = TestPythonPackageBase.config + \
"""
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_PYTHON3_PYEXPAT=y
BR2_PACKAGE_PYTHON_LIBYANG=y
"""
sample_scripts = ["tests/package/sample_python_libyang.py"]