Skip to main content

ConfigParser with layered precedence, provenance, comment-preserving writes, and safe expressions.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tranche-0.4.0.tar.gz (18.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tranche-0.4.0-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file tranche-0.4.0.tar.gz.

File metadata

  • Download URL: tranche-0.4.0.tar.gz
  • Upload date:
  • Size: 18.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tranche-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2a3b2ee84b2b38c77ab43fb6f6e14ee081ab17aafc28fd6cacc8f828957994bd
MD5 426e87f021ca7e6124f1a10b79b0faf6
BLAKE2b-256 24b55c5c42551d7590a70a8749468bb48aa4ff16d30dd04598cd70c354de8370

See more details on using hashes here.

Provenance

The following attestation bundles were made for tranche-0.4.0.tar.gz:

Publisher: publish.yml on xylar/tranche

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tranche-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: tranche-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tranche-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9eee1d3c7b45b063a422f7988ffb3117c2d5977fb8d899cec2674c0dbce812f0
MD5 5b056648b3005a68a18ef1c98030dfdf
BLAKE2b-256 5417007e28c60cdcd1b95d1335002609918ca0c4a0cf8463977cce290bc5d74e

See more details on using hashes here.

Provenance

The following attestation bundles were made for tranche-0.4.0-py3-none-any.whl:

Publisher: publish.yml on xylar/tranche

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page