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

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-detect class by cfg_class_name)
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

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 modify readonly config
RegistrationError Class registration issues
ConfigValidationError Config file validation failed

API Reference

See the API documentation for detailed usage.

License

MIT

Metadata

Release files for gpconfig 0.3.5

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.3.5
File Size Uploaded Provenance
gpconfig-0.3.5.tar.gz 75.6 kB With provenance Details

Built distribution (wheel)

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

Total release size: 93.3 kB

Release files / gpconfig-0.3.5.tar.gz

Download URL gpconfig-0.3.5.tar.gz
Size 75.6 kB
Tags Source
SHA-256 checksum
How to use checksums
04ee4a9c8f841b63766a62c0527157d28d7cc694e032faa65097620d8070977c
BLAKE2b-256 checksum
How to use checksums
dfa9b6f876ec5eaca2e3b91bfcca030ebbc8757cb1a88f894830d2288bb75267
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 Aug 2, 2026.

Transparency log

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

Download URL gpconfig-0.3.5-py3-none-any.whl
Size 17.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2d699bfb3611da45fc1d657abc3fb2af3f89d21abddb5837ea28fc43b581adf
BLAKE2b-256 checksum
How to use checksums
92073501ec6b22f542783cd0bfe1c1b9d950394ac8e3eaf8a98fb0e92b4f62cd
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 Aug 2, 2026.

Transparency log

Security for gpconfig 0.3.5

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.3.5.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 Aug 2, 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