Thread-safe singleton JSON/YAML configuration loader with JSON Schema validation
Project description
ConfigKit
Thread-safe singleton JSON/YAML configuration loader with JSON Schema validation for Python applications.
Features
- JSON & YAML support - Load configuration from
.json,.yaml, or.ymlfiles - Thread-safe singleton - One instance per configuration class
- JSON Schema validation - Draft 2020-12 support via
jsonschema - Dot-notation access -
config.get("database.host") - Runtime reload - Update configuration without restart
- Type-safe - Full type hints with
py.typedmarker - Extensible - Custom validation via
additional_checks()
Installation
From PyPI
pip install pyConfigKit
From Git repository
pip install git+https://github.com/miichoow/ConfigKit.git
Development mode
git clone https://github.com/miichoow/ConfigKit.git
cd ConfigKit
pip install -e ".[dev]"
Quick Start
1. Create your configuration class
from configkit import ConfigKit
class AppConfig(ConfigKit):
def additional_checks(self) -> None:
# Custom validation logic
if self.data.get("debug") and self.data.get("env") == "production":
raise ValueError("Debug mode not allowed in production")
def get_database_url(self) -> str:
host = self.get("database.host")
port = self.get("database.port", default=5432)
name = self.get("database.name")
return f"postgresql://{host}:{port}/{name}"
2. Create configuration files
config.json
{
"env": "development",
"debug": true,
"database": {
"host": "localhost",
"port": 5432,
"name": "myapp"
}
}
Or config.yaml
env: development
debug: true
database:
host: localhost
port: 5432
name: myapp
schema.json (schema files are always JSON)
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["env", "database"],
"properties": {
"env": {
"type": "string",
"enum": ["development", "staging", "production"]
},
"debug": {
"type": "boolean"
},
"database": {
"type": "object",
"required": ["host", "name"],
"properties": {
"host": { "type": "string" },
"port": { "type": "integer", "minimum": 1, "maximum": 65535 },
"name": { "type": "string" }
}
}
}
}
3. Use in your application
# Initialize once at startup (JSON)
config = AppConfig(config_file="config.json", schema_file="schema.json")
# Or with YAML
config = AppConfig(config_file="config.yaml", schema_file="schema.json")
# Access anywhere - returns the same instance
config = AppConfig()
print(config.get_database_url())
API Reference
ConfigKit
Base class for configuration. Subclass and implement additional_checks().
Constructor
ConfigKit(*, config_file: str | Path, schema_file: str | Path)
config_file- Path to configuration file (.json,.yaml, or.yml)schema_file- Path to JSON Schema file
Properties
| Property | Type | Description |
|---|---|---|
data |
dict[str, Any] |
Loaded configuration dictionary |
schema |
dict[str, Any] |
Loaded JSON Schema dictionary |
Methods
| Method | Description |
|---|---|
get(path, *, default=None) |
Get value by dot-notation path |
reload() |
Reload and re-validate from disk |
additional_checks() |
Override for custom validation |
ConfigKitMeta
Metaclass providing singleton behavior.
| Method | Description |
|---|---|
reset() |
Clear all singleton instances (for testing) |
Design Principles
- Fail fast - Invalid configuration raises exceptions immediately
- Single source of truth - One instance per configuration class
- Explicit contracts - Required files on first instantiation
- No magic - Clear, predictable behavior
Publishing
pip install -e ".[dev]"
python -m build
twine upload dist/*
License
MIT License - see LICENSE for details.
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 pyconfigkit-1.1.0.tar.gz.
File metadata
- Download URL: pyconfigkit-1.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
287dd55970068a3f6b0ecd4921eacf06b910b56bffa378d0266e1b52e972fc1a
|
|
| MD5 |
21a926717409f27f825e9b5c467dc971
|
|
| BLAKE2b-256 |
ce196e4417d6f12b9ed8bfd96a4db3ee07c8083bee19c6d97f81a0cd97b3cbe7
|
Provenance
The following attestation bundles were made for pyconfigkit-1.1.0.tar.gz:
Publisher:
python-publish.yml on miichoow/ConfigKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyconfigkit-1.1.0.tar.gz -
Subject digest:
287dd55970068a3f6b0ecd4921eacf06b910b56bffa378d0266e1b52e972fc1a - Sigstore transparency entry: 928382886
- Sigstore integration time:
-
Permalink:
miichoow/ConfigKit@9b1bf4f63531328b1821a723188d6bb2836358ea -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/miichoow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9b1bf4f63531328b1821a723188d6bb2836358ea -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyconfigkit-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pyconfigkit-1.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1881866412fcc89480a314d90c195a17c879188cf49ba7319e40e8c22fd77737
|
|
| MD5 |
09e904fae6ef77c632e83edb82a31161
|
|
| BLAKE2b-256 |
ab406f3d94751212cc54337545442e77c544581f3c2e156dfdece12813b3de8b
|
Provenance
The following attestation bundles were made for pyconfigkit-1.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on miichoow/ConfigKit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyconfigkit-1.1.0-py3-none-any.whl -
Subject digest:
1881866412fcc89480a314d90c195a17c879188cf49ba7319e40e8c22fd77737 - Sigstore transparency entry: 928382888
- Sigstore integration time:
-
Permalink:
miichoow/ConfigKit@9b1bf4f63531328b1821a723188d6bb2836358ea -
Branch / Tag:
refs/tags/v1.1.0 - Owner: https://github.com/miichoow
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9b1bf4f63531328b1821a723188d6bb2836358ea -
Trigger Event:
release
-
Statement type: