Skip to main content

Get and set two-key plaintext configuration values stored to JSON file path.

Project description

dworshak-config

dworshak-config is a lightweight library for managing nested JSON configurations. It serves as the standard storage backend for the Dworshak ecosystem, providing a stable way to persist non-sensitive application settings.

By decoupling storage from user interaction, dworshak-config ensures that your scripts can retrieve settings silently when they exist, leaving the "how to ask for them" to its sister package, dworshak-prompt.

Features

  • Zero Dependencies: Pure Python standard library (json and pathlib).
  • Service-Oriented: Organizes settings by service and item (e.g., config["postgres"]["port"]).
  • Atomic Persistence: Automatically handles directory creation and pretty-printed JSON writes.
  • Fail-Safe Loading: Gracefully handles corrupted or missing configuration files.

Installation

uv add dworshak-config
# or
pip install dworshak-config

Usage

Basic I/O

The DworshakConfig is the primary interface for reading and writing data.

from dworshak_config import DworshakConfig

# Uses default path: ~/.dworshak/config.json
cfg = DworshakConfig()

# Store a value
cfg.set_value("aws", "region", "us-east-1")

# Retrieve a value (returns None if missing)
region = cfg.get_value("aws", "region")
print(f"Targeting: {region}")

Custom Configuration Paths

Perfect for project-specific settings that shouldn't live in the global Dworshak folder.

from dworshak_config import DworshakConfig

# Point to a specific project file
project_cfg = DworshakConfig("./.my_project/config.json")
project_cfg.set_value("internal", "debug_mode", True)

The Ecosystem Integration

While dworshak-config handles the persistence, it is designed to be orchestrated by dworshak-prompt for interactive workflows.

# In your application using dworshak-prompt
from dworshak_prompt import Obtain

# This will:
# 1. Check ~/.dworshak/config.json for 'api_url'
# 2. If missing, prompt the user (Console/GUI/Web)
# 3. Save the answer back to config.json automatically
api_url = Obtain.config("my_service", "api_url")

Configuration Schema

Data is stored in a clean, human-readable nested JSON format:

{
    "aws": {
        "region": "us-east-1",
        "output": "json"
    },
    "rjn_api": {
        "base_url": "https://api.example.com"
    }
}

CLI

The dworshak layer is the intended primary CLI entry point, but the dworshak-config CLI can be used directly.

See the dworshak-config Typer CLI structure.

dworshak-config helptree

Screenshot of the dworshak-config CLI helptree

helptree is utility funtion for Typer CLIs, imported from the typer-helptree library.


Sister Projects in the Dworshak Ecosystem

pipx install dworshak
pip install dworshak-secret
pip install dworshak-config
pip install dworshak-env
pip install dworshak-prompt

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

dworshak_config-0.2.7.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

dworshak_config-0.2.7-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file dworshak_config-0.2.7.tar.gz.

File metadata

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

File hashes

Hashes for dworshak_config-0.2.7.tar.gz
Algorithm Hash digest
SHA256 1df366cfe392cc189dce4ae6f47b2f9e5e70b7b18cf6a4b98f5df8d45f661e07
MD5 494d60b10bba286e1fb7da52e70c8f2e
BLAKE2b-256 8aa91f12fc21748db22880924f8c1eec386abefa1395ec38a7503f05f25a2223

See more details on using hashes here.

Provenance

The following attestation bundles were made for dworshak_config-0.2.7.tar.gz:

Publisher: publish.yml on City-of-Memphis-Wastewater/dworshak-config

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

File details

Details for the file dworshak_config-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for dworshak_config-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a8b0ab00318c2344f0a9763dc2fca235e853635494e6bf5c3a8b8bdf5727bae4
MD5 5152bb8bb8a2c60983e315f421a9342f
BLAKE2b-256 2e6e6c90db2dc7f5f6c8bd4e3c8b2168457dc55638f9106534aca8597c141740

See more details on using hashes here.

Provenance

The following attestation bundles were made for dworshak_config-0.2.7-py3-none-any.whl:

Publisher: publish.yml on City-of-Memphis-Wastewater/dworshak-config

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