{"id":7540,"library":"pyats-datastructures","title":"pyATS Datastructures","description":"pyATS Datastructures provides extended data structures designed to enhance network automation and testing workflows. It offers specialized objects like `DataObject`, `DataList`, `DataDict`, and `MetaData` that allow for attribute-based access, schema validation, and meta-data handling, often used within the Cisco pyATS framework for managing configuration and state data. The current version is 26.3, and it follows the pyATS release cadence, typically releasing new versions quarterly or as needed with the main pyATS framework.","status":"active","version":"26.3","language":"en","source_language":"en","source_url":"https://github.com/Cisco-pyats/pyats.datastructures","tags":["networking","data structures","pyats","cisco","automation","testing"],"install":[{"cmd":"pip install pyats-datastructures","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"YAML serialization/deserialization.","package":"pyyaml"},{"reason":"Schema validation and model definition.","package":"schematics"},{"reason":"String differencing capabilities.","package":"diff_match_patch"},{"reason":"Cross-platform colored terminal output.","package":"colorama"},{"reason":"Templating for string processing.","package":"jinja2"},{"reason":"Core utility functions from the pyATS framework.","package":"pyats.utils"}],"imports":[{"symbol":"DataObject","correct":"from pyats.datastructures import DataObject"},{"symbol":"DataList","correct":"from pyats.datastructures import DataList"},{"symbol":"DataDict","correct":"from pyats.datastructures import DataDict"},{"symbol":"And","correct":"from pyats.datastructures.logic import And"}],"quickstart":{"code":"from pyats.datastructures import DataObject\n\n# Create a DataObject\ndata = DataObject()\n\n# Assign attributes like a regular object\ndata.attr = 'value'\ndata.attr_2 = 123\ndata.nested = DataObject()\ndata.nested.item = 'nested_value'\n\n# Access attributes\nprint(f\"data.attr: {data.attr}\")\nprint(f\"data.nested.item: {data.nested.item}\")\n\n# Convert to a standard Python dictionary\nplain_dict = data.to_dict()\nprint(f\"Converted to dict: {plain_dict}\")\n\nassert plain_dict == {'attr': 'value', 'attr_2': 123, 'nested': {'item': 'nested_value'}}","lang":"python","description":"This quickstart demonstrates how to create and interact with a `DataObject`, assigning attributes and converting it to a standard Python dictionary. `DataObject` provides attribute-style access and allows for nesting other `DataObject` instances."},"warnings":[{"fix":"To perform iterable operations or convert to a native Python type, use specific methods like `DataObject.to_dict()` or `DataList.to_list()`. Interact with `DataDict` or `DataList` objects embedded within the `DataObject` for their respective operations.","message":"While `DataObject` provides dictionary-like and attribute-like access, it does not inherit directly from `dict` or `list`. Direct use of standard dictionary/list methods like `.keys()`, `.items()`, or `.append()` on a `DataObject` instance itself will result in an `AttributeError` (unless explicitly implemented or if it contains a `DataDict`/`DataList` instance).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this implicit conversion. If you require a strictly plain `dict` or `list` nested within, you may need to convert it back explicitly or manage it outside the `DataObject` context. Alternatively, embrace the `DataDict`/`DataList` behavior for enhanced features.","message":"When assigning a plain Python `dict` or `list` to an attribute of a `DataObject`, `pyats-datastructures` will implicitly convert them into `DataDict` or `DataList` instances. While this offers convenience, it means subsequent operations on these nested structures will follow `DataDict`/`DataList` rules, not standard `dict`/`list` behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"If you need a dictionary representation to iterate over its keys or items, convert the `DataObject` to a native Python dictionary first: `data.to_dict().keys()` or `data.to_dict().items()`.","cause":"Attempting to use standard dictionary methods like `keys()`, `items()`, or `values()` directly on a `DataObject` instance, which is not a `dict` subclass.","error":"AttributeError: 'DataObject' object has no attribute 'keys'"},{"fix":"Correct the import statement to use the plural form: `from pyats.datastructures import DataObject`.","cause":"Typo in the package name during import. The correct package name is `pyats.datastructures` (plural 's').","error":"ModuleNotFoundError: No module named 'pyats.datastructure'"}]}