Skip to main content

Lightweight self-documenting configuration classes via Python descriptors.

Project description

cfx

CI Docs PyPI

cfx

Declare configuration fields next to the classes that use them. Each field carries its own default value, type checking, and documentation. Compose flat and nested configs freely — the display shows a unified tree and table.

from cfx import Config, Float, String, Bool

class CalibConfig(Config):
    """Photometric calibration parameters."""
    confid = "calib"
    scale = Float(1.0, "Flux scale factor")
    zero_point = Float(25.0, "Photometric zero-point")

class SourceConfig(Config, components=[CalibConfig]):
    """Source detection and measurement."""
    confid = "source"
    n_sigma = Float(3.0, "Detection threshold in sigma")

class PipelineConfig(Config, components=[SourceConfig]):
    """Image analysis pipeline."""
    confid = "pipeline"
    run_id = String("run_01", "Run identifier")
    dry_run = Bool(False, "Validate only; skip writes")

cfg = PipelineConfig()
print(cfg)
PipelineConfig: Image analysis pipeline.
└─ SourceConfig: Source detection and measurement.
    └─ CalibConfig: Photometric calibration parameters.
Config         | Key        | Value  | Description
---------------+------------+--------+-----------------------------
PipelineConfig | run_id     | run_01 | Run identifier
PipelineConfig | dry_run    | False  | Validate only; skip writes
SourceConfig   | n_sigma    | 3.0    | Detection threshold in sigma
CalibConfig    | scale      | 1.0    | Flux scale factor
CalibConfig    | zero_point | 25.0   | Photometric zero-point

Installation

pip install cfx

With optional serialization and CLI backends:

pip install "cfx[yaml]"   # adds PyYAML
pip install "cfx[toml]"   # adds tomli-w
pip install "cfx[click]"  # adds Click
pip install "cfx[all]"    # everything

Quick start

from cfx import Config, Int, Float, String, Options, Bool, Path

class ProcessingConfig(Config):
    confid = "processing"
    iterations = Int(100, "Number of iterations", minval=1)
    threshold = Float(0.5, "Acceptance threshold", minval=0.0, maxval=1.0)
    label = String("run_01", "Human-readable run label")
    mode = Options(("fast", "balanced", "thorough"), "Processing mode")
    verbose = Bool(False, "Enable verbose logging")

cfg = ProcessingConfig()

# Dot access and dict-style access are interchangeable
cfg.iterations = 200
cfg["mode"] = "thorough"

# Bad values raise immediately
cfg.threshold = 1.5   # ValueError: Expected value <= 1.0, got 1.5

# Serialize to dict, YAML, or TOML
d = cfg.to_dict()
cfg2 = ProcessingConfig.from_dict(d)

# Copy with overrides, diff two instances
modified = cfg.copy(iterations=500)
cfg.diff(modified)   # {'iterations': (200, 500)}

Composition

Combine configs into nested sub-objects or a flat merged namespace:

from cfx import Config, Int, String

class FormatConfig(Config):
    confid = "format"
    precision = Int(6, "Decimal places in numeric output")
    encoding = String("utf-8", "Output file encoding")

class PipelineConfig(Config, components=[ProcessingConfig, FormatConfig]):
    pass

cfg = PipelineConfig()
cfg.processing.iterations = 500
cfg.format.precision = 3

License

GPL-3.0-only — see LICENSE.

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

cfx-0.2.0.tar.gz (274.1 kB view details)

Uploaded Source

Built Distribution

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

cfx-0.2.0-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file cfx-0.2.0.tar.gz.

File metadata

  • Download URL: cfx-0.2.0.tar.gz
  • Upload date:
  • Size: 274.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cfx-0.2.0.tar.gz
Algorithm Hash digest
SHA256 af72d90c6357e78608fce297d72417ed915de10195b8f4d6eff8840528416296
MD5 27591fd5c011b459f229bfd75e853eb2
BLAKE2b-256 18eaefe5a8fcc2a4252a9e7d00ee7f88c1eb2ae88aff96613c5f4017f0871dd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfx-0.2.0.tar.gz:

Publisher: publish.yml on DinoBektesevic/cfx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cfx-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: cfx-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cfx-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb3b726134fd6a1056aa92975c569dee2ebf693deaef567ba21bb9363a76cc5b
MD5 82dfcd87df29eb16cc644a8cee4a9211
BLAKE2b-256 ed7e517620ff394264e850d91760955ecc1f9bfc0e46c70c2580c97df2dc584e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cfx-0.2.0-py3-none-any.whl:

Publisher: publish.yml on DinoBektesevic/cfx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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