Skip to main content

Configuration management for Python using Pydantic types and YAML config files

Project description

Coastline

A Python package for declarative configuration management using Pydantic types and YAML config files.

PyPI Version Python Versions License

See the full documentation at: Github Pages

Features

  • Type-safe configuration: Define your configuration schemas using Pydantic models with full validation
  • YAML integration: Load configuration from YAML files with automatic deserialization
  • Simple decorator API: Register configuration classes with the @config decorator
  • Flexible registry: Central registry for managing all your configuration classes
  • Python 3.11+: Built for modern Python with full type hint support

Installation

pip install coastline

Or using uv:

uv add coastline

Quick Start

Define your configuration schemas using Pydantic models and the @config decorator:

from coastline import config, ConfigLoader
from pydantic import BaseModel

@config
class Database(BaseModel):
    host: str
    port: int
    name: str

@config
class Cache(BaseModel):
    host: str
    port: int
    ttl: int = 300

Create a YAML configuration file:

Database:
  host: localhost
  port: 5432
  name: myapp

Cache:
  host: localhost
  port: 6379

Load and use your configuration:

loader = ConfigLoader()
config = loader.load("config.yaml")

# Access typed configuration objects
db = config["Database"]
print(f"Connecting to {db.host}:{db.port}")

Usage

The @config Decorator

The @config decorator registers your Pydantic model with the global configuration registry.

from coastline import config
from pydantic import BaseModel

# Basic usage - uses class name as registry key
@config
class Database(BaseModel):
    host: str
    port: int

# With parentheses - also works
@config()
class Cache(BaseModel):
    host: str
    port: int

# Custom name for the config key
@config(name="app-settings")
class Settings(BaseModel):
    debug: bool
    log_level: str

ConfigLoader

The ConfigLoader class loads YAML files and instantiates registered configurations.

from coastline import ConfigLoader

loader = ConfigLoader()
config = loader.load("config.yaml")

# Access specific config
database = config["Database"]
print(database.host)

# Check if config exists
if "Cache" in config:
    cache = config["Cache"]

Registry

The Registry provides programmatic access to registered configuration classes:

from coastline import Registry

registry = Registry.get_instance()

# List all registered configs
print(registry.list())  # ['Database', 'Cache', 'Settings']

# Get a registered class
cls = registry.get("Database")
instance = cls(host="localhost", port=5432, name="test")

# Clear all registrations
registry.clear()

Example Project Structure

myproject/
├── config.yaml
├── pyproject.toml
└── myapp/
    ├── __init__.py
    └── config.py
# myapp/config.py
from coastline import config, ConfigLoader
from pydantic import BaseModel

@config
class Database(BaseModel):
    host: str
    port: int
    name: str
    user: str
    password: str

@config
class AppConfig(BaseModel):
    debug: bool = False
    log_level: str = "INFO"

@config
class RedisConfig(BaseModel):
    host: str
    port: int
    db: int = 0
# config.yaml
Database:
  host: localhost
  port: 5432
  name: myapp
  user: admin
  password: secret

AppConfig:
  debug: true
  log_level: DEBUG

RedisConfig:
  host: localhost
  port: 6379
# myapp/__init__.py
from coastline import ConfigLoader

_loader = ConfigLoader()
_loader.load("config.yaml")

def get_config(name: str):
    return _loader.get(name)

Requirements

  • Python 3.11 or higher
  • pydantic >= 2.12.5
  • pyyaml >= 6.0.3

Development

# Install dependencies
uv sync

# Install dev dependencies
uv sync --group dev

# Run tests
uv run pytest

# Run linting
uv run ruff check .

# Build package
uv run python -m build

License

MIT License - see LICENSE file for details.

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

coastline-0.2.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

coastline-0.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file coastline-0.2.0.tar.gz.

File metadata

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

File hashes

Hashes for coastline-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d0a3725a29f6a4bb89c150752fd13cafac9e8d55d62addc18af9660f2c8dab22
MD5 92fffcc6718825434297da215e2ce600
BLAKE2b-256 f2da341a292e44658765bc2408865d1e04514222676f110c2cfdf622292b7565

See more details on using hashes here.

Provenance

The following attestation bundles were made for coastline-0.2.0.tar.gz:

Publisher: release.yml on CaspianDataLabs/Coastline

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

File details

Details for the file coastline-0.2.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for coastline-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ccf269094d25f3ec600d2f459c4d2608dbe707ce3c5f7a8ae724e83b18d6c78
MD5 8003a5abba5327bdb1927dc768aa5f0a
BLAKE2b-256 3584b7edce8f862016971e103abf7a0b13d4fd5bdf7c5bea08f7d5d3c54ac0c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for coastline-0.2.0-py3-none-any.whl:

Publisher: release.yml on CaspianDataLabs/Coastline

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