Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Config Manager using yaml.
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!
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:
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:
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.
pip install heracless
heracless 0.2
written in python 3.11
add config variants
Felix Schelling
github: felixscode
Witten with <3 in Mexico
FAQs
Yaml to Dataclass parser for Config files
We found that heracless demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.