A Python implementation of the Configuration File (CF) format - a human-readable, machine-parseable data serialization format
Project description
configuration-file
A Python implementation of the Configuration File (CF) format - a human-readable, machine-parseable data serialization format for configuration files.
What is CF?
CF (Configuration File) is a modern configuration format designed to address common shortcomings of existing formats like JSON, YAML, TOML, and INI:
- Human-readable: Clean, minimal syntax with comments
- Machine-parseable: Simple, unambiguous LL(1) grammar
- Whitespace-independent: Structure uses explicit delimiters (
{ }and[ ]), not indentation - Copy-paste safe: Configuration survives email, chat, wikis, and forums
- Type-safe: Explicit typing with no implicit conversions
- Extensible: Includes for configuration reuse across files
See the official CF Specification for complete details, or the local copy included in this repository.
Installation
pip install configuration-file
For development:
pip install configuration-file[dev]
Quick Example
CF files use the .cf extension:
# Application configuration
app_name = "my-service"
version = "1.0.0"
debug = false
# Server settings
server = {
host = "localhost"
port = 8080
timeout = 30.5
}
# Supported features
features = ["auth", "logging", "metrics"]
# Database connections
databases = [
{ name = "primary", url = "postgres://localhost/main" }
{ name = "replica", url = "postgres://localhost/replica", readonly = true }
]
Usage
Simple API (dict-based)
import cf
# Parse a CF file
config = cf.load("config.cf")
# Parse a CF string
config = cf.loads('''
app_name = "my-service"
debug = true
''')
# Access values
print(config["app_name"]) # "my-service"
print(config["server"]["port"]) # 8080
# Serialize to CF format
cf_string = cf.dumps(config)
# Write to a file
cf.dump(config, "output.cf")
Roundtrip API (preserves formatting)
import cf
# Parse into a CFDocument that preserves comments, whitespace,
# quote styles, and separator choices
doc = cf.loads_document('''
# Server configuration
server {
host = "localhost"
port = 8080
}
''')
# Read values
host = doc.get("server.host") # "localhost"
# Modify values (only changed values are re-rendered)
doc.set("server.port", 9090)
# Serialize back with minimal diffs
output = doc.serialize()
# Comments, whitespace, and formatting are preserved
# Convert to plain dict when formatting isn't needed
config = doc.to_dict()
Features
- Full CF 1.0 specification support
- Comments: Hash (
#), double-slash (//), and block (/* */) comments - Data types: Strings, integers, floats, booleans, null, dates, times, datetimes
- Collections: Objects and arrays with flexible syntax
- String variants: Double-quoted, single-quoted, triple-quoted, and raw strings
- Environment variable substitution:
${VAR},${VAR:-default},${VAR:?error} - File includes:
include "path/to/file.cf" - Roundtrip preservation: Parse, modify, and serialize with minimal diffs
Development
Setup
- Clone the repository:
git clone https://codeberg.org/configuration-file/py.git
cd py
- Create a virtual environment and install dependencies:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e ".[dev]"
Running Tests
pytest
With coverage:
pytest --cov=cf --cov-report=html
Code Quality
Lint and format code:
ruff check .
ruff format .
Type checking:
mypy src/cf
License
This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.
Copyright (c) 2026 Dejan Lekic.
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 configuration_file-2.1.1.tar.gz.
File metadata
- Download URL: configuration_file-2.1.1.tar.gz
- Upload date:
- Size: 44.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2860388e5df05beae02a7d6782c2d9e013ecb37f14449a75df4e846f9256c54f
|
|
| MD5 |
292a205257b9bb13043a7ec46e105563
|
|
| BLAKE2b-256 |
e3701ccffb96d1820eb45c5ef3f07ef7dced3ac4980ba742b386208f0dd49002
|
File details
Details for the file configuration_file-2.1.1-py3-none-any.whl.
File metadata
- Download URL: configuration_file-2.1.1-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
350ebe081c263f17ba5afc5ad912964fcd2621573835b6f497256cacdc40fe83
|
|
| MD5 |
b9d37f19ec8ef30cfd7fa092235761c6
|
|
| BLAKE2b-256 |
e0ea928bb44a721594bac8a6eb4970f89ceb30532f082e915531eb6d2db20612
|