{"library":"pyangbind","title":"PyangBind","description":"PyangBind is a plugin for `pyang` that converts YANG data models into a Python class hierarchy, enabling Python to manipulate data conforming to a YANG model. It facilitates programmatic interaction with network device configurations and operational state. The current version is 0.8.7, and releases are typically made a few times per year, often driven by bug fixes or new feature support.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install pyangbind"],"cli":null},"imports":["from pyangbind.lib.base import PybindBase","from pyangbind.lib.serialise import pybind_to_dict","from pyangbind.lib.yangtypes import RestrictedPrecisionDecimal"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\n\n# 1. Create a simple YANG model file (e.g., 'example.yang')\nyang_model_content = '''\nmodule example {\n  yang-version 1;\n  namespace \"urn:example:pyangbind:test\";\n  prefix \"ex\";\n\n  container config {\n    leaf hostname {\n      type string;\n      description \"Device hostname.\";\n    }\n    leaf-list interfaces {\n      type string;\n      description \"List of interfaces.\";\n    }\n  }\n}\n'''\nwith open('example.yang', 'w') as f:\n    f.write(yang_model_content)\n\n# 2. Generate Python bindings using pyang\n# This command is typically run from the command line, not Python.\n# For demonstration, we simulate it.\n# In a real scenario, you'd run: pyang -f pybind -o my_bindings.py example.yang\nimport subprocess\ntry:\n    subprocess.run(['pyang', '-f', 'pybind', '-o', 'my_bindings.py', 'example.yang'], check=True)\n    print(\"Bindings generated successfully to my_bindings.py\")\nexcept FileNotFoundError:\n    print(\"Error: 'pyang' command not found. Ensure pyangbind is installed correctly.\")\n    exit(1)\nexcept subprocess.CalledProcessError as e:\n    print(f\"Error generating bindings: {e}\")\n    print(e.stderr.decode())\n    exit(1)\n\n# 3. Use the generated Python classes\nimport my_bindings\nfrom pyangbind.lib.serialise import pybind_to_dict\n\n# Instantiate the top-level module class\n# The class name is typically derived from the YANG module name (e.g., 'example')\ninst = my_bindings.example()\n\n# Set values for the 'config' container and its leaves\ninst.config.hostname = \"my-device-1\"\ninst.config.interfaces.add(\"eth0\")\ninst.config.interfaces.add(\"eth1\")\n\n# Access and print values\nprint(f\"Hostname: {inst.config.hostname}\")\nprint(f\"Interfaces: {list(inst.config.interfaces)}\")\n\n# Serialize the object to a dictionary\ndata_dict = pybind_to_dict(inst)\nprint(\"\\nSerialized data:\")\nimport json\nprint(json.dumps(data_dict, indent=2))\n\n# Clean up generated files\nos.remove('example.yang')\nos.remove('my_bindings.py')\n","lang":"python","description":"This quickstart demonstrates how to define a simple YANG model, generate Python bindings using the `pyang` tool with the `pybind` plugin, and then interact with the generated Python classes to set data and serialize it to a dictionary.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"0.8.7","pypi_latest":"0.8.7","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3,"avg_import_s":0,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"34.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.2,"import_time_s":0,"mem_mb":0,"disk_size":"36M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"37.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.8,"import_time_s":0,"mem_mb":0,"disk_size":"38M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"29.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.6,"import_time_s":0,"mem_mb":0,"disk_size":"30M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"29.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.7,"import_time_s":0,"mem_mb":0,"disk_size":"30M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"34.2M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyangbind","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3.7,"import_time_s":0,"mem_mb":0,"disk_size":"35M"}]}}