Runch: refined munch. With generic typing support.
Project description
Runch
Refined munch. Provides basic munch
functionality with additional generic typing support and runtime validation.
Installation
pip install runch
Usage
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()
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 ofRunchConfigReader.__init__()
. The custom reader should be a callable that takes astr
-type file content and returns a dictionary.
Model Generator
$ python -m runch <config_name> [config_ext]
Manual:
Generate a model definition from a config file.
config_name: the name of the config file without the extension.
config_ext: the extension of the config file. Default is `yaml`.
Use RUNCH_CONFIG_DIR environment variable to specify the directory of the config files. Default is `./etc`.
Example:
python -m runch my_config
python -m runch my_config 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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
runch-1.0.1-py3-none-any.whl
(14.7 kB
view details)
File details
Details for the file runch-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: runch-1.0.1-py3-none-any.whl
- Upload date:
- Size: 14.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7906f47f752e4079e8fae0816967ad4ae877e4c824f484e74637e18904f2f35 |
|
MD5 | 2c88dc86045c8ddda883f9a6cb6584d6 |
|
BLAKE2b-256 | 76588b4249be110633dceeb76a2a968cc51b4f1e243f1e1413979deec3614147 |