Skip to main content

Yaml to Dataclass parser for Config files

Project description

heracless

Config Manager using yaml.

Description

heracless aims to make working with config files in python easy. It parses a config file into a dataclass and creates types as a python file with can be used for type hints. Generated types also make autocompletion a dreamy!

Usage

first create a config file in yaml format and put in your desired fields. to access the config information do like in following sample code.

from heracless import heracless
from config.types import Config

@heracless()
def main(cfg:Config) -> Any: 
"""
simply add a cfg parameter to any function at the first place
and access config attributes like you do any with any other object
"""
    some_sample_config_value = config.sample.some_value

its as simple as that!

or simply use the load_config function to load the config file into a dataclass

from heracless import load_config
from config.types import Config

@heracless()
def main(*args,**kwargs) -> Any: 
    config = load_config()
    print(config.sample.some_value)

arguments:

  • cfg_path:Path yaml config file path -> Default ./config/config.yaml
  • dump_dir:Path Path where types are going to be written to -> Default ./config/types.py
  • dump_func:Callable control's the dumping behavior -> options: heracless.dump_in_file|heracless.dump_in_console| heracless.dump_dummy -> Default dump_in_file
  • frozen:bool whether dataclass config objects are mutable or not -> Default True
  • make_dir:bool make given paths or not if not existing -> Default True

Cli-Tool

heracless also comes with a cli tool to generate the types file from a config file simply run the following command in your terminal

heracless path/to/config.yaml -p path/to/types.py # generates types file
heracless path/to/config.yaml -d # dumps types to console
heracless path/to/config.yaml -h # for help

Sure, here's a markdown document that describes the functions in helper.py and provides example usage:


Helper Functions in Heracless

This document describes the helper functions in the helper.py module of the Heracless project.

mutate_config

This function takes a Config object, a name, and a value, and returns a new Config object with the value at the name updated.

from heracless.utils.helper import mutate_config
from heracless.utils.c_types import Config

config = Config(...)  # Initialize a Config object
new_config = mutate_config(config, "name", "new_value")

as_dict

This function converts a Config object to a dictionary.

from heracless.utils.helper import as_dict
from heracless.utils.c_types import Config

config = Config(...)  # Initialize a Config object
config_dict = as_dict(config)

from_dict

This function creates a Config object from a dictionary. You can specify whether the Config object should be frozen.

from heracless.utils.helper import from_dict

config_dict = {...}  # A dictionary representing the configuration
config = from_dict(config_dict, frozen=True)

Remember to replace Config(...) and {...} with actual Config objects and dictionaries.

installation

pip install heracless

Version

heracless 0.2
written in python 3.11

Future

add config variants

Author

Felix Schelling
github: felixscode
Witten with <3 in Mexico

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

heracless-0.2.3.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

heracless-0.2.3-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

Details for the file heracless-0.2.3.tar.gz.

File metadata

  • Download URL: heracless-0.2.3.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for heracless-0.2.3.tar.gz
Algorithm Hash digest
SHA256 a5e6c7ba06e3eedeabea528691f4f79820f8cca18c9a50cf24b05cb56c72cf75
MD5 8a6a291eb76206d2976e27260b2ca4a9
BLAKE2b-256 0b7db0652450dde07b30b739fc023db40879965319a055d59db2780ddfd6d55a

See more details on using hashes here.

File details

Details for the file heracless-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: heracless-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.12

File hashes

Hashes for heracless-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 174bcb8eb927b63c0b88a791cd5c319e9fff6f81c30c7c06a3a637c592b7dd64
MD5 86969e5bd18a055e57e6f246ed50fe78
BLAKE2b-256 98796c38b1fa098976e47ea61c4d83d90586580fa2e3a2c19d62d5c0a334e167

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page