Skip to main content

Loads configurations from different files with ease

Project description

c3a3‑config‑loader

Coverage Python

Seamless, pluggable configuration for modern Python apps — merge CLI/ENV/RC, validate & decrypt secrets in one line.


Why?

Reading configuration shouldn’t require boilerplate. c3a3‑config‑loader lets you declare a tiny TOML‑like spec and automatically:

  • Parse command‑line arguments (--db.password) with positional support.
  • Pull values from environment variables (C3A3_DB_PASSWORD).
  • Fall back to a per‑user rc‑file (~/.c3a3rc) in TOML or INI.
  • Respect a deterministic precedence order you choose.
  • Validate types, required flags, allowed values & numeric ranges.
  • Obfuscate or reveal sensitive values using AES‑256.
  • Extend via plugins (e.g. vault://secret) with size/charset constraints.

All in a 100% type‑annotated, 80%+ test‑covered library.


Installation

pip install c3a3-config-loader

Requires Python≥3.9. Binary wheels ship with [cryptography] so no external libs.


Quick start

Automatic Configuration Loading (New!)

The easiest way to get started is with automatic configuration loading:

from config_loader.main import load_config_auto

# Automatically loads script_name.json or script_name.yaml
cfg = load_config_auto()
result = cfg.process()  # auto‑reads sys.argv, os.environ, ~/.c3a3rc

print(result.db.password)               # ➔ "obfuscated:..."
print(cfg.reveal(result.db.password))   # ➔ "my‑secret"
print(result.mode)                      # ➔ "prod"

Create a configuration file named after your script (e.g., myapp.json for myapp.py):

{
    "schema_version": "1.0",
    "app_name": "myapp",
    "precedence": ["args", "env", "rc"],
    "parameters": [
        {"namespace": "db", "name": "password", "type": "string", "required": true, "obfuscated": true},
        {"namespace": null, "name": "mode", "type": "string", "default": "prod", "accepts": ["dev", "prod"]},
        {"namespace": "app", "name": "timeout", "type": "number", "min": 1, "max": 60, "default": 30}
    ]
}

Manual Configuration (Traditional)

from config_loader.main import Configuration

spec = {
    "app_name": "c3a3",               # affects env‑var prefix & rc file name
    "precedence": ["args", "env", "rc"],  # CLI wins, env next, then rc
    "parameters": [
        {"namespace": "db", "name": "password", "type": "string", "required": True, "obfuscated": True},
        {"namespace": None, "name": "mode", "type": "string", "default": "prod", "accepts": ["dev", "prod"]},
        {"namespace": "app", "name": "timeout", "type": "number", "min": 1, "max": 60, "default": 30},
    ],
}

cfg = Configuration(spec)
result = cfg.process()  # auto‑reads sys.argv, os.environ, ~/.c3a3rc

print(result.db.password)               # ➔ "obfuscated:..."
print(cfg.reveal(result.db.password))   # ➔ "my‑secret"
print(result.mode)                      # ➔ "prod"

Command‑line invocation

python app.py --db.password my‑secret --mode dev

Environment variables

export C3A3_DB_PASSWORD=my‑secret

RC file (~/.c3a3rc)

[default]
mode = "dev"

New Features

YAML Support

Configuration files can now be written in YAML format alongside JSON:

schema_version: "1.0"
app_name: myapp
precedence:
  - args
  - env
  - rc
parameters:
  - namespace: db
    name: password
    type: string
    required: true
    obfuscated: true
  - namespace: null
    name: mode
    type: string
    default: prod
    accepts:
      - dev
      - prod

The system automatically detects and loads .json, .yaml, or .yml files.

Schema Validation

All configuration files must now include a schema_version field and conform to the defined JSON schema. This ensures:

  • Structure validation: Required fields, correct data types, valid enum values
  • Version compatibility: Forward/backward compatibility handling
  • Error reporting: Clear validation error messages

Supported schema versions: 1.0, 1.0.0


Plugins

Implement ConfigPlugin to fetch protocol values from anywhere:

from config_loader.plugin_interface import ConfigPlugin, PluginManifest

class VaultPlugin(ConfigPlugin):
    @property
    def manifest(self):
        return PluginManifest(protocol="vault", type="string")

    def load_value(self, protocol_value: str):
        # e.g. call HashiCorp Vault
        return vault_client.read(protocol_value)

Register at Configuration(..., plugins=[VaultPlugin()]) and list protocol:"vault" in a parameter.


Coverage & quality

  • Tests: 40+pytest cases, 80% overall coverage
  • Type‑checking: mypy --strict -p config_loader
  • Lint: ruff check --fix

Development

git clone https://github.com/your‑org/c3a3‑config_loader.git
cd c3a3‑config_loader
python -m pip install -e .[dev]
pytest -q  # run test suite

Pull requests welcome — please include tests and pass CI.


License

SPDX-License-Identifier: Prosperity-3.0.0 © 2025 ã — see LICENSE.md for terms.

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

c3a3_config_loader-1.1.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

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

c3a3_config_loader-1.1.0-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file c3a3_config_loader-1.1.0.tar.gz.

File metadata

  • Download URL: c3a3_config_loader-1.1.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for c3a3_config_loader-1.1.0.tar.gz
Algorithm Hash digest
SHA256 de4463404c9d9f23f0073b9ae8957ff430f44aa2553b5bb4022231baeb224b03
MD5 01dd39d92c1e452fd57eb02a2762d56d
BLAKE2b-256 ae5907ff72cda6f02a38eaae5e1df94eb9cd65968596ace886973dce3422c5c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for c3a3_config_loader-1.1.0.tar.gz:

Publisher: ci.yml on mrtu/c3a3-config_loader

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

File details

Details for the file c3a3_config_loader-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for c3a3_config_loader-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ae5836667c97805424017c367b2848783bbf6d9d6fbc92abda611a56084e245
MD5 2a0feaa553cfb1905f7a466fe5594b07
BLAKE2b-256 39bea6b45be95d7e605ab7fb2266fe6eec0df00392706d300e876b137ee66b85

See more details on using hashes here.

Provenance

The following attestation bundles were made for c3a3_config_loader-1.1.0-py3-none-any.whl:

Publisher: ci.yml on mrtu/c3a3-config_loader

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