
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Config2Code simplifies configuration management by automatically generating Python dataclasses from YAML or JSON files. This tool enhances code readability, maintainability, and type safety, saving you time and effort.
Config2Code is a Python tool designed to streamline the process of converting configuration files (YAML or JSON or TOML) into Python dataclasses. By automating the generation of dataclasses, you can improve code readability, maintainability, and type safety.
You can install Config2Code using pip:
pip install config2code
Prepare your configuration file: Create a YAML or JSON file containing your configuration data. Here's an example YAML file:
DatabaseConfig:
host: localhost
port: 5432
user: myuser
password: mypassword
Run the tool:
Use the config2code
command-line interface to convert the configuration file:
config2code to-code --input input.yaml --output output.py
This will generate a Python file output.py
containing a dataclass representing the configuration:
from dataclasses import dataclass
@dataclass
class DatabaseConfig:
host: str
port: int
user: str
password: str
Sometimes you put redundant data in your config file because it is more convenient to only move parts of the config further down the road. Examples could be a machine learning pipeline where you have parameters for your dataset and model which can have redundant values. To counter the problem of always changing multiple values at once in your config we introduce placeholder. A placeholder is a path packed into a token ${<path-in-config>}
which points to a value you want to insert automatically into your loaded config file. This path starts always at the yaml root and ends at the value to insert.
pipeline:
dataset:
x_dim: 42
y_dim: 5
batch_size: 128
shuffle: True
model:
input_dim: ${pipeline.dataset.x_dim}
output_dim: ${pipeline.dataset.y_dim}
activation_func: ReLU
learning_rate: 0.0001
Here we use the API of OmegaConf. Therefor you are allowed to use all kinds of funny stuff like custom evaluators or missing value imputation or merging config files from multiple files or .... .
Please note for the last one is no tested feature for merging configs from multiple files into one big structured config.
Additionally we support now a Hydra integration where provide functions to add the hydra ArgumentParser to your custom parser.
Note: Please note this feature is still underdevelopment. Therefor please be careful while merging those two argument parser and setup the wrapper function. A rough example can be examined here
This service monitors the requested configuration file. If the services detects changes in the file it will automatically write those changes into the specified output.py
.
You can start the service for example with:
config2code service-start --input input.yaml --output output.py
To stop it you can stop all with
config2code stop-all
After you created your python config you can easily use as follows:
from output import DatabaseConfig
config = DatabaseConfig.from_file("input.yaml")
# access config field with dot operator
config.host
This is different to a normal DictConfig
from OmegaConf because this supports code completion in your coding environment.
{{<path>.<to>.<element>[<index>]}}
We welcome contributions to improve Config2Code. Feel free to fork the repository, make changes, and submit a pull request.
License
This project is licensed under the MIT License.
FAQs
Config2Code simplifies configuration management by automatically generating Python dataclasses from YAML or JSON files. This tool enhances code readability, maintainability, and type safety, saving you time and effort.
We found that config2class 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
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.