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.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: heracless-0.2.1.tar.gz
  • Upload date:
  • Size: 11.7 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.1.tar.gz
Algorithm Hash digest
SHA256 3ef954d5e56332efcc4ac6eb99c704420bb8a39ad481426faf04060f187ed8b0
MD5 8a4c793485aff73163e0cbb4a5cbc80c
BLAKE2b-256 32fe760c7ad4458f1488e0f2f0ba453d2fc5d1061aca178c3294b6fc67a90680

See more details on using hashes here.

File details

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

File metadata

  • Download URL: heracless-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ab10b4e45d5a9f8ef261af7078925b2b04b91b9eb0b6dc0471496bc07fc1752c
MD5 7104ef440d481e9528a85f7b266fa1b5
BLAKE2b-256 897a65ae788868c6be1e03f6fe5b459185c1733d6ae61a32d9b14fd45d40ce5f

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