A type-safe python configuration library
Project description
Canopee is a production-ready configuration library that treats Python as the ultimate config DSL.
Built on top of Pydantic v2, it removes the brittleness of YAMLs, silent mutation footguns, and metaclass magic, giving you IDE autocomplete, instant validation, and elegant hyperparameter sweeping out of the box.
🌟 Why Canopee?
- Always Valid: Configs are validated precisely at construction. No runtime surprises.
- Immutable:
ConfigBaseobjects arefrozen=True. They can be hashed, cached, and safely passed across threads. - Type-Safe Evolution: Evolve new variants purely with Python keywords via the
.evolve(**kwargs)method. - First-Class Sweeps: Define hyperparameter search spaces directly over your types, using strategies like grid, random, or optuna.
- Symmetric I/O: Naturally save and load instances via
.toml,.yaml, or.jsonextensions natively, or inject CLI/Env overrides securely.
🚀 Quickstart
Installation
pip install canopee
Basic Usage
Subclass ConfigBase as you would any Pydantic model.
from canopee import ConfigBase
from pydantic import computed_field
class TrainingConfig(ConfigBase):
learning_rate: float = 1e-3
epochs: int = 20
batch_size: int = 128
@computed_field
@property
def total_steps(self) -> int:
return self.epochs * (10_000 // self.batch_size)
# 1. Instantiate (validated instantly)
cfg = TrainingConfig()
# 2. Evolve (returns a new modified frozen instance, IDE autocomplete works perfectly!)
fast_cfg = cfg.evolve(epochs=5, learning_rate=5e-3)
# Computed fields naturally update based on the new instance values
print(fast_cfg.total_steps)
# 3. Save it to disk (JSON, TOML, YAML supported out-of-the-box)
fast_cfg.save("experiment.toml")
Sweeps
Native support for generating massive, reproducible configuration variants.
from canopee.sweep import Sweep, log_uniform, choice
def train(cfg: TrainingConfig) -> float:
# return accuracy metric here
return 0.95
best_cfg = (
Sweep(TrainingConfig())
.vary("learning_rate", log_uniform(1e-5, 1e-1))
.vary("batch_size", choice(32, 64, 128))
.strategy("random", n_samples=20, seed=42)
.run(train)
.best(minimize=False)
)
📖 Documentation
The full documentation—including Guides on advanced ConfigStore registries and cli/env Source merging—can be generated by running:
uv run zensical serve
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file canopee-0.0.2.tar.gz.
File metadata
- Download URL: canopee-0.0.2.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9baa645debe2c2c1ca98e791285ffa0ebecb75ae9796c4f051f9ee7b147154ac
|
|
| MD5 |
df397728ee553539e8c76bccdb90f8f8
|
|
| BLAKE2b-256 |
e266d8cfbcfcc72c4f4f27737984242b191285fe246f4494031c3aeaa4e81b49
|
File details
Details for the file canopee-0.0.2-py3-none-any.whl.
File metadata
- Download URL: canopee-0.0.2-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e65976538d5a613c4f911be68b4f6d3a9118d362da01c6dd32a5dc44110c7ee
|
|
| MD5 |
f5a28331e83a6412d3697858e602e4c8
|
|
| BLAKE2b-256 |
55302b491687a07eac180f270adb0742baa735f18308111a47c9eda3cd8cfb19
|