Skip to main content

gpconfig

简体中文 | English

General Purpose Configuration management library for Python projects.

A type-safe, YAML-based configuration management library built on Pydantic.

Features

  • Type-safe configuration - Built on Pydantic with full type validation
  • YAML-based - Human-readable configuration files
  • Nested configs - Organize configs in directories (e.g., llm/openai.yaml)
  • Auto-detection - Automatically detect config classes from YAML files
  • Configurable objects - Create object instances directly from configs
  • Environment variable support - Configure paths via environment variables
  • Readonly configs - Protect sensitive configurations

Installation

pip install gpconfig

Quick Start

1. Define Config Classes

from typing import ClassVar
from gpconfig import GPConfig

class DatabaseConfig(GPConfig):
    cfg_class_name: ClassVar[str] = "DatabaseConfig"
    host: str
    port: int = 5432
    username: str
    password: str
    database: str

2. Create Config Folder

myapp/
├── global_env.yaml    # Required: global environment config
├── database.yaml      # Your config files
└── llm/               # Nested configs
    ├── openai.yaml
    └── anthropic.yaml

global_env.yaml:

version: "1.0.0"
debug: true
log_level: INFO

database.yaml:

cfg_class_name: "DatabaseConfig"
host: localhost
port: 5432
username: admin
password: secret
database: myapp

Naming rule: . is the path separator in dot-notation, so .yaml file names and subdirectory names must not contain . (construction fails with ConfigFolderError otherwise). To use a name with literal dots — e.g. an internet domain — write each . as @: domain_name@com.yaml is addressed as get_config("domain_name@com"). @ is a plain pass-through character at the addressing layer; consumer libraries that need real dots implement "escape on addressing, restore after loading" client-side (config.name always returns the raw stem). See the naming rule in the docs.

3. Initialize Manager and Load Configs

from gpconfig import GPConfigManager

# Config folder search order:
# 1. Explicit cfg_folder parameter
# 2. Environment variable: {PROJECT_NAME}_CFG_PATH
# 3. User directory: ~/.{project_name}/
manager = GPConfigManager("myapp", cfg_folder="/path/to/myapp")

# Read global_env values
debug = manager.get_config("global_env.debug")

# Load config (auto-detects the registered class by cfg_class_name;
#               returns a plain dict if no class is registered for it)
db_config = manager.get_config("database")

# Load nested config
llm_config = manager.get_config("llm.openai")

# Read specific field
host = manager.get_config("database.host")

4. Create Configurable Objects

from gpconfig import GPConfigurable

class Database(GPConfigurable):
    def __init__(self, config: DatabaseConfig) -> None:
        super().__init__(config)
        self.host = config.host
        self.port = config.port
        self.username = config.username
        self.password = config.password
        self.database = config.database

    @property
    def connection_string(self) -> str:
        return f"postgresql://{self.username}:{self.password}@{self.host}:{self.port}/{self.database}"

# Register classes
GPConfigManager.register_config_class(DatabaseConfig)
GPConfigManager.register_configurable_class(Database)

# Create object instance
db = manager.get_object("database")
print(db.connection_string)

Note: Add configured_class_name to your YAML for get_object():

cfg_class_name: "DatabaseConfig"
configured_class_name: "Database"
host: localhost
port: 5432

5. Save Configs

# Modify and save
db_config.port = 5433
db_config.save()

# Save to new location
manager.save(db_config, "backups/database_backup")

Core Components

Component Description
GPConfig Base class for all config classes
GPConfigurable Base class for objects created from configs
GPConfigManager Manages config folder, loading, and object creation
GPConfigFolder Subfolder wrapper, provides scoped access to a config subtree
GPConfigurableContext Immutable manager+path context passed to from_config

Exceptions

Exception Description
GPConfigError Base exception for all gpconfig errors
ConfigFolderError Config folder not found or invalid
ConfigNotFoundError Requested config path does not exist
IllegalPathError Config path is malformed or escapes cfg_folder
ConfigReadonlyError Attempted to save a readonly config
RegistrationError Class registration issues
ConfigValidationError Config file validation failed
ConfigurableConstructionError from_config returned an object of the wrong type

API Reference

See the API documentation for detailed usage.

License

MIT

Metadata

Release files for gpconfig 0.5.0

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

Source distribution (sdist)

Source distribution for gpconfig 0.5.0
File Size Uploaded Provenance
gpconfig-0.5.0.tar.gz 94.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for gpconfig 0.5.0
File Interpreter ABI Platform
gpconfig-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 114.3 kB

Release files / gpconfig-0.5.0.tar.gz

Download URL gpconfig-0.5.0.tar.gz
Size 94.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ac1c6d4a7c84e2a9f6db03196e436216a44e1b3316306e3088835181e19a164e
BLAKE2b-256 checksum
How to use checksums
cc1d084a0af6fe41069477c3051702116fde58ffe402e101b4a441915aa0cf2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Release files / gpconfig-0.5.0-py3-none-any.whl

Download URL gpconfig-0.5.0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccb5eb7d3e8ac8bc7b86f02c95b8da39712d89eb523adbb5ed566d0cbc84b4ab
BLAKE2b-256 checksum
How to use checksums
344395589234faca2bfe5cc001e391cf789b9e00a9dada13fcfaf4fa333284e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 16, 2026.

Transparency log

Security for gpconfig 0.5.0

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for gpconfig-0.5.0.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 Oct 16, 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.

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