Spring Boot-style configuration for Python applications
SprigConfig includes a CLI for inspecting and debugging configuration. This is invaluable for understanding merged configuration, verifying deployments, and troubleshooting issues.
The CLI is included when you install SprigConfig:
pip install sprig-config
Verify installation:
sprigconfig --help
dump CommandThe primary CLI command loads configuration and displays the merged result.
sprigconfig dump --config-dir=config --profile=dev
This loads configuration from config/ with the dev profile and prints the merged result to stdout.
| Argument | Description |
|---|---|
--config-dir PATH |
Directory containing configuration files |
--profile NAME |
Profile to load (dev, test, prod, etc.) |
$ sprigconfig dump --config-dir=config --profile=dev
app:
profile: dev
server:
host: localhost
port: 9090
database:
host: localhost
port: 5432
password: <LazySecret>
logging:
level: DEBUG
sprigconfig:
_meta:
profile: dev
sources:
- /path/to/config/application.yml
- /path/to/config/application-dev.yml
--formatSpecify the input configuration format:
# Load YAML files (default)
sprigconfig dump --config-dir=config --profile=dev --format=yml
# Load JSON files
sprigconfig dump --config-dir=config --profile=dev --format=json
# Load TOML files
sprigconfig dump --config-dir=config --profile=dev --format=toml
--output-formatControl the output format:
# Output as YAML (default)
sprigconfig dump --config-dir=config --profile=dev --output-format=yaml
# Output as JSON
sprigconfig dump --config-dir=config --profile=dev --output-format=json
--outputWrite to a file instead of stdout:
sprigconfig dump --config-dir=config --profile=prod --output=merged-config.yml
--secretsReveal decrypted secrets in output:
# Default: secrets are redacted
$ sprigconfig dump --config-dir=config --profile=prod
database:
password: <LazySecret>
# With --secrets: plaintext shown (unsafe!)
$ sprigconfig dump --config-dir=config --profile=prod --secrets
database:
password: actual-plaintext-password
Warning: Only use --secrets in secure environments. Never pipe to logs or shared outputs.
# Check what production will see
sprigconfig dump --config-dir=config --profile=prod
# Save for review
sprigconfig dump --config-dir=config --profile=prod --output=prod-review.yml
# Dump each profile
sprigconfig dump --config-dir=config --profile=dev --output=dev.yml
sprigconfig dump --config-dir=config --profile=prod --output=prod.yml
# Compare
diff dev.yml prod.yml
When configuration doesn’t look right:
# See the full merged result
sprigconfig dump --config-dir=config --profile=dev
# Check what files were loaded
sprigconfig dump --config-dir=config --profile=dev | grep -A 20 "_meta"
Add to your CI pipeline:
# GitLab CI example
validate-config:
script:
- pip install sprig-config
- sprigconfig dump --config-dir=config --profile=prod
rules:
- changes:
- config/**/*
Export your configuration structure:
sprigconfig dump --config-dir=config --profile=dev --output-format=json > docs/config-schema.json
SprigConfig provides pytest flags for debugging tests:
--dump-configPrint merged configuration for each test:
pytest --dump-config tests/
--dump-config-formatChoose output format:
pytest --dump-config --dump-config-format=json tests/
--dump-config-secretsResolve LazySecrets (still redacted by default):
pytest --dump-config --dump-config-secrets tests/
--dump-config-no-redactShow plaintext secrets (very unsafe):
pytest --dump-config --dump-config-secrets --dump-config-no-redact tests/
--debug-dumpWrite merged configuration to a file after tests:
pytest --debug-dump=test-config-snapshot.yml tests/
--env-pathUse a custom .env file:
pytest --env-path=/path/to/.env.test tests/
The CLI provides clear error messages:
$ sprigconfig dump --config-dir=nonexistent --profile=dev
Error: Configuration directory not found: nonexistent
$ sprigconfig dump --config-dir=config --profile=staging
Error: Profile file not found: config/application-staging.yml
$ sprigconfig dump --config-dir=config --profile=dev
Error: Invalid YAML in config/application.yml: ...
$ sprigconfig dump --config-dir=config --profile=dev
Error: Circular import detected: a.yml → b.yml → a.yml
The CLI respects these environment variables:
| Variable | Description |
|---|---|
SPRIGCONFIG_FORMAT |
Default config format (yml, json, toml) |
APP_SECRET_KEY |
Fernet key for decrypting secrets |
Example:
export APP_SECRET_KEY="your-fernet-key"
sprigconfig dump --config-dir=config --profile=prod --secrets
#!/bin/bash
if sprigconfig dump --config-dir=config --profile=prod > /dev/null 2>&1; then
echo "Configuration valid"
exit 0
else
echo "Configuration error"
exit 1
fi
# Using jq with JSON output
PORT=$(sprigconfig dump --config-dir=config --profile=prod --output-format=json | jq -r '.server.port')
echo "Server port: $PORT"
#!/bin/bash
for profile in dev test prod; do
echo "Checking $profile..."
if ! sprigconfig dump --config-dir=config --profile=$profile > /dev/null; then
echo "FAILED: $profile"
exit 1
fi
done
echo "All profiles valid"
--secrets in CI logs — Secrets would be exposed