
Research
/Security News
Toptal’s GitHub Organization Hijacked: 10 Malicious Packages Published
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Code generator that produces a Python class from a YAML input file. Can be used to facilitate code completion for config objects.
This package enables you to easily generate and instantiate dataclasses from an input YAML
file. For example
this YAML
file
image_size: [ 1280, 960 ]
cluster_config:
eps: 0.02
min_num_samples: 10
path_output: "./output"
automatically converts to a Python class
import dataclasses
import yaml2pyclass
class Config(yaml2pyclass.CodeGenerator):
@dataclasses.dataclass
class ClusterConfigClass:
eps: float
min_num_samples: int
image_size: list
cluster_config: ClusterConfigClass
path_output: str
In addition to code creation, an instance of the generated class that is initialized with the YAML
s values can be
created automatically.
The use case it was primarily developed for is facilitating code completion for arbitrary YAML
config files.
Using YAML
files as input config allows flexible and general information passing, however, when
using pyyaml
the
information is saved as a dict
which does not support any automatic code completion. This means, that you need to know
the exact variable names for access.
Using this package you can enjoy YAML
s flexibility and generality, while additionally providing the benefit of code
completion and type specific suggestions from your IDE. Thus, no need to memorize exact variable names or types.
You can install the package using pip
pip install yaml2pyclass
To update an existing file, as e.g. in the case of a config file, you need to create a base file. The base file (e.g.
at path/to/config.py
) should simply contain a class, that inherits from the yaml2pyclass
base class CodeGenerator
:
import yaml2pyclass
class Config(yaml2pyclass.CodeGenerator):
# content is updated automatically from the specified YAML file
pass
Then, in the function where you want to use this class based on the YAML
input, import the created class and call
the from_yaml
function
from path.to.config import Config # import the class Config from the path/to/config.py file
config = Config.from_yaml("config.yaml")
This will update the file of the Config
class with dataclass that matches the input YAML
.
This project is a collaboration with Felix Hertlein.
This code is distributed under the 3-Clause BSD License, see LICENSE.
FAQs
Code generator that produces a Python class from a YAML input file. Can be used to facilitate code completion for config objects.
We found that yaml2pyclass 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.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.
Research
/Security News
Socket researchers investigate 4 malicious npm and PyPI packages with 56,000+ downloads that install surveillance malware.
Security News
The ongoing npm phishing campaign escalates as attackers hijack the popular 'is' package, embedding malware in multiple versions.