API Reference¶
Welcome to the complete API reference for pyvider.cty. This section provides detailed documentation for all public classes, functions, and modules in the library.
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
Module Organization¶
The pyvider.cty API is organized into the following modules:
Core Modules¶
- Types - Type system implementation (primitives, collections, structural, capsule)
- Primitive Types -
CtyString,CtyNumber,CtyBool - Collection Types -
CtyList,CtyMap,CtySet - Structural Types -
CtyObject,CtyTuple,CtyDynamic -
Capsule Types -
CtyCapsule,CtyCapsuleWithOps -
Values -
CtyValueclass for immutable, type-safe data instances -
Conversion - Type conversion and unification functions
convert(value, target_type)- Convert between typesunify(types)- Find the most specific common type
Serialization & Encoding¶
- Codec - MessagePack serialization for cross-language compatibility
cty_to_msgpack()- Serialize to binary format-
cty_from_msgpack()- Deserialize from binary format -
Functions - Standard library of built-in functions
- String manipulation, numeric operations, collection functions
- Type conversions, encoding/decoding, date/time operations
Advanced Features¶
- Path Navigation - Navigate nested structures with
CtyPath -
GetAttrStep,IndexStep,KeyStep -
Parser - Terraform type string parsing
parse_tf_type_to_ctytype()- Parse Terraform type specifications-
parse_type_string_to_ctytype()- Alias for backward compatibility -
Validation - Recursion detection and validation utilities
- Recursion context management
-
Cycle detection decorators
-
Context - Validation depth tracking
- Context-local state management
- Depth limit protection
Quick Reference¶
Importing Types¶
from pyvider.cty import (
CtyString, CtyNumber, CtyBool, # Primitives
CtyList, CtyMap, CtySet, # Collections
CtyObject, CtyTuple, CtyDynamic, # Structural
CtyCapsule, CtyCapsuleWithOps, # Capsule
CtyType, CtyValue, # Base classes
)
Importing Utilities¶
from pyvider.cty import convert, unify # Conversion
from pyvider.cty import CtyMark # Marks
from pyvider.cty.codec import ( # Serialization
cty_to_msgpack, cty_from_msgpack
)
from pyvider.cty.functions import ( # Functions
jsonencode, jsondecode,
upper, lower, concat,
# ... and many more
)
Importing Exceptions¶
from pyvider.cty import (
CtyValidationError, # General validation
CtyConversionError, # Type conversion
CtyAttributeValidationError, # Object attributes
CtyListValidationError, # List validation
CtyMapValidationError, # Map validation
CtySetValidationError, # Set validation
CtyTupleValidationError, # Tuple validation
CtyTypeMismatchError, # Type mismatches
CtyTypeParseError, # Type string parsing
)
Documentation Notes¶
- Auto-generated sections: Some API sections are auto-generated from source code docstrings
- Type hints: All functions include complete type annotations
- Examples: Most API functions include usage examples
- Related guides: Each API section links to related user guide chapters
Additional Resources¶
- User Guide - Comprehensive feature documentation
- How-To Guides - Task-oriented guides
- Getting Started - Quick introduction
- Examples - Runnable code examples
PyVider CTY API¶
pyvider.cty
¶
Attributes¶
BytesCapsule
module-attribute
¶
A capsule type for wrapping raw bytes.
Classes¶
CtyConversionError
¶
CtyConversionError(
message: str,
*,
source_value: object | None = None,
target_type: object | None = None,
**kwargs: Any,
)
Bases: CtyError
Base for CTY value or type conversion errors.
Initializes the CtyConversionError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The base error message. |
required |
source_value
|
object | None
|
The value that was being converted. |
None
|
target_type
|
object | None
|
The intended target type of the conversion. |
None
|
**kwargs
|
Any
|
Additional foundation error context. |
{}
|
Source code in pyvider/cty/exceptions/conversion.py
Functions¶
CtyTypeParseError
¶
Bases: CtyConversionError
Raised when a CTY type string cannot be parsed.
Source code in pyvider/cty/exceptions/conversion.py
CtyValidationError
¶
CtyValidationError(
message: str,
value: object = None,
type_name: str | None = None,
path: CtyPath | None = None,
**kwargs: Any,
)
Bases: ValidationError
Base exception for all validation errors.
Inherits from foundation's ValidationError for enhanced diagnostics and automatic retry/circuit breaker support where applicable.
Source code in pyvider/cty/exceptions/validation.py
CtyMark
¶
Represents a mark that can be applied to a cty.Value. The 'details' attribute is automatically converted to a hashable frozenset.
CtyCapsule
¶
Represents a capsule type in the Cty type system. Capsule types are opaque types that can be used to wrap arbitrary Python objects.
Source code in pyvider/cty/types/capsule.py
CtyCapsuleWithOps
¶
CtyCapsuleWithOps(
capsule_name: str,
py_type: type,
*,
equal_fn: Callable[[Any, Any], bool] | None = None,
hash_fn: Callable[[Any], int] | None = None,
convert_fn: Callable[
[Any, CtyType[Any]], CtyValue[Any] | None
]
| None = None,
)
Bases: CtyCapsule
A CtyCapsule that supports custom operations like equality, hashing, and conversion.
Initializes a CtyCapsule with custom operational functions.
Source code in pyvider/cty/types/capsule.py
Functions¶
CtyDynamic
¶
Represents a dynamic type that can hold any CtyValue.
Functions¶
validate
¶
Validates a raw Python value for a dynamic type. The result is always a CtyValue of type CtyDynamic, which wraps the inferred concrete value.
Source code in pyvider/cty/types/structural/dynamic.py
CtyType
¶
Bases: CtyTypeProtocol[T], Generic[T], ABC
Generic abstract base class for all Cty types.
Functions¶
convert
¶
Converts a CtyValue to a new CtyValue of the target CtyType.
Source code in pyvider/cty/conversion/explicit.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
unify
¶
Finds a single common CtyType that all of the given types can convert to. This is a wrapper that enables caching by converting input to a frozenset.
Source code in pyvider/cty/conversion/explicit.py
parse_tf_type_to_ctytype
¶
Parses a Terraform type constraint, represented as a raw Python object (typically from JSON), into a CtyType instance.