Skip to main content

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
user_id: config.userId
command: run
args:
  - --verbose
  - --endpoint
  - config.base_url
env:
  - name: API_KEY
    value: config.api_key
"""

# 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

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

yaml_config_processor-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yaml_config_processor-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file yaml_config_processor-0.1.1.tar.gz.

File metadata

  • Download URL: yaml_config_processor-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for yaml_config_processor-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69fb88107e7e839cd5d63cc341a06eb41754e5266dc11f7de46cac0475f67f31
MD5 014ffb9bc616f6932678d385c24a05ab
BLAKE2b-256 ab8d86b0c55b01ddb1ad6b46e2e49e1600de0852d18833e76b70f0cb08cd61f8

See more details on using hashes here.

File details

Details for the file yaml_config_processor-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for yaml_config_processor-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 faa3f8a468511fb321b50c0ac8e1d31d4c6c4a2ecc9b5b62780e8500c357d0e0
MD5 7b29e8ebc460b16457838bd37354ea36
BLAKE2b-256 fff542ea928d641c294c4c125b8acfae45e3c04d3058c4bb6636d14d415c91b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page