A config library that lets you use TOML, JSON, YAML, and .conf files interchangeably,
with a single canonical schema, validation, and automatic format conversion.
Install
pip install alfig-py
# With optional format support:
pip install alfig-py[yaml] # adds PyYAML
pip install alfig-py[toml] # adds tomli-w (for writing TOML)
pip install alfig-py[all] # everything
Python 3.11+ includes
tomllibfor reading TOML. For writing TOML,tomli-wis required.
Quick Start
from alfig import Alfig
# Define your schema once
schema = {
"database": {
"host": str,
"port": int,
"user": str,
"password": (str, "secret"), # (type, default)
},
"features": {
"enable_logging": bool,
"max_threads": (int, 4),
},
}
# Create instance
config = Alfig(schema)
# Load from any supported format — auto-detected by extension
config.load("settings.yaml") # or .json, .toml, .conf, .ini
# Validate against schema (fills in defaults for optional fields)
config.validate()
# Access values with dot-notation
db_host = config.get("database.host")
threads = config.get("features.max_threads") # → 4 (default)
# Modify values
config.set("features.max_threads", 16)
# Save to any format
config.save("settings.json")
config.save("settings.toml")
config.save("settings.conf")
Schema Reference
| Definition | Meaning |
|---|---|
"field": str |
Required string field |
"field": int |
Required int field |
"field": bool |
Required bool field |
"field": float |
Required float field |
"field": list |
Required list field |
"field": dict |
Required dict field |
"field": (str, "x") |
Optional string, default "x" |
"field": (int, 0) |
Optional int, default 0 |
"section": {...} |
Nested section |
Supported Formats
| Format | Extension | Read | Write | Notes |
|---|---|---|---|---|
| JSON | .json |
✓ | ✓ | Built-in |
| YAML | .yaml .yml |
✓ | ✓ | Requires PyYAML |
| TOML | .toml |
✓ | ✓ | Read: tomllib (builtin 3.11+) / tomli; Write: tomli-w or toml |
| CONF | .conf .ini |
✓ | ✓ | Custom parser (see below) |
CONF Format — Nested Sections
The .conf format uses dot-notation section headers for nesting:
# settings.conf
[database]
host = localhost
port = 5432
enabled = true
[database.replica]
host = replica.local
port = 5433
[features]
max_threads = 8
tags = ["web", "api"]
This maps to the same dict as the equivalent JSON:
{
"database": {
"host": "localhost",
"port": 5432,
"enabled": true,
"replica": {
"host": "replica.local",
"port": 5433
}
},
"features": {
"max_threads": 8,
"tags": ["web", "api"]
}
}
Auto-coercion rules (all CONF values are strings at parse time):
| Raw value | Python type |
|---|---|
true / false |
bool |
42 |
int |
3.14 |
float |
["a", "b"] |
list |
{"x": 1} |
dict |
| everything else | str |
API Reference
Alfig(schema=None)
Create a config instance. schema is optional — omit it to skip validation.
.load(path, format=None) → self
Load from a file. Format auto-detected from extension unless overridden.
.loads(text, format) → self
Load from a raw string.
.load_dict(data) → self
Load directly from a Python dict.
.validate() → self
Validate against schema, filling defaults. Raises ValidationError on failure.
.get(key_path, default=None) → value
Read a value with dot-notation: config.get("database.host").
.set(key_path, value) → self
Write a value with dot-notation. Creates intermediate dicts as needed.
.delete(key_path) → self
Remove a key.
.as_dict() → dict
Return a deep copy of the internal data.
.save(path, format=None) → self
Save to a file. Format auto-detected from extension unless overridden.
.dumps(format) → str
Serialize to a string in the given format.
Alfig.convert(input_path, output_path, ...) (static)
Convert a file from one format to another without instantiating Alfig.
CLI
# Convert between formats
alfig convert settings.toml --to json
alfig convert settings.yaml --to conf --out app.conf
# Validate / inspect a file
alfig validate settings.yaml
alfig validate settings.yaml --verbose # prints parsed JSON
# Read a single value
alfig get settings.yaml database.host
Project Structure
alfig/
├── __init__.py # Public API
├── core.py # Alfig class
├── schema.py # Validation engine
├── cli.py # CLI entry point
└── formats/
├── __init__.py # Format registry
├── json_fmt.py
├── yaml_fmt.py
├── toml_fmt.py
└── conf_fmt.py # Custom nested INI parser
License
MIT © dominionthedev
Metadata
Release files for alfig-py 0.1.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 |
|---|---|---|---|---|
| alfig_py-0.1.1.tar.gz | 17.9 kB | With provenance | Details for alfig_py-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alfig_py-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for alfig_py-0.1.1-py3-none-any.whl |
Total release size: 34.3 kB
Release files / alfig_py-0.1.1.tar.gz
| Download URL | alfig_py-0.1.1.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1fe4aac16e54f7392136f107c853d452569a2d1cc00d7a01e424c45ab1cde0cc
|
|
BLAKE2b-256 checksum How to use checksums |
33981a74e5d8799e5268fd3c1b9c5e160943f0e28f07444f0572dab2a77020b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 7, 2026.
Transparency logRelease files / alfig_py-0.1.1-py3-none-any.whl
| Download URL | alfig_py-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6f503e4794a48a5d5974017294e83e35d8e4bb51fa8c0177f3c74195eb4c906
|
|
BLAKE2b-256 checksum How to use checksums |
00cecfee115ed47c0e8e7421e3e6d8f4e4240326a26751a537b19f3e68797564
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 7, 2026.
Transparency logSecurity for alfig-py 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for alfig_py-0.1.1.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 May 7, 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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.