Skip to main content

Configuration helpers (YAML + dotenv layered priority) — standalone module from the SciTeX ecosystem

Project description

scitex-config

SciTeX

Configuration + path management with `direct → yaml → env → default` priority cascade.

Full Documentation · uv pip install scitex-config[all]

pypi python docs

tests install-check quality cov


Problem and Solution

# Problem Solution
1 Config values come from many sources (CLI flags, YAML files, env vars, hard-coded defaults) and ad-hoc precedence rules drift between scripts. PriorityConfig.resolve() enforces a single direct → yaml → env → default cascade with a resolution log.
2 Runtime directories (cache, logs, sessions) get hardcoded to ~/.cache/<pkg>/ and ignore the user's $SCITEX_DIR. get_paths() / ScitexPaths roots every directory at $SCITEX_DIR (default ~/.scitex) and exposes typed accessors.
3 .env loading is reinvented per project (cwd-only, no walk-up, silent override of process env). load_dotenv(walk_up=True) walks parents to $HOME, never overrides existing process env, and returns a boolean status.

Installation

pip install scitex-config

Architecture

scitex-config/
├── src/scitex_config/
│   ├── __init__.py              # get_config, get_paths, PriorityConfig
│   ├── _config.py               # YAML loader + dotted-path resolve()
│   ├── _paths.py                # ~/.scitex/cache, function_cache, ...
│   ├── _priority.py             # PriorityConfig: direct > yaml > env > default
│   └── _bridge.py               # sys.modules alias -> scitex.config
└── tests/

Quick Start

import scitex_config as cfg

config = cfg.get_config()
log_level = config.resolve("logging.level", default="INFO")

paths = cfg.get_paths()
print(paths.cache)            # ~/.scitex/cache

1 Interfaces

Python API
import scitex_config as cfg

# YAML-based (recommended)
config = cfg.get_config()
print(config.MY_KEY)
log_level = config.resolve("logging.level", default="INFO")

# Path resolution
paths = cfg.get_paths()
paths.function_cache       # ~/.scitex/cache/function/...

# Layered priority cascade (direct > yaml > env > default)
pc = cfg.PriorityConfig(yaml_path="config/app.yaml")
db_url = pc.resolve(
    direct=cli_arg,
    key="database.url",
    env_var="DATABASE_URL",
    default="sqlite:///dev.db",
)

Demo

flowchart LR
    D[direct=cli_arg] -->|wins if not None| R[PriorityConfig.resolve]
    Y["yaml: config/app.yaml<br/>database.url"] -->|2nd| R
    E["env: DATABASE_URL"] -->|3rd| R
    F["default='sqlite:///dev.db'"] -->|fallback| R
    R --> V["resolved value"]

Status

Standalone fork of scitex.config. Only dep is PyYAML. The umbrella package's scitex.config import path is preserved via a sys.modules-alias bridge.

Part of SciTeX

scitex-config is part of SciTeX. Install via the umbrella with pip install scitex[config] to use as scitex.config (Python) or scitex config ... (CLI).

Four Freedoms for Research

  1. The freedom to run your research anywhere — your machine, your terms.
  2. The freedom to study how every step works — from raw data to final manuscript.
  3. The freedom to redistribute your workflows, not just your papers.
  4. The freedom to modify any module and share improvements with the community.

AGPL-3.0 — because we believe research infrastructure deserves the same freedoms as the software it runs on.

License

AGPL-3.0-only (see LICENSE).


SciTeX

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

scitex_config-0.3.4.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

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

scitex_config-0.3.4-py3-none-any.whl (38.6 kB view details)

Uploaded Python 3

File details

Details for the file scitex_config-0.3.4.tar.gz.

File metadata

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

File hashes

Hashes for scitex_config-0.3.4.tar.gz
Algorithm Hash digest
SHA256 d840399bc9c98dbb997fceb04ce683a1b82087c76cfa2181bfd2fd54156185e5
MD5 f386197a01b304df11a84be15aa98d19
BLAKE2b-256 5089ccd15931206ff5f6850d77ed4eec423fb792c4241600fc21a42e42f8f08f

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_config-0.3.4.tar.gz:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-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 scitex_config-0.3.4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for scitex_config-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 536be80f3b4cbf49685ce009263131eca07290462203194b416980d7fd9c6325
MD5 d9c29854052f0be45e60ec4770b9693f
BLAKE2b-256 cb1d155b76e18d8d3d3b7d144feb7197d76fd275c21a00918fdc4950e8f0e0aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for scitex_config-0.3.4-py3-none-any.whl:

Publisher: pypi-publish-and-github-release-on-tag.yml on ywatanabe1989/scitex-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