ConfigParser with layered precedence, provenance, comment-preserving writes, and safe expressions.
Project description
tranche
ConfigParser with layered precedence, provenance, comment-preserving writes, and safe expressions.
The name tranche comes from the French word for slice — a nod to how the library lets you cut cleanly through multiple configuration layers to get a single, effective view of your settings.
Documentation
Full docs: https://xylar.github.io/tranche/
Install
- From PyPI (no NumPy):
pip install tranche
- With NumPy extras (to enable safe NumPy expressions):
pip install tranche[numpy]
- From source (local checkout):
pip install .
Quick start
from tranche import Tranche
config = Tranche()
config.add_from_file("defaults.cfg")
config.add_user_config("user.cfg")
# Simple values
value = config.get("core", "option")
# Expression (literal backend chosen automatically)
points = config.getexpression("plot", "ticks")
# NumPy expression (auto-selects safe backend because allow_numpy=True)
arr = config.getexpression("plot", "bins", allow_numpy=True)
# Or via convenience helper
arr2 = config.getnumpy("plot", "bins")
# Provenance
info = config.explain("plot", "bins")
print(info)
Security notes
- Expressions default to
backend="literal"for safety. - The
safebackend only allows a small AST subset and a very small set of symbols. - NumPy is opt-in via
allow_numpy=Trueand thenumpyextra.
Extensibility
You can add your own safe symbols:
import math
config.register_symbol("sqrt", math.sqrt)
Links
- Docs: https://xylar.github.io/tranche/
- Source: https://github.com/xylar/tranche
- Issues: https://github.com/xylar/tranche/issues
License
BSD-3-Clause
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tranche-0.2.3.post1.tar.gz.
File metadata
- Download URL: tranche-0.2.3.post1.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62409a928fe04bd9bb3403dc5730a1553a8b16c3c5e087f41c2a9a23c94a11b7
|
|
| MD5 |
baf7a5f392f540f507f9929423f8ff10
|
|
| BLAKE2b-256 |
f0dc92974777e0356b71fe0546eb104987c2d529064ccab2e222509550fbd507
|
File details
Details for the file tranche-0.2.3.post1-py3-none-any.whl.
File metadata
- Download URL: tranche-0.2.3.post1-py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7f9067109a3afafc964eaec4c45885f36fed0ad61cdeb9048e02d5bda8f072f
|
|
| MD5 |
09795be69e5f7f8fa78867c87dcb4bd9
|
|
| BLAKE2b-256 |
8825693432da0617d143759aa12035fdd25120c212987833047cbe9fa65cd7fe
|