Skip to main content

yang2sdk

Generate a Pydantic v2, IDE-friendly SDK for your network device directly from the YANG modules it actually runs.

flowchart LR
    A[yang-downloader<br/>get-schema off the box] --> B[yang2sdk<br/>you confirm the roots]
    B --> C[yang2sdk --protocol<br/>AST → IR → Jinja]
    C --> D[versioned Python package]
    D --> E[HAL + adapters<br/>multi-vendor automation]
    D -. lab-only .-> F[sdk-verify<br/>read + RPC + gated CRUD]

Both targets share the same navigator intent — retrieve / update / replace / create / delete, RPC __call__ — but the per-class surface is asymmetrical by protocol (e.g. RESTCONF plural lists expose create, not update; NETCONF plural lists expose update, not delete); only transport/encoding differs (JSON vs XML). See docs/usage.md and AGENTS.md parity table.

Example

from g30_1_4_0 import RestconfClient

# Auth comes from args or DEVICE_USER / DEVICE_PASS at runtime.
# Nothing is baked into generated code. verify=True is the default.
client = RestconfClient(management_ip="192.0.2.10")

# Top-level data is "<module>_<node>"; lists take key(s) in `key` order.
iface = client.data.ietf_interfaces_interface("ethernet-1/1")

port = iface.retrieve(content="config", depth=2)
port.description = "uplink-to-core"
iface.update(port)  # PATCH merge — the verb you normally want

Pydantic validates on assignment, so the IDE catches bad values before they reach the device:

port.admin_status = "dowm"
# ValidationError: Input should be 'up' or 'down'

replace() is PUT / nc:operation="replace" — the body is the whole resource (RFC 8040 §4.5, RFC 6241 §8.2.1). It refuses a depth-truncated model instead of silently deleting the rest; read deeper, use update(), or pass allow_partial=True when deletion is intended. See docs/usage.md.

For network engineers

Requires Python >= 3.12 and uv.

git clone https://github.com/ConsortiumGARR/yang2sdk.git
cd yang2sdk
uv sync --locked --extra lab
cp .env.example .env   # never commit .env; DEVICE_USER / DEVICE_PASS live here
uv run yang-downloader
mkdir -p temp/yang_tree
uv run pyang -p temp/yang_modules/<device>/ -f tree temp/yang_modules/<device>/*.yang > temp/yang_tree/<device>.txt
uv run yang2sdk --protocol netconf   --device <device>   # picks the roots for you
uv run yang2sdk --protocol restconf --device <device>

temp/ is an untracked workspace — every command creates its own output dir on demand, so a fresh clone has no temp/ until the first run (and rm -rf temp/ only loses re-downloadable/recompilable output).

Each compile emits a self-contained package at temp/<protocol>_clients/<device>_<os-version>/ (client, models, navigators, pyproject.toml, README, MANIFEST.yang-revisions.json, py.typed):

uv add path/to/temp/restconf_clients/<device>_<os-version>
from <device>_<os_version> import RestconfClient  # or NetconfClient

One package per device and OS version — different YANG revisions produce different models. Next: compile flags and HAL sketch · lab validation with sdk-verify.

For contributors

uv sync --locked --group dev --extra lab
uv run ruff check . && uv run ruff format --check . \
  && uv run ty check && uv run pyrefly check \
  && uv run pytest tests/test_matrix.py   # offline gate: no docker, no device

ruff is the only linter/formatter. ty and pyrefly must both pass on src/ (temp/ output is excluded). The four gates are pinned exactly and run from the venv, never via uvx — see docs/dev.md for why, and for the bump procedure. Live-matrix tests need docker / lab gear — see docs/dev.md for the test/CI matrix and AGENTS.md for the normative generator contract.

Docs

Doc Audience Contents
docs/usage.md network engineer Credentials, transport defaults, NETCONF write safety, RPCs/actions, packaging, HAL
docs/lab.md network engineer sdk-verify tiers and write gates, simulator matrix, SR Linux job
docs/dev.md contributor Gates, tool pinning and the bump procedure, tests, CI
AGENTS.md contributor Normative generator contract (IR ↔ templates, RFC compliance, safety)
CONTRIBUTING.md contributor Setup, the gate checklist, house rules
SECURITY.md security reporter Scope, private reporting, credential and transport-default guarantees

Status

Public prototype. Both protocols generate; wire shapes are pinned offline in tests/test_matrix.py and exercised live against notconf simulators, SR Linux (full vendor tree, non-NMDA), and the Groove G30. Alternatives (pydantify, pyangbind) cover data modelling but not network operations — this project generates models and the operation code on top of pyang.

Metadata

Release files for yang2sdk 2026.10.16.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 yang2sdk 2026.10.16.1
File Size Uploaded
yang2sdk-2026.10.16.1.tar.gz 372.5 kB Details

Built distribution (wheel)

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

Total release size: 506.8 kB

Release files / yang2sdk-2026.10.16.1.tar.gz

Download URL yang2sdk-2026.10.16.1.tar.gz
Size 372.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9f2887ac96f2848ca167a8f0b0406464f8b4d0e995bd70d424b0954cd53b5326
BLAKE2b-256 checksum
How to use checksums
e6f0fab76f0dbf8785521e697a8bd67ce95b52615b6f29aae7b86a84323f0608
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 Oct 16, 2026.

Transparency log

Release files / yang2sdk-2026.10.16.1-py3-none-any.whl

Download URL yang2sdk-2026.10.16.1-py3-none-any.whl
Size 134.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
313c5e692bc9b9e11d0b29db7d204ef293d704a24121a9ca69ecdd589f56e4db
BLAKE2b-256 checksum
How to use checksums
fb119f87c2add754eaa6ad175d26215370c7f0773ffcd52659986a98325c2e70
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 Oct 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2026.10.16.1 This release

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