
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
A simple and minimalistic 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 stub file (.pyi) which can be used for type hints. Generated types also make autocompletion dreamy!
Heracless is available as a pip package:
pip install heracless
If you want to build from source, run:
git clone https://github.com/felixscode/heracless.git
cd heracless
pip install -e .
First, create a config.yaml
file in a desired location and add desired configs. Make a new Python file called load_config.py
and put it somewhere into your project.
Here is an example project structure:
├── src
│ └── your_module
│ ├── main.py
│ └──utils
│ └── load_config.py
├── data
│ └── config.yaml
├── README.md
├── pyproject.toml
└── .gitignore
Paste the following code into your load_config.py
:
from pathlib import Path
from typing import TypeVar
from heracless import load_config as _load_config
# CONFIG_YAML_PATH is a global variable that sets the path of your yaml config file
# Edit this to your config file path
CONFIG_YAML_PATH = None
Config = TypeVar("Config")
def load_config(config_path : Path|str = CONFIG_YAML_PATH,frozen: bool = True,stub_dump:bool = True) -> Config:
"""
Load the configuration from the specified directory and return a Config object.
Args:
config_path (Path|str, optional): The path to the configuration file. Defaults to CONFIG_YAML_PATH.
frozen (bool, optional): Whether the configuration should be frozen. Defaults to True.
stub_dump (bool, optional): Whether to dump a stub file for typing support or not. Defaults to True.
Returns:
Config: The loaded configuration object.
Raises:
FileNotFoundError: If the configuration file does not exist.
yaml.YAMLError: If there is an error parsing the YAML configuration file.
Note:
CONFIG_YAML_PATH is a global variable that sets the path of your YAML config file.
"""
file_path = Path(__file__).resolve() if stub_dump else None
return _load_config(config_path, file_path, frozen=frozen)
After creating the load_config.py
file, set the CONFIG_YAML_PATH
variable to the path of your config.yaml
file. For example:
CONFIG_YAML_PATH = "/path/to/your/config.yaml"
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 your_project import load_config
from heracless.utils.helper import mutate_config
config = load_config()
new_config = mutate_config(config, "name", "new_value")
as_dict
This function converts a Config
object to a dictionary.
from your_project import load_config
from heracless.utils.helper import as_dict
config = load_config()
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)
Heracless 0.4
Written in Python 3.11
in Order to install all dependcies install the optinal [dev] dependcies.
git clone ...
cd heracless
pip install -e .[dev]
Felix Schelling
GitHub: felixscode
Website: heracless.io
Personal website: felixschelling.de
Written with ❤️ 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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.