pyATS Utilities Module

26.3 · active · verified Thu Apr 16

pyATS Utils is a core component of Cisco's pyATS framework, providing a collection of reusable utility functions for test automation, data manipulation, schema validation, and file operations. It's designed to support and extend the capabilities of pyATS and Genie, streamlining common tasks in network automation and testing. The current version is 26.3, and it follows a rapid release cadence, typically aligning with the broader pyATS ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define and use a simple schema for data validation using `pyats_utils.schema`. It shows how to import `Schema` and `validate`, define data structures with types and optional fields, and then validate sample data against the defined schema.

from pyats_utils.schema.api import validate
from pyats_utils.schema.base import Schema, Any, Optional

# Define a simple schema
my_schema = Schema({
    'name': str,
    'age': int,
    Optional('city'): str,
    'active': bool
})

# Data to validate
valid_data = {
    'name': 'Alice',
    'age': 30,
    'active': True
}

invalid_data = {
    'name': 'Bob',
    'age': 'twenty five', # Incorrect type
    'active': False
}

# Validate data
print("Validating valid_data...")
try:
    validated = validate(data=valid_data, schema=my_schema)
    print(f"Validation successful: {validated}")
except Exception as e:
    print(f"Validation failed: {e}")

print("\nValidating invalid_data...")
try:
    validated = validate(data=invalid_data, schema=my_schema)
    print(f"Validation successful: {validated}")
except Exception as e:
    print(f"Validation failed: {e}")

view raw JSON →