Skip to main content

PandaConfig

PandaConfig is a dynamic configuration engine designed to transform static configuration files into executable code. Unlike traditional loaders, it supports variable resolution, function execution, and file inheritance directly within your configs.

Now supporting both YAML and JSON, with an extensible architecture ready for future formats (like TOML, XML, or INI).

Key Features

  • Multi-Format Support: Works seamlessly with YAML (.yaml, .yml) and JSON (.json) out of the box.
  • Dynamic Variables: Define values once and interpolate them anywhere (url: "http://$host:$port").
  • Function Execution: Run Python logic directly inside your config (secret: "$(get_env API_KEY)").
  • File Inheritance: Keep configs DRY (Don't Repeat Yourself) using the extends keyword.
  • Extensible Architecture: Easily register custom functions or add support for new file formats without modifying the core library.

Installation

Install via pip or uv:

# Using pip
pip install nguyenpanda-config

# Using uv
uv add nguyenpanda-config

Quick Start

1. Define Your Configuration

PandaConfig works identically across different formats. Choose the one you prefer.

Option A: YAML (config.yaml)

extends: "./base.yaml"

server:
  host: "localhost"
  port: 8080
  url: "http://$server.host:$server.port/api"     # Variable interpolation ($var)

logs:
  path: "$(path ./logs)/$(now).log"                # Function execution ($(func arg))

Option B: JSON (config.json)

{
  "extends": "./base.json",
  "server": {
    "host": "localhost",
    "port": 8080,
    "url": "http://$server.host:$server.port/api"
  },
  "logs": {
    "path": "$(path ./logs)/$(now).log"
  }
}

2. Load it in Python

The PandaConfig class automatically detects the file type and parses it accordingly.

from PandaConfig import PandaConfig

# Works for YAML
agent_yaml = PandaConfig("config.yaml")
print(agent_yaml.config['server']['url']) 
# Output: http://localhost:8080/api

# Works for JSON
agent_json = PandaConfig("config.json")
print(agent_json.config['server']['url'])

Advanced Usage

Custom Functions

You can extend the logic available inside your configuration files by registering Python functions.

import os
from PandaConfig import PandaConfig

# 1. Initialize
agent = PandaConfig("config.yaml")

# 2. Register a custom function
@agent.registration("env", 1)  # Name='env', Expected Args=1
def get_env_var(key):
    return os.getenv(key, "UNKNOWN")

# 3. Use it in YAML/JSON: 
# db_password: "$(env DB_PASS)"

Adding New File Formats (Future-Proofing)

PandaConfig is designed to be agnostic to the file format. You can register new parsers (e.g., TOML) dynamically.

import tomllib
from PandaConfig import ConfigLoader

# Register a parser for .toml files
ConfigLoader.register_parser('.toml', lambda path: tomllib.load(open(path, "rb")))

# Now you can load TOML files!
agent = PandaConfig("settings.toml")

Built-in Functions

PandaConfig comes with a suite of utility functions ready to use:

Function Args Description
path 1 Convert string to a system-safe Path object
abspath 1 Get the absolute path of a file/folder
glob 2 (dir pattern) List matching files
rglob 2 Recursive glob listing
find_ancestor 2 (path target) Find parent dir containing a target file
now 0 Get current timestamp
list 1 Wrap an item in a list [item]
not 1 Boolean negation

Advanced Usage

Registering Custom File Types

You can extend PandaConfig to support other file formats (like TOML, JSON, or XML) by registering a custom parser.

Here is an example of how to register a TOML parser:

from PandaConfig import PandaConfig
import toml
from pathlib import Path
from typing import Any

# 1. Define your parsing logic
def parse_toml(file_path: Path) -> dict[str, Any]:
    try:
        with open(file_path, 'r', encoding='utf-8') as f:
            return toml.load(f) or {}
    except toml.TomlDecodeError as e:
        raise ValueError(f'Invalid TOML in {file_path}: {e}')

# 2. Register the parser for the .toml extension
PandaConfig.register_parser('.toml', lambda path: parse_toml(path))

# 3. Use PandaConfig with a .toml file
agent = PandaConfig("./pyproject.toml")
print(agent.yaml())

Development & Testing

We use uv for dependency management and pytest for testing. The test suite is dynamic and automatically picks up new test cases added to the data/cases directory.

# Run all tests (YAML, JSON, etc.)
uv run pytest

Author

If you find this project useful, please consider giving it a ⭐ on GitHub!

License

This project is licensed under the MIT License.

You are free to use, modify, and distribute this software, provided that the original copyright notice and permission notice are included in all copies or substantial portions of the software.

See the LICENSE file for more details.

Metadata

Release files for nguyenpanda-config 0.1.1

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

Source distribution (sdist)

Source distribution for nguyenpanda-config 0.1.1
File Size Uploaded Provenance
nguyenpanda_config-0.1.1.tar.gz 17.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nguyenpanda-config 0.1.1
File Interpreter ABI Platform
nguyenpanda_config-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 25.9 kB

Release files / nguyenpanda_config-0.1.1.tar.gz

Download URL nguyenpanda_config-0.1.1.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
eddde35c917d6afdfdc490a61da59c877158e7fae4f5c727923d003a9a8e19f6
BLAKE2b-256 checksum
How to use checksums
47cb1b6fd3aee253d6bf90a609364bf8e2d1b5161f73818ce7087e657c6c2092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Release files / nguyenpanda_config-0.1.1-py3-none-any.whl

Download URL nguyenpanda_config-0.1.1-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32425f296d1c6a680e09cbfe5634d29781388ea1363df3641d759418e8d61ce8
BLAKE2b-256 checksum
How to use checksums
6a34c9292bd5ecd8698e854ed4197bcde2d073f2e575aa35b73ab2474d4d96e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.18

Security for nguyenpanda-config 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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