![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
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 Type, 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(frozen: bool = True) -> Config:
"""
Load the configuration from the specified directory and return a Config object.
Args:
frozen (bool, optional): Whether the configuration should be frozen. 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()
yaml_config_path = CONFIG_YAML_PATH
return _load_config(yaml_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
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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.