pirrtools.structures package#
Submodules#
pirrtools.structures.attrdict module#
Enhanced dictionary with attribute-style access.
This module provides the AttrDict class, which extends the standard Python dictionary to allow accessing keys as attributes, making it more convenient for interactive use and structured data access.
- class pirrtools.structures.attrdict.AttrDict(*args, **kwargs)[source]#
Bases:
dict
Dictionary subclass that supports attribute-style access to keys.
This class extends the standard dict to allow accessing dictionary keys as attributes, providing a more convenient syntax for nested data structures. Nested dictionaries are automatically converted to AttrDict instances.
Attributes are created dynamically based on dictionary keys, and missing keys create new empty AttrDict instances when accessed.
Examples
>>> d = AttrDict({'a': 1, 'b': 2}) >>> d.a 1 >>> d.c.d = 'nested' # Creates nested structure >>> d.c.d 'nested'
>>> nested = AttrDict({'x': {'y': {'z': 42}}}) >>> nested.x.y.z 42
Note
Attribute names that conflict with dict methods (like ‘keys’, ‘items’) will still access the dict methods, not the stored values.
- __init__(*args, **kwargs)[source]#
Initialize AttrDict with automatic nested conversion.
- Parameters:
*args – Positional arguments passed to dict constructor.
**kwargs – Keyword arguments passed to dict constructor.
Note
Any nested dictionaries in the input are automatically converted to AttrDict instances for consistent attribute access.
- __getattr__(item)[source]#
Get dictionary value as attribute.
- Parameters:
item (str) – The attribute/key name to access.
- Returns:
The value associated with the key.
- Raises:
AttributeError – If the key doesn’t exist.
- __setattr__(key, value)[source]#
Set dictionary value as attribute.
- Parameters:
key (str) – The attribute/key name to set.
value – The value to associate with the key.
- __delattr__(item)[source]#
Delete dictionary key as attribute.
- Parameters:
item (str) – The attribute/key name to delete.
- Raises:
AttributeError – If the key doesn’t exist.
- __dir__()[source]#
Return list of available attributes (dictionary keys).
- Returns:
List of dictionary keys available as attributes.
- Return type:
pirrtools.structures.attrpath module#
Enhanced pathlib with attribute-based navigation and intelligent file viewing.
This module provides the AttrPath class, which extends pathlib.Path with attribute-based navigation capabilities and intelligent file viewing based on file extensions. Files and directories can be accessed as attributes, and various file types are automatically displayed with appropriate formatting.
- Key Features:
Attribute-based file and directory navigation
Automatic syntax highlighting for code files
Built-in viewers for common file formats (CSV, JSON, images, etc.)
Safe attribute names for files with special characters
Organized access to files by type and directory structure
Example
>>> path = AttrPath('/my/project')
>>> path.src.main_py.view # View main.py with syntax highlighting
>>> path.data.results_csv.view # View CSV as pandas DataFrame
>>> path.D.subdirectory # Access subdirectory
>>> path.py.script # Access script.py from .py extension group
- class pirrtools.structures.attrpath.AttrPath(*args, **kwargs)[source]#
Bases:
PosixPath
- static __new__(cls, *args, **kwargs)[source]#
Create new AttrPath instance with expanded user path (no resolve to avoid recursion).
Module contents#
Data structures module for pirrtools.
This module provides enhanced data structures including attribute-accessible dictionaries and path objects with convenient file system navigation.