Process YAML templates with JSON configurations
Project description
YAML Config Processor
A Python package for processing configuration templates from YAML strings with JSON user configurations.
Installation
pip install yaml-config-processor
Features
- Define templates in YAML for better readability
- Accept user configurations in JSON format
- Validate templates and configurations against JSON Schema
- Process templates with user configurations
- Output results in YAML or JSON format
Usage
Basic Example
from yaml_config_processor import ConfigProcessor
# Create processor
processor = ConfigProcessor()
# Define template in YAML
template_yaml = """
configSchema:
type: object
required:
- api_key
- user_id
- base_url
properties:
api_key:
type: string
description: API key for service
user_id:
type: string
description: Unique identifier for the user
base_url:
type: string
format: uri
description: Base URL for the service
service_name: example-service
command: run
args:
- --verbose
- --endpoint
- config.base_url
env:
- name: API_KEY
value: config.api_key
description: |
This template defines the configuration schema and how to use the user-provided values.
The `config.` prefix is used to reference user configuration values.
license: MIT
owner: John Doe
"""
# Define user configuration in JSON
user_config_json = """
{
"api_key": "abc123xyz456",
"user_id": "user1",
"base_url": "https://api.example.com"
}
"""
# Process configuration
template = processor.validate_template(template_yaml)
user_config = processor.validate_user_config(template, user_config_json)
processed = processor.process_configuration(template, user_config)
# Output as YAML
yaml_output = processor.output_yaml(processed)
print(yaml_output)
# Output as JSON
json_output = processor.output_json(processed)
print(json_output)
Step-by-Step Usage
-
Create a template in YAML
Templates define both the schema for user configuration and the template structure with references to the configuration values.
-
Validate the template
template = processor.validate_template(template_yaml)
-
Extract schema for clients (optional)
schema = processor.get_schema(template_yaml)
-
Validate user configuration
user_config = processor.validate_user_config(template, user_config_json)
-
Process configuration
processed = processor.process_configuration(template, user_config)
-
Output the result
# As YAML yaml_result = processor.output_yaml(processed) # As JSON json_result = processor.output_json(processed)
Template Format
Templates must follow this structure:
configSchema: JSON Schema definition for validating user configurations- Other fields: Template structure with references to config values
Example:
configSchema:
type: object
required:
- api_key
properties:
api_key:
type: string
service_name: example-service
config_value: config.api_key
Configuration References
References to configuration values use the config. prefix:
config.api_keyrefers to theapi_keyproperty in the user configconfig.userIdis automatically mapped touser_id(camelCase to snake_case)
License
MIT License
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yaml_config_processor-0.2.11.tar.gz.
File metadata
- Download URL: yaml_config_processor-0.2.11.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
257b2bbec0952efe83cb9299e499ceb96692e2561aca389c71ea3ed3068a4515
|
|
| MD5 |
e13eaf0441e44d32368ef72613ccdfa9
|
|
| BLAKE2b-256 |
9a08641c73cffca9bae40ad4e26d55f1d5496c27de8570e68bb1c5753cb599a4
|
File details
Details for the file yaml_config_processor-0.2.11-py3-none-any.whl.
File metadata
- Download URL: yaml_config_processor-0.2.11-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee1f0950cdabd3b5afb965f1e27f54fe3fff615108c209e45d4c7d005db85786
|
|
| MD5 |
1ca290a4dfee541b692e2a67a92257da
|
|
| BLAKE2b-256 |
db89c0c6441a682e18bde8f0b958eca0f21b2c8712386d5420e5cb2918a0b352
|