Schema Types Reference¶
This guide provides a complete reference of all attribute types available in Pyvider's schema system.
🤖 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.
Type Categories¶
Pyvider provides three categories of types:
- Simple Types: String (
a_str), Number (a_num), Boolean (a_bool), Dynamic (a_dyn) - Collection Types: List (
a_list), Map (a_map), Set (a_set), Tuple (a_tuple) - Complex Types: Object (
a_obj)
Simple Types¶
String - a_str()¶
Text values.
| Python | |
|---|---|
Terraform: name = "my-server"
Number - a_num()¶
Numeric values (integers or floats).
| Python | |
|---|---|
Terraform: port = 443
Boolean - a_bool()¶
True/false values.
| Python | |
|---|---|
Terraform: enabled = true
Dynamic - a_dyn()¶
Accepts any type. Use sparingly.
Terraform: metadata = "string" or metadata = {key = "value"}
Null - a_null()¶
Explicitly represents a null value.
| Python | |
|---|---|
Use Cases: - Representing optional fields that can be explicitly set to null - Schema placeholders - Conditional nullability in complex schemas
Terraform: Not commonly used in HCL configurations - most often used internally.
Note: In most cases, you should use optional=True on regular attributes rather than a_null().
Unknown - a_unknown()¶
Represents values that are unknown during planning phase.
| Python | |
|---|---|
Use Cases: - Values computed during apply that can't be known during plan - Handling Terraform's unknown value semantics - Advanced provider scenarios with deferred computation
Terraform: Terraform internally represents these as unknown values during the plan phase.
Note: This is an advanced type primarily used for complex provider scenarios. Most computed values should use a_str(computed=True) or similar instead.
Collection Types¶
List - a_list(element_type)¶
Ordered collection of same-typed elements.
| Python | |
|---|---|
Terraform:
Map - a_map(value_type)¶
Key-value pairs (keys are strings).
| Python | |
|---|---|
Terraform:
| Terraform | |
|---|---|
Set - a_set(element_type)¶
Unordered, unique elements.
| Python | |
|---|---|
Terraform:
| Terraform | |
|---|---|
Tuple - a_tuple([type1, type2, ...])¶
Fixed-length, mixed-type collection.
| Python | |
|---|---|
Terraform:
Complex Types¶
Object - a_obj({...})¶
Structured data with typed fields.
Terraform:
| Terraform | |
|---|---|
Type Composition Examples¶
List of Maps¶
| Python | |
|---|---|
| Terraform | |
|---|---|
Map of Lists¶
| Python | |
|---|---|
List of Objects¶
| Python | |
|---|---|
Type Mapping Reference¶
| Pyvider Function | Python Type | Terraform Type | Example |
|---|---|---|---|
a_str() |
str |
string |
"hello" |
a_num() |
int \| float |
number |
42 |
a_bool() |
bool |
bool |
true |
a_list(T) |
list[T] |
list(T) |
["a", "b"] |
a_map(T) |
dict[str, T] |
map(T) |
{k = "v"} |
a_set(T) |
set[T] |
set(T) |
["a"] |
a_tuple([T...]) |
tuple |
tuple([T...]) |
["a", 1] |
a_obj({...}) |
dict |
object({...}) |
{k = "v"} |
a_dyn() |
Any |
dynamic |
any |
a_null() |
None |
null |
null |
a_unknown() |
N/A | unknown |
(plan-time) |
Choosing the Right Type¶
Use String for: Names, IDs, URLs, text, enums Use Number for: Counts, ports, timeouts, sizes, percentages Use Boolean for: Flags, toggles, conditions Use List for: Ordered collections, duplicates OK Use Map for: Key-value lookups, labels, config dicts Use Set for: Unique values, order doesn't matter Use Object for: Structured config, multiple related fields Use Dynamic for: Truly arbitrary data (use sparingly!)
Best Practices¶
Be Specific¶
Use Appropriate Collections¶
| Python | |
|---|---|
Structure with Objects¶
| Python | |
|---|---|
Provide Defaults¶
| Python | |
|---|---|
Related Documentation¶
- Overview - Schema system introduction
- Attributes - Attribute options
- Validators - Custom validation
- Best Practices - Design guidelines
Remember: Choose the most specific type for your data. This provides better validation and user experience.