Skip to main content

TyConf - Modern Type-safe Configuration for Python 3.13+

Project description

TyConf

TyConfTyped Config - a type-safe configuration management library for Python with runtime validation.

What is TyConf?

TyConf is a modern Python 3.13+ library that makes managing application configuration simple, safe, and intuitive. It provides runtime type validation, value validation, read-only properties, and freeze/unfreeze capabilities to help you build robust applications.

Quick Start

from tyconf import TyConf
from tyconf.validators import range

# Create configuration with type-safe properties and validators
config = TyConf(
    host=(str, "localhost"),               # Mutable string
    debug=(bool, True),                    # Mutable boolean
    port=(int, 8080, range(1024, 65535)),  # Validated mutable range
    users=(list, ["admin", "root"], True)  # Immutable list
)

# Access values easily
print(config.host)       # 'localhost'
config.port = 3000       # Type-checked and range-validated automatically
config.port = "3000"     # Rises TypeError: Property 'port': expected int, got str
config.users = ["guest"] # Rises AttributeError: Property 'users' is read-only

Serialization

TyConf supports exporting and importing configurations in multiple formats:

from tyconf import TyConf

config = TyConf(
    host=(str, "localhost"),
    port=(int, 8080),
    debug=(bool, True)
)

# Export to JSON (with full metadata)
config.to_json('config.json')

# Export to JSON (values only)
config.to_json('values.json', values_only=True)

# Export to TOML (requires: pip install tyconf[toml])
config.to_toml('config.toml')

# Import from JSON
config = TyConf.from_json('config.json')

# Import from TOML (built-in via tomllib)
config = TyConf.from_toml('config.toml')

# Load from environment variables
config = TyConf.from_env(prefix='APP_', schema={
    'host': str,
    'port': int,
    'debug': bool
})

# Merge configurations
config.load_json('overrides.json')  # Merge JSON into existing config
config.load_env(prefix='APP_')      # Merge environment variables

Key Features

Type Safety - Runtime type validation with support for Optional and Union types
Value Validation - Built-in validators (range, length, regex, etc.) and custom validation functions
Read-Only Properties - Protect critical configuration from accidental changes
Freeze/Unfreeze - Lock entire configuration to prevent modifications
Serialization - Export/import configurations to JSON, TOML, and environment variables
Intuitive API - Both attribute (config.host) and dict-style (config['host']) access
Copy & Reset - Easily duplicate or restore default configurations
Zero Dependencies - Pure Python with no external requirements (TOML write requires optional dependency)

Installation

pip install tyconf

Requirements: Python 3.13+

Optional Dependencies:

# For TOML export support (TOML import is built-in via tomllib)
pip install tyconf[toml]

Documentation

Examples

See the examples/ directory for complete examples:

License

MIT License - see LICENSE for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Links

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

tyconf-1.2.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

tyconf-1.2.0-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file tyconf-1.2.0.tar.gz.

File metadata

  • Download URL: tyconf-1.2.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tyconf-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4cbe6c913852c59af3f4774f38999c87af7c738af11b992552642b372ae7e37c
MD5 b52cd9f61cdf7e7b3b131f3bdf639835
BLAKE2b-256 4646d5597192e03ec981c0dde83eb57183d03f176e33cb40a07e5f4102583da6

See more details on using hashes here.

File details

Details for the file tyconf-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: tyconf-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for tyconf-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 75a295e8ef2d51946cafd95f734cda3f1f0f6b30566b1780afa57b72d6f0ea7c
MD5 f99aefbee2664193f0c08ac78b773c39
BLAKE2b-256 33653b3d0e2572365955c140a5c78c597b24e03d1a1fabe0aa9a608d0c29c892

See more details on using hashes here.

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