Skip to main content

Runch: refined munch. Attribute-style access for python dicts, with generic typing support. Help handle your configs, data, and more.

Project description

Runch

Refined munch. Provides basic munch functionality (attribute-style access for python dicts) with additional generic typing support and runtime validation.

Also provides a config reader that reads config files into predefined runch models. Say goodbye to config["key"], config.get("key") and runtime errors caused by missing keys!

Installation

pip install runch

If you find any bugs, please submit an issue or a pull request at GitHub.

Usage

# This model definition can be auto-generated by runch, based on existing config files.

from runch import RunchModel, RunchConfigReader

class ExampleConfig(RunchModel):
    db_host: str
    db_port: int
    db_user: str
    db_password: str
    db_name: str

# Read config from file.                 ↓ square brackets
example_config_reader = RunchConfigReader[ExampleConfig](
#                                         ^^^^^^^^^^^^^ Config model class name
    config_name="example_config_file",  # without extension
    config_dir="example_config_dir",    # default is os.environ.get("RUNCH_CONFIG_DIR", "./etc")
    config_ext="yaml"                   # default is "yaml"
    config_encoding="utf-8"             # default is "utf-8"
)
example_config = example_config_reader.read()  # Or .read_lazy() for lazy loading

print(example_config.config.db_host)  # with awesome intellicode support & runtime validation!
$ touch example_config_dir/example_config_file.yaml
db_host: localhost
db_port: 5432
db_user: user
db_password: password
db_name: database

Supported File Formats

  • YAML
  • JSON
  • TOML
  • arbitrary file formats with custom reader, specified via the custom_config_loader param of RunchConfigReader.__init__(). The custom reader should be a callable that takes a str-type file content and returns a dictionary.

Model Definition Generator

$ python -m runch <config_path> [config_ext]

Manual:

Usage: python -m runch <config_path> [config_ext]
    Generate a model definition from a config file.

    config_path: path to your config file.
    config_ext: content type of your config file. Default is `yaml`.

    Example:
        python -m runch path/to/my_config.foo
        python -m runch path/to/my_config.foo yaml

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

runch-1.1.2.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

runch-1.1.2-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file runch-1.1.2.tar.gz.

File metadata

  • Download URL: runch-1.1.2.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Darwin/22.6.0

File hashes

Hashes for runch-1.1.2.tar.gz
Algorithm Hash digest
SHA256 44c93e187cc52d1fde6d05fd213520c7af5ded34f973fa546c7e07f619d7d15a
MD5 1d388e8abb63eae81d60f34e40263a62
BLAKE2b-256 7f8b15d9cbe19be356f63ee3329b91c6ff4a1c10bed200688d1d1ffc94bc2d7f

See more details on using hashes here.

File details

Details for the file runch-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: runch-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Darwin/22.6.0

File hashes

Hashes for runch-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 438038c43693a306015a23860c7ff1d79e29194ab2192978ab4fcf9c4fe0ad22
MD5 36501e01ad59e6b37d97dfdd90db8485
BLAKE2b-256 bcd0da14e83291ed098a3ad025a3e161d20cb8483f4ce8239494c3542fb85efe

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