Metadata-Version: 2.5
Name: nac-yaml
Version: 2.1.0
Summary: A Python library with common YAML utility functions supporting 'Network as Code'.
Project-URL: homepage, https://github.com/netascode/nac-yaml
Project-URL: repository, https://github.com/netascode/nac-yaml
Project-URL: documentation, https://github.com/netascode/nac-yaml
Author-email: Daniel Schmidt <danischm@cisco.com>
Maintainer-email: Daniel Schmidt <danischm@cisco.com>
License: MPL-2.0
License-File: LICENSE
Keywords: automation,cisco,network,utilities,yaml
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: ruamel-yaml>=0.18.15
Provides-Extra: dev
Requires-Dist: ansible-core>=2.17.6; (sys_platform != 'win32' and python_version < '3.12') and extra == 'dev'
Requires-Dist: ansible-core>=2.20.0; (sys_platform != 'win32' and python_version >= '3.12') and extra == 'dev'
Requires-Dist: bandit[toml]>=1.9.1; extra == 'dev'
Requires-Dist: pre-commit>=4.4.0; extra == 'dev'
Requires-Dist: pytest-cov>=7.0.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.15.1; extra == 'dev'
Requires-Dist: pytest>=9.0.1; extra == 'dev'
Requires-Dist: ruff>=0.14.5; extra == 'dev'
Requires-Dist: ty>=0.0.78; extra == 'dev'
Provides-Extra: vault
Requires-Dist: ansible-core>=2.17.6; (sys_platform != 'win32' and python_version < '3.12') and extra == 'vault'
Requires-Dist: ansible-core>=2.20.0; (sys_platform != 'win32' and python_version >= '3.12') and extra == 'vault'
Description-Content-Type: text/markdown

[![Tests](https://github.com/netascode/nac-yaml/actions/workflows/test.yml/badge.svg)](https://github.com/netascode/nac-yaml/actions/workflows/test.yml)
![Python Support](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-informational "Python Support: 3.10, 3.11, 3.12, 3.13, 3.14")

# nac-yaml

A Python library with common YAML utility functions supporting `Network as Code`.

## Usage

### Load and merge YAML files

```python
from pathlib import Path
from nac_yaml.yaml import load_yaml_files

# Default is ruamel's round-trip loader (preserves formatting internally).
data = load_yaml_files([
    Path("path/to/file1.yaml"),
    Path("path/to/file2.yaml"),
])

# Use the safe loader to get native dict/list containers.
data_safe = load_yaml_files([
    Path("path/to/file1.yaml"),
    Path("path/to/file2.yaml"),
], typ="safe")
```

Note: when `typ` is not round-trip (e.g. `"safe"`), formatting features (quotes/comments/style) are not preserved.

### Ansible Vault encrypted values

Values encrypted with [Ansible Vault](https://docs.ansible.com/ansible/latest/vault_guide/index.html) can be used with the `!vault` tag:

```yaml
password: !vault |
  $ANSIBLE_VAULT;1.2;AES256;dev
  6535616566336139303566666336633163663431306337356461633439626638...
```

The vault password is read from the `ANSIBLE_VAULT_PASSWORD` environment variable, `ANSIBLE_VAULT_ID` is optional:

```bash
export ANSIBLE_VAULT_ID=dev
export ANSIBLE_VAULT_PASSWORD=Password123
```

Decryption requires `ansible-core`, either installed in the same Python environment (`pip install nac-yaml[vault]`) or available as `ansible-vault` command on `PATH`. All values are decrypted in a single batch after parsing. If a value cannot be decrypted, `load_yaml_files()` raises a `VaultError` for explicitly provided files, while files found in directories are skipped with a warning. Ansible Vault is not supported on Windows.

## Installation

### Using uv (recommended)

```bash
uv add nac-yaml
```

### Using pip

```bash
pip install nac-yaml
```
