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-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.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| gpconfig-0.4.0.tar.gz | 89.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gpconfig-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 108.8 kB
Release files / gpconfig-0.4.0.tar.gz
| Download URL | gpconfig-0.4.0.tar.gz |
|---|---|
| Size | 89.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
716ad754a5b89b7039028d2d4b266df492164d0579594aa4ea29b9ce70047f01
|
|
BLAKE2b-256 checksum How to use checksums |
c30d096bd3da20666867a8c75656ffb4c5aea65b8c401d2581be2c04d47fb71c
|
| 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 3, 2026.
Transparency logRelease files / gpconfig-0.4.0-py3-none-any.whl
| Download URL | gpconfig-0.4.0-py3-none-any.whl |
|---|---|
| Size | 19.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f0ae4c2aea97c48f5147301f41be741dfb6c2db5a4e6141df9ef469b74eff62
|
|
BLAKE2b-256 checksum How to use checksums |
8664218447472127d9fdcc76241bf5d174bb522d19c50646795e7f7284d4be63
|
| 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 3, 2026.
Transparency logSecurity for gpconfig 0.4.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.
Attestation for gpconfig-0.4.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 Aug 3, 2026.
Transparency logA 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.