Skip to main content

vcti-config

Type-safe environment variable decoding and configuration resolution for Python.

Overview

VCollab applications take their configuration from several places: environment variables, values the application already holds, and defaults. Without a shared layer every package reinvents how a setting is named in each place, which place wins, and how problems are reported.

vcti-config separates what an application needs from where the values come from. A model is a Config subclass, a frozen pydantic model that states field names, types and constraints. A resolver knows one source: Env reads environment variables, Values holds values supplied by code. Resolvers are applied in priority order to a draft, each filling only what is still missing, and build() returns the validated config or reports every problem at once.

A model can contain other models: sections that are always present, and one_of choices where one setting selects which of several shapes is built (an LLM adapter, a deployment target).


Installation

pip install vcti-config

In requirements.txt

vcti-config>=5.0.1

In pyproject.toml dependencies

dependencies = [
    "vcti-config>=5.0.1",
]

Quick Start

Declare a model and resolve it from the environment

from pathlib import Path

from vcti.config import Config, Env, Field

class AppConfig(Config):
    debug: bool = False
    port: int = Field(default=8080, ge=1, le=65535)
    name: str = "myapp"
    data_dir: Path | None = None

config = AppConfig.resolve(Env(prefix="MYAPP_")).build()   # reads os.environ
config.debug   # bool, from MYAPP_DEBUG
config.port    # int,  from MYAPP_PORT
config.name    # str,  from MYAPP_NAME

A field with no default is required. The prefix belongs to the resolver, not to the model, and is used exactly as written: a field's variable is the prefix followed by the upper-cased field name, so the prefix includes its own underscore.

Combine sources in priority order

Resolvers are listed highest priority first. Each fills only what the ones before it left missing; defaults apply last.

from vcti.config import Values

env = {"MYAPP_PORT": "8081", "MYAPP_DEBUG": "true"}   # stands in for os.environ

draft = AppConfig.resolve(
    Values({"port": 9000}),                           # values the code already has
    Env(prefix="MYAPP_", source=env),
)
config = draft.build()
config.port        # 9000, from Values
config.debug       # True, from MYAPP_DEBUG
draft.sources()    # {"debug": "env", "port": "values", "name": "default", ...}

Values is how a test forces a setting, and how an application passes on what its own command-line parser produced. source is anything with get(name) -> str | None, so os.environ and a plain dict both work.

Handle all errors at once

from vcti.config import ConfigErrors

class StrictConfig(Config):
    host: str
    port: int = Field(ge=1, le=65535)

try:
    StrictConfig.resolve(Env(prefix="STRICT_", source={"STRICT_PORT": "70000"})).build()
except ConfigErrors as exc:
    for err in exc.errors:        # every problem, each with its source
        print(err)
# 'host' has no value and no default (looked for: env STRICT_HOST).
# 'port': Input should be less than or equal to 65535 ('70000' from env STRICT_PORT).

Compose models: sections and one_of

from enum import StrEnum
from typing import ClassVar

from vcti.config import SecretStr, one_of

class Adapter(StrEnum):
    CLAUDE_CODE = "claude-code"
    OPENAI = "openai"

class ClaudeCodeConfig(Config):
    KIND: ClassVar[Adapter] = Adapter.CLAUDE_CODE     # → MYAPP_CLAUDE_CODE__*
    model: str = "sonnet"

class OpenAiConfig(Config):
    KIND: ClassVar[Adapter] = Adapter.OPENAI          # → MYAPP_OPENAI__*
    api_key: SecretStr                                # masked on display
    model: str = "gpt-4o-mini"

class StorageConfig(Config):
    cache_dir: Path

class ServiceConfig(Config):
    storage: StorageConfig                            # a section → MYAPP_STORAGE__*
    adapter: ClaudeCodeConfig | OpenAiConfig = one_of(default_kind=Adapter.CLAUDE_CODE)

env = {
    "MYAPP_STORAGE__CACHE_DIR": "/var/cache",
    "MYAPP_ADAPTER": "OPENAI",                        # selects the branch
    "MYAPP_OPENAI__API_KEY": "sk-example",
}
config = ServiceConfig.resolve(Env(prefix="MYAPP_", source=env)).build()
config.storage.cache_dir     # Path
config.adapter.api_key       # SecretStr('**********')
config.adapter.KIND          # Adapter.OPENAI
  • A section is a field annotated with another Config class.
  • A one_of is a field annotated with a union of Config classes that each declare KIND. Its selector is read from the variable named for the field (MYAPP_ADAPTER) and matched against the enum's member names; only the selected branch is built, so an unset required field in another branch is not an error. one_of(default_kind=...) is optional and names the branch used when nothing selects one.
  • Use isinstance or match on config.adapter to branch on the choice.

Construct a config directly

A model is an ordinary pydantic model, so a test that knows every value needs no resolver:

config = AppConfig(port=9000, name="test")

Decode, read and resolve standalone

from vcti.config import MISSING, decode_int, get_str, resolve_value

decode_int("8080")                                # 8080
raw = get_str({"PORT": " 8081 "}, "PORT")         # "8081"; None if unset or blank
port = resolve_value(MISSING if raw is None else decode_int(raw), default=8080)

# MISSING, not None, is the skip sentinel, so None is a real value:
resolve_value(MISSING, "env", default="x")        # "env"
resolve_value(None, "env", default="x")           # None

Resolvers

Resolver Source Notes
Env(prefix, ...) Environment variables, or any ConfigSource Strings; pydantic converts them on build()
Values(mapping) Values held in code Flat path keys or nested mappings; None is a real value

Env options:

Option Purpose
source Where to read from; defaults to os.environ
separator Joins nested names; defaults to __
aliases Extra variable names for a path: {"LEGACY_PORT": "port"}
exclude Paths that must not be supplied from this source
parsers Custom string parsers by type: {list[str]: split_commas}
path_parsers Custom string parsers for single paths: {"tags": split_commas}. Wins over a parser for the type
unknown Whether a variable that starts with the prefix and matches no field is an "error" (the default with a prefix) or "ignore"d

What Env does to a raw string before pydantic sees it:

  • A blank value counts as unset.
  • A list[...] or dict[...] field is parsed as JSON.
  • A one_of's selector is decoded to its enum member, by member name, or with the enum's vcti-enum coder if it has one.
  • A bool field accepts the spellings below, case-insensitively.
True False
1, true, yes, on, enabled, t, y 0, false, no, off, disabled, f, n

Public API

Name Purpose
Config Base class for a model; Config.resolve(*resolvers) starts a draft
Field, SecretStr pydantic's own, re-exported
one_of Declares the default branch of a one_of field
Draft A config being resolved: resolve, get, sources, build
Env, Values The shipped resolvers
Resolver The protocol a custom resolver implements
SchemaEntry, Invalid What a custom resolver reads and may store
ConfigSource, get_str A look-up-by-name source, and a stripped read from one
resolve_value, MISSING Standalone priority resolution and its "no value" sentinel
decode_bool/int/float/str/path/json/secret/enum, make_bool_decoder Standalone str -> T decoders
ConfigErrors Raised by build(); holds MissingValueError, InvalidValueError, UnknownKeyError, CollisionError
ConfigError, DecodeError The base class, and the error the standalone decoders raise

Dependencies


Documentation

If you want to… Read
Get started using the package Quick Start above
Understand the model, resolvers and draft, and the design decisions docs/design.md
Navigate and understand the source docs/source-guide.md
Write a resolver for another source docs/extending.md

Metadata

Release files for vcti-config 5.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vcti-config 5.0.1
File Size Uploaded Provenance Actions
vcti_config-5.0.1.tar.gz 53.2 kB With provenance Details for vcti_config-5.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for vcti-config 5.0.1
File Interpreter ABI Platform Actions
vcti_config-5.0.1-py3-none-any.whl Python 3 none any Details for vcti_config-5.0.1-py3-none-any.whl

Total release size: 84.2 kB

Release files / vcti_config-5.0.1.tar.gz

Download URL vcti_config-5.0.1.tar.gz
Size 53.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d33780cabf7ee1993212a52fd77101f6f191ff1930cc8d63688827721cd3949d
BLAKE2b-256 checksum
How to use checksums
2f5e21b95700f7a31d9370e2abd0bb705fdd3ecd935d9ba5e4c1e2784a30e2dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Release files / vcti_config-5.0.1-py3-none-any.whl

Download URL vcti_config-5.0.1-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77a3c3781fecba2a34b33fa76147e7acda8efa1343adf4eac66b45eb165a1c62
BLAKE2b-256 checksum
How to use checksums
7152bef3e5fc11f19b6efbccd165cd60a3f0b2c8ab66fbd76d684d4cb15abfe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

Security for vcti-config 5.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for vcti_config-5.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page