Skip to content

Welcome to Pyvider CTY

A powerful and flexible type system for Python, compatible with HashiCorp's go-cty.

πŸ€– 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.

pyvider.cty is a pure-Python implementation of the go-cty type system, providing strong type validation and serialization capabilities for configuration data. It's designed to work seamlessly with Terraform providers and other HashiCorp ecosystem tools.


Why Pyvider CTY?

⚑ Expressive and Flexible

  • Rich Type System: A comprehensive set of primitive, collection, and structural types to model your data accurately.
  • Dynamic Types: Handle data with unknown or varying structures using the dynamic type.
  • Capsule Types: Encapsulate and protect foreign data types within the cty system.

πŸ› οΈ Developer Experience

  • Modern Python: Leverages Python 3.11+ features with complete type annotations.
  • Clear and Concise API: A simple and intuitive API for defining types, validating data, and working with values.
  • Detailed Diagnostics: Get detailed error messages and validation diagnostics to quickly identify and fix issues.

πŸ—οΈ Robust and Reliable

  • Immutable Values: cty values are immutable, ensuring data integrity and preventing unintended side effects.
  • Thoroughly Tested: A comprehensive test suite ensures the library is reliable and production-ready.
  • Battle-Tested Concepts: Based on the well-established cty type system from HashiCorp's Terraform.

πŸ”„ Cross-Language Compatibility

  • Go-Cty Interoperability: Serialize and deserialize data in MessagePack format compatible with go-cty.
  • Terraform Integration: Parse Terraform type strings and work with Terraform data structures.

Quick Example

from pyvider.cty import CtyObject, CtyString, CtyNumber, CtyList

# Define a type schema
user_type = CtyObject(
    attribute_types={
        "name": CtyString(),
        "age": CtyNumber(),
        "hobbies": CtyList(element_type=CtyString())
    },
    optional_attributes={"age"}
)

# Validate data
user_data = {
    "name": "Alice",
    "hobbies": ["reading", "hiking"]
}

user_val = user_type.validate(user_data)
print(f"Name: {user_val['name'].raw_value}")

Where to Start

  • Getting Started


    Install pyvider.cty and learn the basics in 5 minutes

  • User Guide


    Comprehensive guide to types, values, and advanced features

  • How-To Guides


    Practical guides for common tasks and use cases

  • API Reference


    Complete API documentation for all types and functions


Installation

# With uv (recommended)
uv add pyvider-cty

# With pip
pip install pyvider-cty

Features at a Glance

  • 🎯 Complete Type System: Primitives, collections, and structural types
  • πŸ”„ Cross-Language Compatibility: Interoperates with go-cty via MessagePack
  • πŸ›‘οΈ Type Safety: Strong validation at value creation
  • 🏷️ Marks System: Attach metadata without modifying values
  • πŸ—ΊοΈ Path Navigation: Type-safe access to nested data
  • ⚑ Full Standard Library: Comprehensive suite of functions for data manipulation

Community and Support


License

Apache License 2.0. See LICENSE for details.