{"id":29357018,"url":"https://github.com/cesnet/libyang-python","last_synced_at":"2025-09-10T11:39:09.992Z","repository":{"id":37859119,"uuid":"275748507","full_name":"CESNET/libyang-python","owner":"CESNET","description":"Python bindings for the libyang library","archived":false,"fork":false,"pushed_at":"2025-06-29T19:38:44.000Z","size":361,"stargazers_count":65,"open_issues_count":23,"forks_count":51,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-08T14:33:22.561Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CESNET.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-29T06:23:52.000Z","updated_at":"2025-06-29T19:38:48.000Z","dependencies_parsed_at":"2024-02-07T14:25:26.663Z","dependency_job_id":"33bd4ae5-e9b8-463e-9bae-fba80d870c95","html_url":"https://github.com/CESNET/libyang-python","commit_stats":{"total_commits":230,"total_committers":16,"mean_commits":14.375,"dds":"0.34782608695652173","last_synced_commit":"d8549c8a900a6a5ef3bb86f8d7859849e7964b5a"},"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"purl":"pkg:github/CESNET/libyang-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CESNET%2Flibyang-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CESNET%2Flibyang-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CESNET%2Flibyang-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CESNET%2Flibyang-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CESNET","download_url":"https://codeload.github.com/CESNET/libyang-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CESNET%2Flibyang-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274455910,"owners_count":25288557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-09T05:41:27.043Z","updated_at":"2025-09-10T11:39:09.969Z","avatar_url":"https://github.com/CESNET.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==============\nlibyang-python\n==============\n\nPython CFFI bindings to libyang__.\n\n__ https://github.com/CESNET/libyang/\n\n|pypi-project|__ |python-versions|__ |build-status|__ |license|__ |code-style|__\n\n__ https://pypi.org/project/libyang\n__ https://github.com/CESNET/libyang-python/actions\n__ https://github.com/CESNET/libyang-python/actions\n__ https://github.com/CESNET/libyang-python/blob/master/LICENSE\n__ https://github.com/psf/black\n\n.. |pypi-project| image:: https://img.shields.io/pypi/v/libyang.svg\n.. |python-versions| image:: https://img.shields.io/pypi/pyversions/libyang.svg\n.. |build-status| image:: https://github.com/CESNET/libyang-python/workflows/CI/badge.svg\n.. |license| image:: https://img.shields.io/github/license/CESNET/libyang-python.svg\n.. |code-style| image:: https://img.shields.io/badge/code%20style-black-000000.svg\n\nInstallation\n============\n\n::\n\n   pip install libyang\n\nThis assumes ``libyang.so`` is installed in the system and that ``libyang.h`` is\navailable in the system include dirs.\n\nYou need the following system dependencies installed:\n\n- Python development headers\n- GCC\n- FFI development headers\n\nOn a Debian/Ubuntu system::\n\n   sudo apt-get install python3-dev gcc python3-cffi\n\nCompatibility\n-------------\n\nThe current version requires at least C `libyang 2.25`__.\n\nThe last version of the bindings that works with C `libyang 1.x`__ is v1.7.0__.\n\n__ https://github.com/CESNET/libyang/commit/d2f1608b348f\n__ https://github.com/CESNET/libyang/tree/libyang1\n__ https://pypi.org/project/libyang/1.7.0/\n\nCompilation Flags\n-----------------\n\nIf libyang headers and libraries are installed in a non-standard location, you\ncan specify them with the ``LIBYANG_HEADERS`` and ``LIBYANG_LIBRARIES``\nvariables. Additionally, for finer control, you may use ``LIBYANG_EXTRA_CFLAGS``\nand ``LIBYANG_EXTRA_LDFLAGS``::\n\n   LIBYANG_HEADERS=/home/build/opt/ly/include \\\n   LIBYANG_LIBRARIES=/home/build/opt/ly/lib \\\n   LIBYANG_EXTRA_CFLAGS=\"-O3\" \\\n   LIBYANG_EXTRA_LDFLAGS=\"-rpath=/opt/ly/lib\" \\\n          pip install libyang\n\nExamples\n========\n\nSchema Introspection\n--------------------\n\n.. code-block:: pycon\n\n   \u003e\u003e\u003e import libyang\n   \u003e\u003e\u003e ctx = libyang.Context('/usr/local/share/yang/modules')\n   \u003e\u003e\u003e module = ctx.load_module('ietf-system')\n   \u003e\u003e\u003e print(module)\n   module: ietf-system\n     +--rw system\n     |  +--rw contact?          string\n     |  +--rw hostname?         ietf-inet-types:domain-name\n     |  +--rw location?         string\n     |  +--rw clock\n     |  |  +--rw (timezone)?\n     |  |     +--:(timezone-utc-offset)\n     |  |        +--rw timezone-utc-offset?   int16\n     |  +--rw dns-resolver\n     |     +--rw search*    ietf-inet-types:domain-name\n     |     +--rw server* [name]\n     |     |  +--rw name          string\n     |     |  +--rw (transport)\n     |     |     +--:(udp-and-tcp)\n     |     |        +--rw udp-and-tcp\n     |     |           +--rw address    ietf-inet-types:ip-address\n     |     +--rw options\n     |        +--rw timeout?    uint8 \u003c5\u003e\n     |        +--rw attempts?   uint8 \u003c2\u003e\n     +--ro system-state\n        +--ro platform\n        |  +--ro os-name?      string\n        |  +--ro os-release?   string\n        |  +--ro os-version?   string\n        |  +--ro machine?      string\n        +--ro clock\n           +--ro current-datetime?   ietf-yang-types:date-and-time\n           +--ro boot-datetime?      ietf-yang-types:date-and-time\n\n     rpcs:\n       +---x set-current-datetime\n       |  +---- input\n       |     +---w current-datetime    ietf-yang-types:date-and-time\n       +---x system-restart\n       +---x system-shutdown\n\n   \u003e\u003e\u003e xpath = '/ietf-system:system/ietf-system:dns-resolver/ietf-system:server'\n   \u003e\u003e\u003e dnsserver = next(ctx.find_path(xpath))\n   \u003e\u003e\u003e dnsserver\n   \u003clibyang.schema.SList: server [name]\u003e\n   \u003e\u003e\u003e print(dnsserver.description())\n   List of the DNS servers that the resolver should query.\n\n   When the resolver is invoked by a calling application, it\n   sends the query to the first name server in this list.  If\n   no response has been received within 'timeout' seconds,\n   the resolver continues with the next server in the list.\n   If no response is received from any server, the resolver\n   continues with the first server again.  When the resolver\n   has traversed the list 'attempts' times without receiving\n   any response, it gives up and returns an error to the\n   calling application.\n\n   Implementations MAY limit the number of entries in this\n   list.\n   \u003e\u003e\u003e dnsserver.ordered()\n   True\n   \u003e\u003e\u003e for node in dnsserver:\n   ...     print(repr(node))\n   ...\n   \u003clibyang.schema.SLeaf: name string\u003e\n   \u003clibyang.schema.SContainer: udp-and-tcp\u003e\n   \u003e\u003e\u003e ctx.destroy()\n   \u003e\u003e\u003e\n\nData Tree\n---------\n\n.. code-block:: pycon\n\n   \u003e\u003e\u003e import libyang\n   \u003e\u003e\u003e ctx = libyang.Context()\n   \u003e\u003e\u003e module = ctx.parse_module_str('''\n   ... module example {\n   ...   namespace \"urn:example\";\n   ...   prefix \"ex\";\n   ...   container data {\n   ...     list interface {\n   ...       key name;\n   ...       leaf name {\n   ...         type string;\n   ...       }\n   ...       leaf address {\n   ...         type string;\n   ...       }\n   ...     }\n   ...     leaf hostname {\n   ...       type string;\n   ...     }\n   ...   }\n   ... }\n   ... ''')\n   \u003e\u003e\u003e print(module.print_mem('tree'))\n   module: example\n     +--rw data\n        +--rw interface* [name]\n        |  +--rw name       string\n        |  +--rw address?   string\n        +--rw hostname?    string\n   \u003e\u003e\u003e node = module.parse_data_dict({\n   ...     'data': {\n   ...         'hostname': 'foobar',\n   ...         'interface': [\n   ...             {'name': 'eth0', 'address': '1.2.3.4/24'},\n   ...             {'name': 'lo', 'address': '127.0.0.1'},\n   ...         ],\n   ...     },\n   ... })\n   \u003e\u003e\u003e print(node.print_mem('xml', pretty=True))\n   \u003cdata xmlns=\"urn:example\"\u003e\n     \u003cinterface\u003e\n       \u003cname\u003eeth0\u003c/name\u003e\n       \u003caddress\u003e1.2.3.4/24\u003c/address\u003e\n     \u003c/interface\u003e\n     \u003cinterface\u003e\n       \u003cname\u003elo\u003c/name\u003e\n       \u003caddress\u003e127.0.0.1\u003c/address\u003e\n     \u003c/interface\u003e\n     \u003chostname\u003efoobar\u003c/hostname\u003e\n   \u003c/data\u003e\n   \u003e\u003e\u003e node.print_dict()\n   {'data': {'interface': [{'name': 'eth0', 'address': '1.2.3.4/24'}, {'name':\n   'lo', 'address': '127.0.0.1'}], 'hostname': 'foobar'}}\n   \u003e\u003e\u003e node.free()\n   \u003e\u003e\u003e ctx.destroy()\n   \u003e\u003e\u003e\n\nSee the ``tests`` folder for more examples.\n\nContributing\n============\n\nThis is an open source project and all contributions are welcome.\n\nIssues\n------\n\nPlease create new issues for any bug you discover at\nhttps://github.com/CESNET/libyang-python/issues/new. It is not necessary to file\na bug if you are preparing a patch.\n\nPull Requests\n-------------\n\nHere are the steps for submitting a change in the code base:\n\n#. Fork the repository: https://github.com/CESNET/libyang-python/fork\n\n#. Clone your own fork into your development machine::\n\n      git clone https://github.com/\u003cyou\u003e/libyang-python\n\n#. Create a new branch named after what your are working on::\n\n      git checkout -b my-topic -t origin/master\n\n#. Edit the code and call ``make format`` to ensure your modifications comply\n   with the `coding style`__.\n\n   __ https://black.readthedocs.io/en/stable/the_black_code_style.html\n\n   Your contribution must be licensed under the `MIT License`__ . At least one\n   copyright notice is expected in new files.\n\n   __ https://spdx.org/licenses/MIT.html\n\n#. If you are adding a new feature or fixing a bug, please consider adding or\n   updating unit tests.\n\n#. Before creating commits, run ``make lint`` and ``make tests`` to check if\n   your changes do not break anything. You can also run ``make`` which will run\n   both.\n\n#. Once you are happy with your work, you can create a commit (or several\n   commits). Follow these general rules:\n\n   -  Address only one issue/topic per commit.\n   -  Describe your changes in imperative mood, e.g. *\"make xyzzy do frotz\"*\n      instead of *\"[This patch] makes xyzzy do frotz\"* or *\"[I] changed xyzzy to\n      do frotz\"*, as if you are giving orders to the codebase to change its\n      behaviour.\n   -  Limit the first line (title) of the commit message to 60 characters.\n   -  Use a short prefix for the commit title for readability with ``git log\n      --oneline``. Do not use the `fix:` nor `feature:` prefixes. See recent\n      commits for inspiration.\n   -  Only use lower case letters for the commit title except when quoting\n      symbols or known acronyms.\n   -  Use the body of the commit message to actually explain what your patch\n      does and why it is useful. Even if your patch is a one line fix, the\n      description is not limited in length and may span over multiple\n      paragraphs. Use proper English syntax, grammar and punctuation.\n   -  If you are fixing an issue, use appropriate ``Closes: \u003cURL\u003e`` or\n      ``Fixes: \u003cURL\u003e`` trailers.\n   -  If you are fixing a regression introduced by another commit, add a\n      ``Fixes: \u003cCOMMIT_ID\u003e (\"\u003cTITLE\u003e\")`` trailer.\n   -  When in doubt, follow the format and layout of the recent existing\n      commits.\n   -  The following trailers are accepted in commits. If you are using multiple\n      trailers in a commit, it's preferred to also order them according to this\n      list.\n\n      *  ``Closes: \u003cURL\u003e``: close the referenced issue or pull request.\n      *  ``Fixes: \u003cSHA\u003e (\"\u003cTITLE\u003e\")``: reference the commit that introduced\n         a regression.\n      *  ``Link: \u003cURL\u003e``: any useful link to provide context for your commit.\n      *  ``Suggested-by``\n      *  ``Requested-by``\n      *  ``Reported-by``\n      *  ``Co-authored-by``\n      *  ``Tested-by``\n      *  ``Reviewed-by``\n      *  ``Acked-by``\n      *  ``Signed-off-by``: Compulsory!\n\n   There is a great reference for commit messages in the `Linux kernel\n   documentation`__.\n\n   __ https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes\n\n   IMPORTANT: you must sign-off your work using ``git commit --signoff``. Follow\n   the `Linux kernel developer's certificate of origin`__ for more details. All\n   contributions are made under the MIT license. If you do not want to disclose\n   your real name, you may sign-off using a pseudonym. Here is an example::\n\n       Signed-off-by: Robin Jarry \u003crobin@jarry.cc\u003e\n\n   __ https://www.kernel.org/doc/html/latest/process/submitting-patches.html#sign-your-work-the-developer-s-certificate-of-origin\n\n#. Push your topic branch in your forked repository::\n\n      git push origin my-topic\n\n   You should get a message from Github explaining how to create a new pull\n   request.\n\n#. Wait for a reviewer to merge your work. If minor adjustments are requested,\n   use ``git commit --fixup $sha1`` to make it obvious what commit you are\n   adjusting. If bigger changes are needed, make them in new separate commits.\n   Once the reviewer is happy, please use ``git rebase --autosquash`` to amend\n   the commits with their small fixups (if any), and ``git push --force`` on\n   your topic branch.\n\nThank you in advance for your contributions!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesnet%2Flibyang-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcesnet%2Flibyang-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcesnet%2Flibyang-python/lists"}