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_py

# Parse a CF file
config = cf_py.load("config.cf")

# Parse a CF string
config = cf_py.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_py.dumps(config)

# Write to a file
cf_py.dump(config, "output.cf")

Roundtrip API (preserves formatting)

import cf_py

# Parse into a CFDocument that preserves comments, whitespace,
# quote styles, and separator choices
doc = cf_py.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_py --cov-report=html

Code Quality

Lint and format code:

ruff check .
ruff format .

Type checking:

mypy src/cf_py

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.0.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.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file configuration_file-2.1.0.tar.gz.

File metadata

  • Download URL: configuration_file-2.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 87ecd6a479c03aa0812d9d4e4be5e5609ca716f0d43610c0c61ddca29be14877
MD5 592ba2d9686d7fc2bb0499d94685962a
BLAKE2b-256 cc7074ee0efd961c3fe34853af8bf2174422718a693fea0e24b6c6ffc3231402

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for configuration_file-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aba1a3f66b723c83c09043d64f8644ab1b90e3945b3cbc73260f656ca86e6110
MD5 4dd4edb8ab7f1037c5e03e7a6a5ae7b8
BLAKE2b-256 bb6fa77d9ebdec3b396b08425b424bed672d24ef79eaae9f593d8a7e6d9f6347

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