Skip to main content

Convert Junos configurations between XML, JSON, structured, and display set formats

Project description

Junoscfg (Python)

Convert and validate Junos configurations between JSON, structured, YAML, and display set formats.

Originally inspired by the Ruby Junoser gem, now a comprehensive Junos configuration toolkit.

Installation

pip install junoscfg

Usage

CLI

# Convert structured config to set commands
junoscfg -i structured -e set config.conf

# Convert JSON to set commands
junoscfg -i json -e set config.json

# Convert to structured format
junoscfg -e structured config.set

# Read from stdin
echo '{"configuration":{"system":{"host-name":"test"}}}' | junoscfg -i json -e set

# Transform YAML for Ansible (literal extraction)
junoscfg edityaml ansibilize -p "addr:interfaces.interface[*].name" config.yaml

# Offset mode for multi-router deployments (generates ipmath expressions)
junoscfg edityaml ansibilize -P "addr:interfaces.interface[*].unit[*].family.*.address[*].name" config.yaml

# Anonymize all sensitive data
junoscfg -i json -e set --anonymize-all config.json

# Anonymize with regex patterns (e.g. match site codes)
junoscfg -e set --anonymize-sensitive-patterns 'LAX\d+' config.json

# Retrieve XSD dump and generate schema artifacts
echo "<rpc> <get-xnm-information> <type>xml-schema</type> <namespace>junos-configuration</namespace> </get-xnm-information> </rpc>" | ssh -Csp 830 router.example.com netconf > netconf.xml
junoscfg schema generate netconf.xml -o ./artifacts/

Python API

from junoscfg import convert_config, Format, validate_json

# Convert between any format pair
result = convert_config(
    '{"configuration":{"system":{"host-name":"test"}}}',
    from_format=Format.JSON, to_format=Format.SET,
)

# Validate a JSON config
result = validate_json('{"configuration":{"system":{"host-name":"test"}}}')
print(result.valid)  # True

# Convert with strict field-level validation (raises on invalid enum/pattern/IP values)
result = convert_config(source, from_format=Format.JSON, to_format=Format.SET, strict=True)

# Anonymize a configuration
from junoscfg.anonymize import anonymize
from junoscfg.anonymize.config import AnonymizeConfig

config = AnonymizeConfig(ips=True, passwords=True, salt="my-salt")
config.expand_all()
ir = {"configuration": {"system": {"host-name": "router1", "name-server": [{"name": "8.8.8.8"}]}}}
result = anonymize(ir, config)

Documentation

For full documentation, install the docs dependencies and run:

uv sync --group docs
uv run mkdocs serve

Then open http://127.0.0.1:8000.

Key sections:

  • Getting Started — Installation and usage examples
  • User Guide — Conversion, validation, and CLI reference
  • API Reference — Auto-generated Python API docs
  • Architecture — Design decisions and schema internals

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

junoscfg-0.5.6.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

junoscfg-0.5.6-py3-none-any.whl (2.2 MB view details)

Uploaded Python 3

File details

Details for the file junoscfg-0.5.6.tar.gz.

File metadata

  • Download URL: junoscfg-0.5.6.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for junoscfg-0.5.6.tar.gz
Algorithm Hash digest
SHA256 89a5dd407e6cb3d84c37f015508391569c782da46f7518aeafc8c7102803c099
MD5 12c8f6b8ce0d4c9fa5ddee64faf2a115
BLAKE2b-256 6e2d0a81510e35180f968fea64c21092930d1bea6ea414844675a04d0d9c3374

See more details on using hashes here.

File details

Details for the file junoscfg-0.5.6-py3-none-any.whl.

File metadata

  • Download URL: junoscfg-0.5.6-py3-none-any.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for junoscfg-0.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0b91de3741819c94b8a1638a26f0a4203ae0503c46191c17c1d95f0dedc76641
MD5 0044da5597d2d23a4d8a92bcbfbb97b2
BLAKE2b-256 3bcecee7a94f3617e8a1bd41ed2a998deebf7cacc3e2ef8e0f146bce296976af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page