Skip to main content

Pyvider Cty Package - Core data types and serialization.

Project description

🐍🏗️ pyvider.cty

⚠️ PREVIEW RELEASE ⚠️

This is a preview release of pyvider.cty. While the core functionality is complete and well-tested, this release is intended for early adopters and feedback gathering. Please report any issues or suggestions.

Overview

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.

Features

  • 🎯 Complete Type System: Primitives, collections, and structural types.
  • 🔄 Cross-Language Compatibility: Interoperates with go-cty via JSON and 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: A comprehensive suite of functions for data manipulation.

Installation

uv add pyvider-cty

Quick Start

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

# 1. Define a type schema for a user profile.
# 'age' is an optional attribute.
user_type = CtyObject(
    attribute_types={
        "name": CtyString(),
        "age": CtyNumber(),
        "hobbies": CtyList(element_type=CtyString())
    },
    optional_attributes={"age"}
)

# 2. Create raw Python data that matches the schema.
user_data = {
    "name": "Alice",
    "hobbies": ["reading", "hiking"]
}

# 3. Validate the data. This returns an immutable CtyValue.
try:
    user_val = user_type.validate(user_data)
    print("✅ Validation successful!")

    # 4. Access data from the CtyValue.
    # Accessing attributes returns another CtyValue. Use .raw_value to get the Python type.
    print(f"Name: {user_val['name'].raw_value}")

    # The optional 'age' attribute is present but is a null CtyValue.
    print(f"Age: {user_val['age'].raw_value} (Is Null: {user_val['age'].is_null})")

    print("Hobbies:")
    for hobby_val in user_val['hobbies']:
        print(f"- {hobby_val.raw_value}")

except CtyValidationError as e:
    print(f"❌ Validation failed: {e}")

Documentation

The complete user guide can be found in the docs/ directory, starting with the index.

Known Limitations

  • Python 3.13+ Required: Due to advanced type features used.
  • Performance: The library is not yet optimized for performance-critical applications involving very large or deeply nested data structures. Performance is reasonable for typical use cases.

Contributing

We welcome contributions! Please see our Contributing Guidelines for details.

License

Apache License 2.0. See LICENSE for details.

CI Test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvider_cty-0.0.116.tar.gz (60.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvider_cty-0.0.116-py3-none-any.whl (80.9 kB view details)

Uploaded Python 3

File details

Details for the file pyvider_cty-0.0.116.tar.gz.

File metadata

  • Download URL: pyvider_cty-0.0.116.tar.gz
  • Upload date:
  • Size: 60.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyvider_cty-0.0.116.tar.gz
Algorithm Hash digest
SHA256 ae405aeaf9a4c4297f8388e675615f0cb04ee5194818ea17003021372f37c418
MD5 2bfa1324e327cfad7f2eab05dd12a96e
BLAKE2b-256 4e84d4c9c14250255de72aec0f5f251189af06c22822a563e3586d6f316e5e01

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvider_cty-0.0.116.tar.gz:

Publisher: release.yml on provide-io/pyvider-cty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvider_cty-0.0.116-py3-none-any.whl.

File metadata

  • Download URL: pyvider_cty-0.0.116-py3-none-any.whl
  • Upload date:
  • Size: 80.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyvider_cty-0.0.116-py3-none-any.whl
Algorithm Hash digest
SHA256 f6930ad4bfa378804c44e082b5287ac0c9471ed597cf5064c337c7cf9b63499f
MD5 d3e7d8ff00233db387967120ac26e862
BLAKE2b-256 6b1888b265b3621763de1d67b23cb048d80b93bc7f9f09eed3f940b25e4d022f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvider_cty-0.0.116-py3-none-any.whl:

Publisher: release.yml on provide-io/pyvider-cty

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page