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
Release files for tranche 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tranche-0.6.1.tar.gz | 27.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tranche-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.0 kB
Release files / tranche-0.6.1.tar.gz
| Download URL | tranche-0.6.1.tar.gz |
|---|---|
| Size | 27.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b2c7c33e3c4d244b93d704fd417ec4cc08bf762ceda0e3b60111c3bbf9dc46c6
|
|
BLAKE2b-256 checksum How to use checksums |
9b5b1368dc8d86a873b8830f86b21685ceca5bfae9821bdf6400739fda6799cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency logRelease files / tranche-0.6.1-py3-none-any.whl
| Download URL | tranche-0.6.1-py3-none-any.whl |
|---|---|
| Size | 19.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bc299cd938893c064a013bce51e7dffae7a5fc82887d027c44048b17d499398b
|
|
BLAKE2b-256 checksum How to use checksums |
d0ac66110b77aa8c203f7e1c317d2a42f15f0120725c285f7d7a2803e6c559e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 29, 2026.
Transparency log