Skip to main content

tranche logo

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 safe backend only allows a small AST subset and a very small set of symbols.
  • NumPy is opt-in via allow_numpy=True and the numpy extra.

Extensibility

You can add your own safe symbols:

import math
config.register_symbol("sqrt", math.sqrt)

Links

License

BSD-3-Clause

Release files for tranche 0.6.0

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

Source distribution (sdist)

Source distribution for tranche 0.6.0
File Size Uploaded
tranche-0.6.0.tar.gz 25.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tranche 0.6.0
File Interpreter ABI Platform
tranche-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.2 kB

Release files / tranche-0.6.0.tar.gz

Download URL tranche-0.6.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a32bbe48bf689f601933c607ea054cc119f90e5c16ee63d31d80f53765ddf4
BLAKE2b-256 checksum
How to use checksums
52d0972c91f920da693130f25a12b4373ac96f05ebcd064ecec63983c2ee62f9
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

Release files / tranche-0.6.0-py3-none-any.whl

Download URL tranche-0.6.0-py3-none-any.whl
Size 18.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27510ad0699c795adad17aa580d09e8bea2a2dd3c032f57304337e349915d155
BLAKE2b-256 checksum
How to use checksums
20202977b8439fab1b6df8618f6ca6d328144c0dc3aae5670f6f79f71a0649ba
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

Release history Release notifications | RSS feed

0.6.1

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.1.1

2 release files

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