Skip to main content

Config With YAML

Config With YAML is a pure-Python package to load config YAML files.

Installation

pip install config_with_yaml

Quick Start

from config_with_yaml import Loader

loader = Loader()
cfg = loader.load("config.yml")

print(cfg.getProperty("database.host"))
print(cfg.getPropertyWithDefault("database.port", 5432))
print(cfg)

Using !include

The Loader class supports the !include tag to include external YAML files. Paths are resolved relative to the current file's directory.

# config.yml
app_name: myapp

database: !include database.yml
features: !include features.yml
# database.yml
host: localhost
port: 5432
# features.yml
debug: true
max_connections: 100

Loading the config:

from config_with_yaml import Loader

loader = Loader()
cfg = loader.load("config.yml")

print(cfg.getProperty("app_name"))       # myapp
print(cfg.getProperty("database.host"))  # localhost
print(cfg.getProperty("features.debug")) # true

Chained Includes

Includes can be chained (A includes B includes C). By default, maximum depth is 5.

# level1.yml
data: !include level2.yml
# level2.yml
nested: !include level3.yml
# level3.yml
value: deep_value
cfg = loader.load("level1.yml")
print(cfg.getProperty("data.nested.value"))  # deep_value

Relative Paths

Use relative paths to include files from other directories:

# subdir/config.yml
data: !include ../shared/common.yml

Configuration

The Loader class accepts the following parameters:

  • max_include_depth (int): Maximum depth for nested includes (default: 5)
  • log_level (int): Logging level (default: logging.DEBUG)
  • config_paths (str): Additional colon-separated paths to search for config files
import logging
from config_with_yaml import Loader

loader = Loader(
    max_include_depth=3,
    log_level=logging.INFO,
    config_paths="/path/to/configs:/another/path"
)

cfg = loader.load("config.yml")

Environment Variables

  • YAML_CONFIG_PATHS: Colon-separated paths to search for config files (in addition to current directory)
export YAML_CONFIG_PATHS=path/to/folder1:path/to/folder2

Legacy API (Deprecated)

The old load() function is still available but deprecated:

import warnings
from config_with_yaml import load

# This will show a DeprecationWarning
warnings.filterwarnings('ignore', category=DeprecationWarning)
cfg = load("config.yml")

Migration: Replace with:

from config_with_yaml import Loader

loader = Loader()
cfg = loader.load("config.yml")

Config File Format

Example YAML config:

Demo:
  Motors:
    Server: ROS
    Proxy: Motors:default -h localhost -p 9001
    Topic: '/turtlebotROS/mobile_base/commands/velocity'
    Name: basic_component_pyCamera
    maxW: 0.7
    maxV: 4

  Camera:
    Server: ROS
    Proxy: "CameraL:default -h localhost -p 9001"
    Format: RGB8
    Topic: "/TurtlebotROS/cameraL/image_raw"
    Name: basic_component_pyCamera

  NodeName: demo

Access properties:

cfg = loader.load("demo.yml")
print(cfg.getProperty("Demo.Motors.Server"))       # ROS
print(cfg.getPropertyWithDefault("Demo.Motors.X", "default"))  # default
print(cfg.getProperty("Demo.Camera.Format"))        # RGB8

Testing

pip install -e ".[dev]"
pytest tests/

Release files for config-with-yaml 0.2.0

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

Source distribution (sdist)

Source distribution for config-with-yaml 0.2.0
File Size Uploaded
config_with_yaml-0.2.0.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for config-with-yaml 0.2.0
File Interpreter ABI Platform
config_with_yaml-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.1 kB

Release files / config_with_yaml-0.2.0.tar.gz

Download URL config_with_yaml-0.2.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ed01ba6b9c75e9a83a12eba99f6a5ab44dee26664bb7b86a5c3b3f21b4747258
BLAKE2b-256 checksum
How to use checksums
d126c6a663595742241188a9bca46063cd9638e9b2a49bf17b9e17ce1865a9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / config_with_yaml-0.2.0-py3-none-any.whl

Download URL config_with_yaml-0.2.0-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a2e5a79c965aadd8ae0f8d421d3b8f544c5a730744f78cf3b3ff695d823f686
BLAKE2b-256 checksum
How to use checksums
b9fb1830f8780adea6bc7cb27aada2aa50476bde02efb8c4f5671d50656ba68c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

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