Skip to main content

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

  1. Create a template in YAML

    Templates define both the schema for user configuration and the template structure with references to the configuration values.

  2. Validate the template

    template = processor.validate_template(template_yaml)
    
  3. Extract schema for clients (optional)

    schema = processor.get_schema(template_yaml)
    
  4. Validate user configuration

    user_config = processor.validate_user_config(template, user_config_json)
    
  5. Process configuration

    processed = processor.process_configuration(template, user_config)
    
  6. 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_key refers to the api_key property in the user config
  • config.userId is automatically mapped to user_id (camelCase to snake_case)

License

MIT License

Release files for yaml-config-processor 0.2.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yaml-config-processor 0.2.13
File Size Uploaded
yaml_config_processor-0.2.13.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yaml-config-processor 0.2.13
File Interpreter ABI Platform
yaml_config_processor-0.2.13-py3-none-any.whl Python 3 none any Details

Total release size:17.6 kB

Release files / yaml_config_processor-0.2.13.tar.gz

Download URL yaml_config_processor-0.2.13.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
49e62a9a4e94fa1a9c7209d45c768a04af1146827caf713e054277bceda74a97
BLAKE2b-256 checksum
How to use checksums
03b5f5fa9b2074ada04d133e9ed8b5aa979046ccfefd6e36cf15899e01327479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / yaml_config_processor-0.2.13-py3-none-any.whl

Download URL yaml_config_processor-0.2.13-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59e6c08b9827dfcae319718f53149693da05ecca2d5587e1dc99f21f35c8e787
BLAKE2b-256 checksum
How to use checksums
946e2b62484f211ce787d4d1427bc6ec4c57ac665b6eeb72a2a13d474c512a27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.2.13 This release

2 release files

0.2.12

2 release files

0.2.11

2 release files

0.2.10

2 release files

0.2.0

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page