fuckPythonConfig
English | 简体中文
A zero-boilerplate config loader for Python. It auto-discovers a TOML config file and a .env file located next to your running script, then resolves placeholders like ${VAR} and ${VAR:default} recursively across dicts/lists. It uses python-dotenv under the hood for robust .env behavior.
Goal: in small-to-medium scripts/services, get a ready-to-use config with one call to
load_config(), without writing path plumbing and env-var glue code.
Features
- Auto discovery: by default, finds the first .toml and .env next to the caller script
- Placeholder resolution:
- ${VAR} uses the environment variable
- ${VAR:default} uses default when the variable is missing
- Recursively resolves across dicts/lists
- .env compatibility: powered by python-dotenv (merge/override/interpolate, etc.)
- Clear errors:
- FileNotFoundError (custom, more friendly info)
- TOMLReadError
- EnvVarNotFoundError (when no default provided)
- Minimal deps: only python-dotenv (plus stdlib tomllib)
Installation
Requires: Python >= 3.11
- pip
pip install fuckpythonconfig
- uv (optional)
uv add fuckpythonconfig
- from source
pip install git+https://github.com/JGG0sbp66/fuckPythonConfig.git@dev
Quick Start
Project layout (example):
your-project/
app.py # your script calling load_config()
config.toml # config file
.env # environment variables (dev)
config.toml:
[database]
host = "127.0.0.1"
port = 5432
username = "${DB_USER:postgres}"
password = "${DB_PASS}" # will raise EnvVarNotFoundError if missing
.env:
DB_USER=local_user
DB_PASS=secret123
app.py:
from fuckpythonconfig import load_config
cfg = load_config() # auto-discovers .toml and .env next to app.py
print(cfg["database"]["username"]) # => "local_user"
Explicit parameters (optional):
from fuckpythonconfig import load_config
cfg = load_config(
file_path="./config.toml", # specify TOML path
dotenv_path="./.env", # specify .env path
verbose=True, # passthrough to python-dotenv
override=False, # override existing env vars
interpolate=True, # allow .env interpolation
)
Placeholder rules
- Syntax:
- ${VAR} → use env var VAR
- ${VAR:default} → use default literal if VAR is missing
- Scope: recursively applied to all string values in dict/list
- Match: only replaced when a value is exactly a placeholder
- i.e. "${VAR}" is replaced; "prefix ${VAR}" is not (current limitation)
- Types:
- replaced value is a string (from env/default)
- non-placeholder TOML types remain unchanged (int/bool/array, etc.)
- Missing variable: raises EnvVarNotFoundError if no default provided
API
load_config(
file_path: str | None = None, dotenv_path: str | None = None, stream: IO[str] | None = None, verbose: bool = False, override: bool = False, interpolate: bool = True, encoding: str | None = "utf-8", ) -> dict
Purpose:
- Read TOML → load .env → resolve placeholders → return a merged dict
Details:
- When not specified, it searches the caller script directory for the first .toml and .env
- .env loading is handled by python-dotenv; parameters are passed through
Exceptions:
- FileNotFoundError (missing .toml/.env/dir)
- TOMLReadError (syntax or read failure)
- EnvVarNotFoundError (placeholder var missing without default)
Limitations
- Only replaces values that are exactly a placeholder (no partial replacement in long strings)
- If multiple .toml/.env files exist, the first one enumerated by the filesystem is used
- Python >= 3.11 (due to stdlib tomllib)
Development
Ruff is used for linting/formatting.
uv sync
Contributions are welcome (placeholder improvements, type casting, cross-file refs, etc.).
Acknowledgments
- python-dotenv for the robust .env handling
License
MIT License. See LICENSE for details.
Metadata
Release files for fuckpythonconfig 1.0.1
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 | Actions |
|---|---|---|---|---|
| fuckpythonconfig-1.0.1.tar.gz | 8.9 kB | Without provenance | Details for fuckpythonconfig-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fuckpythonconfig-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for fuckpythonconfig-1.0.1-py3-none-any.whl |
Total release size: 16.4 kB
Release files / fuckpythonconfig-1.0.1.tar.gz
| Download URL | fuckpythonconfig-1.0.1.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f43ba716de96dcfb84f2d93a1bdf3b908d26e26aa0650fa2beec1b0e30a19b2d
|
|
BLAKE2b-256 checksum How to use checksums |
6820e62af32799fd957bdac5d7675891d28a6d066f4e188c74b6db471ee087bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Release files / fuckpythonconfig-1.0.1-py3-none-any.whl
| Download URL | fuckpythonconfig-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69fb7ecffb04f3f96ae3a11a1e7a236c7df3f3ee9344410c74b8c87288357027
|
|
BLAKE2b-256 checksum How to use checksums |
2b5a88ce1bf75400bae27d2ba349a124a4983af67dc1ec0e50e318bb85d3d82c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.1
|
Security for fuckpythonconfig 1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.