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.5.0.tar.gz (23.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.5.0-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tranche-0.5.0.tar.gz
Algorithm Hash digest
SHA256 6dc78ced6d5710b3c057bb08be521a818a002c80f1a212ee801588cd14fd756b
MD5 039105b8bc886a9e532ac3d471dd94d4
BLAKE2b-256 e84fc189b7e50a168c5d99f6f3275c83acb24af478a11dd10c6d2662bf14f251

See more details on using hashes here.

Provenance

The following attestation bundles were made for tranche-0.5.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.5.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for tranche-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5127088d2fc2822d800842a94d9fa6d215fe66732b90a36396fb761c91e876db
MD5 40b1c2b27202cad2856e56f0c4a5e949
BLAKE2b-256 df758420b8d7dd961624ddd947c26093b1fee35ccf8ab0b6e2a576eb68549a89

See more details on using hashes here.

Provenance

The following attestation bundles were made for tranche-0.5.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