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.2.3.post1.tar.gz (16.1 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.2.3.post1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

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

Hashes for tranche-0.2.3.post1.tar.gz
Algorithm Hash digest
SHA256 62409a928fe04bd9bb3403dc5730a1553a8b16c3c5e087f41c2a9a23c94a11b7
MD5 baf7a5f392f540f507f9929423f8ff10
BLAKE2b-256 f0dc92974777e0356b71fe0546eb104987c2d529064ccab2e222509550fbd507

See more details on using hashes here.

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

Hashes for tranche-0.2.3.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7f9067109a3afafc964eaec4c45885f36fed0ad61cdeb9048e02d5bda8f072f
MD5 09795be69e5f7f8fa78867c87dcb4bd9
BLAKE2b-256 8825693432da0617d143759aa12035fdd25120c212987833047cbe9fa65cd7fe

See more details on using hashes here.

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