Skip to main content

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.

License Python

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

  1. Clone the repository:
git clone https://codeberg.org/configuration-file/py.git
cd py
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

configuration_file-2.1.1.tar.gz (44.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

configuration_file-2.1.1-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

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

Hashes for configuration_file-2.1.1.tar.gz
Algorithm Hash digest
SHA256 2860388e5df05beae02a7d6782c2d9e013ecb37f14449a75df4e846f9256c54f
MD5 292a205257b9bb13043a7ec46e105563
BLAKE2b-256 e3701ccffb96d1820eb45c5ef3f07ef7dced3ac4980ba742b386208f0dd49002

See more details on using hashes here.

File details

Details for the file configuration_file-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for configuration_file-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 350ebe081c263f17ba5afc5ad912964fcd2621573835b6f497256cacdc40fe83
MD5 b9d37f19ec8ef30cfd7fa092235761c6
BLAKE2b-256 e0ea928bb44a721594bac8a6eb4970f89ceb30532f082e915531eb6d2db20612

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page