Net Schema
About this Project
Net Schema is a library that validates JSON and YAML documents against a defined schema, utilizing JSON Schema. This ensures that data adheres to specified formats and rules.
Additionally, this project is designed for schema validation of network-specific data, providing a range of network-related custom validators.
Installation
To install Net Schema:
pip install net-schema
uv add net-schema
Usage
Net Schema provides a CLI. You pass in the path to your documents, along with your schema path. Then Net Schema validates your data against the schema.
net-schema --help
Usage: net-schema [OPTIONS]
Validate a directory of YAML and JSON files against a schema.
Options:
-p, --document_path PATH Path to the documents directory [required]
-s, --schema PATH Path to the schema file [required]
-k, --check-dup-keys Check for duplicate keys in JSON or YAML documents
--help Show this message and exit.
Custom Validators
Net Schema provides various custom validators that can be used within your schema.
Usage
To utilize custom validators within your schema, provide the name of the validator as a key, and then provide True as its value.
Below is an example of using the vlan custom validator to ensure the vlans array consist of vlan values (i.e. integers between 1 and 4094).
type: object
properties:
vlans:
type: array
items:
vlan: True
ASN Validators
| Validator Name | Checks |
|---|---|
asn |
Validates whether the ASN is valid in general. |
asn_public |
Checks if the ASN is a public/global ASN. |
asn_private |
Determines if the ASN is a private ASN. |
asn_reserved |
Identifies if the ASN is reserved. |
asn_documentation |
Validates if the ASN is meant for documentation. |
asn_2byte |
Checks if the ASN falls within the 2-byte ASN range. |
asn_4byte |
Checks if the ASN falls within the 4-byte ASN range. |
asn_notation_dot |
Validates ASN format in dot notation. |
asn_notation_int |
Validates ASN format in integer notation. |
IP Validators
| Validator Name | Checks |
|---|---|
ip |
Validates if the instance is a valid IP address. |
ip_ipv4 |
Checks if the instance is a valid IPv4 address. |
ip_ipv6 |
Checks if the instance is a valid IPv6 address. |
ip_multicast |
Determines if the instance is a multicast IP address. |
ip_private |
Validates if the instance is a private IP address. |
ip_reserved |
Identifies if the instance is a reserved IP address. |
ip_linklocal |
Checks if the instance is a link-local IP address. |
ip_network |
Validates if the instance represents a valid IP network. |
VLAN Validators
| Validator Name | Checks |
|---|---|
vlan |
Validates if the instance is a valid VLAN ID (between 1 and 4094). |
vlan_standard |
Checks if the instance is a standard VLAN ID (between 1 and 1001). |
vlan_extended |
Determines if the instance is an extended VLAN ID (between 1006 and 4094). |
Example
document
interfaces:
- name: eth0
ip: 10.1.1.1
netmask: 255.255.255.0
- name: eth1
ip: 10.1.2.1
netmask: 255.255.255.0
- name: eth2
ip: 10.1.3.1
netmask: 255.255.255.0
- name: eth3
ip: 10.1.4.1000
netmask: 255.255.255.0
- name: eth4
ip: 10.1.5.1
netmask: 255.255.255.0
schema
type: object
properties:
interfaces:
type: array
items:
type: object
properties:
name:
type: string
pattern: '^eth[0-9]+$'
ip:
ip_ipv4: true
netmask:
type: string
pattern: '^255\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'
❯ net-schema --document_path examples/host_vars/ --schema examples/schema.yaml --check-dup-keys
───────────────────────────────────────────────────────────────────────────────────────────────────
Result Filename Location Msg
───────────────────────────────────────────────────────────────────────────────────────────────────
❌ examples/host_vars/rtr001.yml ['interfaces', 3, 'ip'] '10.1.4.1000' is not a 'ipv4'
✅ examples/host_vars/rtr002.yml -- --
✅ examples/host_vars/rtr003.yml -- --
Metadata
Release files for net-schema 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| net_schema-1.0.0.tar.gz | 12.5 kB | Without provenance | Details for net_schema-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| net_schema-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for net_schema-1.0.0-py3-none-any.whl |
Total release size: 25.6 kB
Release files / net_schema-1.0.0.tar.gz
| Download URL | net_schema-1.0.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a78aa0f6a07c1d017a84c3a922ef6d8106b8627b9c8dbd9c90136d3dd52735a
|
|
BLAKE2b-256 checksum How to use checksums |
5aba83e3bf633bc12e79654371aeddb2e403e48d58dc4f5f4393375975c253ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Release files / net_schema-1.0.0-py3-none-any.whl
| Download URL | net_schema-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c7fb34c45d7c53a73dc434a05e794c3c61931a95044871d9069f7e93a69827f
|
|
BLAKE2b-256 checksum How to use checksums |
fa41540aa634a30a71582aa8332d1f4be7ff93e9f60aa697cdc50917ee949462
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.6
|
Security for net-schema 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.