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.
Project description
Config2Code: A Tool to Generate Python Dataclasses from Configuration Files
Introduction
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.
Installation
You can install Config2Code using pip:
pip install config2code
Usage
-
Prepare your configuration file: Create a YAML or JSON file containing your configuration data. Here's an example YAML file:
database: 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
Key Features
- Supports YAML, JSON and TOML: Easily convert both formats.
- Automatic dataclass generation: Generates well-structured dataclasses.
- Nested configuration support: Handles nested structures in your configuration files.
- Type inference: Infers types for fields based on their values.
- Customizable output: Control the output file name and code formatting.
Additional Considerations
- Complex data structures: For more complex data structures, consider using custom type hints or additional configuration options.
- Error handling: The tool includes basic error handling for file loading and parsing.
- Future enhancements: We plan to add support for additional file formats, advanced type inference, and more customization options.
Contributing
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file config2class-0.1.0.tar.gz
.
File metadata
- Download URL: config2class-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb9c38a4582ec272a7f7ddba7e3bcddb8d04d3479e8a6582c9a00e8b876eb077 |
|
MD5 | 6876a1c8a905685943fe15169241f528 |
|
BLAKE2b-256 | ab86be3f1e63b2d1262e2841d2da576239dba41ae8d56eb2a7cf68a23808da61 |
File details
Details for the file config2class-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: config2class-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Linux/6.8.0-47-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6102eb1a32357225343e6465efbc72589dbf7630d44ffc9029c6d1562eba5cb |
|
MD5 | 3b638dd18686e324ecb62e820312a13d |
|
BLAKE2b-256 | d9cdc7eb3b4ad627c523c8d96beba3ec49912bd75df70b190b9a535e8e50e0de |