Skip to main content

A config system that is lazily validated as parameters are used

Project description

ghostconfig

A config system that is lazily validated as parameters are used.

Installation

pip install ghostconfig

Usage

Creating a config

import ghostconfig

# From a YAML file (OmegaConf interpolations supported)
config = ghostconfig.GhostConfig("path/to/config.yaml")

# From a JSON file
config = ghostconfig.GhostConfig("path/to/config.json")

# From a plain Python dict
config = ghostconfig.GhostConfig({"num_epochs": 10, "learning_rate": 0.001})

Reading values

get(key) with no default returns a GhostConfig sub-config (real or ghost). get(key, default) returns the leaf value (type inferred from the default).

# Given config.yaml:
# model:
#   layers: 4
#   block: resnet
# dataset:
#   path: my/data/
#   augmentations: [crop]

model_config = config.get("model")    # GhostConfig
layers = model_config.get("layers", 1)  # 4

# Accessing a key that doesn't exist in the YAML is fine at this point —
# a "ghost" GhostConfig is returned and the access is recorded.
training_config = config.get("training")
learning_rate = training_config.get("learning_rate", 0.001)  # returns 0.001

Validating at setup time

Call check() once all parameters have been read. It raises MissingConfigError with a suggestion showing exactly what to add to your config file.

config.check()
# MissingConfigError:
# The following parameters were used but missing from the config.
# Since this started from a yaml (path/to/config.yaml), you should add:
#
# training:
#   learning_rate: 0.001

If multiple keys are missing they are merged into a single suggestion block. The format matches the source: YAML for .yaml files, JSON for .json files, and a Python dict literal for dict-based configs.

Development

Setup

pip install -e ".[dev]"

Or install with test dependencies:

pip install pytest
pip install -e .

Running Tests

pytest

To run with verbose output:

pytest -v

Building and Publishing to PyPI

Prerequisites

pip install build twine

Build the distribution

python -m build

This creates a dist/ directory containing a .whl and .tar.gz file.

Upload to PyPI

First, upload to TestPyPI to verify everything looks correct:

twine upload --repository testpypi dist/*

When ready, upload to the real PyPI:

twine upload dist/*

You will be prompted for your PyPI credentials. It is recommended to use an API token instead of your password.

To avoid entering credentials each time, create a ~/.pypirc file:

[pypi]
  username = __token__
  password = pypi-your-api-token-here

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

ghostconfig-0.1.0.tar.gz (15.2 kB view details)

Uploaded Source

Built Distribution

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

ghostconfig-0.1.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ghostconfig-0.1.0.tar.gz.

File metadata

  • Download URL: ghostconfig-0.1.0.tar.gz
  • Upload date:
  • Size: 15.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ghostconfig-0.1.0.tar.gz
Algorithm Hash digest
SHA256 107371d9db0d3397ad695c115d0a4cf6b09aa6b5add4b005e749951d8816e919
MD5 072ad3954e16cefcb9af1a76db7ff9d9
BLAKE2b-256 42f508e3d829f281a4287fc73e1da66018ae71b45d6cdb6a4729a662b066adc2

See more details on using hashes here.

File details

Details for the file ghostconfig-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ghostconfig-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for ghostconfig-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0d0e49a40eeb62c476dd0a05380f0ac3f442741bcedec42b5c71212dd8f388de
MD5 a9b46a714fbe32e58c23e61d88d72973
BLAKE2b-256 78dddb444b7aa42ee23d23ea3a8b30065528847ed6e15e4e45e0ff4d5fbde21b

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