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/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

config_with_yaml-0.2.0.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

config_with_yaml-0.2.0-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file config_with_yaml-0.2.0.tar.gz.

File metadata

  • Download URL: config_with_yaml-0.2.0.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for config_with_yaml-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ed01ba6b9c75e9a83a12eba99f6a5ab44dee26664bb7b86a5c3b3f21b4747258
MD5 0cacd3bd322ac6c34674ec20a18160c2
BLAKE2b-256 d126c6a663595742241188a9bca46063cd9638e9b2a49bf17b9e17ce1865a9ef

See more details on using hashes here.

File details

Details for the file config_with_yaml-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for config_with_yaml-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a2e5a79c965aadd8ae0f8d421d3b8f544c5a730744f78cf3b3ff695d823f686
MD5 aa68222310e0498c324a1e8dc8a4fbe0
BLAKE2b-256 b9fb1830f8780adea6bc7cb27aada2aa50476bde02efb8c4f5671d50656ba68c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

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