Skip to main content

Subtrix

    ## Project overview
    
    Subtrix is a substitution module for Python, providing powerful tools for text
    manipulation through substitutions. The main interface is the `Mechanism` class,
    which allows for standard substitution, term expansion, and variable
    substitution.
    
    Subtrix is part of the Solutions Brewer (SB) stack and is consumed by sibling
    projects such as **GoaLT** (report rendering) and **Condor** (prompt
    templating). It is designed to be:
    
    - **Deterministic** — given the same template and data, output is byte-stable.
    - **Composable** — the public API is a single class with a small surface.
    - **Safe** — built-in security validation (max size, max recursion, dangerous
      pattern deny-list).
    - **Lightweight** — minimal dependencies, no template precompilation step.
    
    See [ARCHITECTURE.md](ARCHITECTURE.md) for the full design and
    [CLI.md](CLI.md) for the command-line interface.
    
    ## Features
    
    - Provides a basic substitution mechanism
    - Supports variable substitution
    - Supports lists of variables to generate multiple documents from a single template
    - Supports term expansion by using term looping substitution all combinations of a list of terms can be generated
    - Provides Prefix and Suffix Support with controls for trailing suffix
    
    ## Installation
    
    You can install Subtrix via pip:
    
    ```bash
    pip install subtrix
    ```
    
    Alternatively, clone the repository and install from source:
    
    ```bash
    git clone https://github.com/solubrew/subtrix.git
    cd subtrix
    pip install -e .
    ```
    
    ### Requirements
    
    - Python 3.<MIN_VERSION> or higher
    - Dependencies: re, <EVAL_LIB> (automatically installed via pip where applicable)
    
    ## Quick Start
    
    Import the module and use the Mechanism class for substitutions:
    
    ## Standard Patterns
    
    ### Substitution:
    
        <[token]>: basic substitution
        <~[token]~>: optional token substituion (is removed if unused in template render)
        <[prefix.:token]>: token substitution with prefix
        <[token:.suffix]>: token substitution with suffix
    
    ### Variable Substitution:
    
        <(token)>: registerd variable lookup for things like TODAY, USER, etc.
        <(prefix.:token)>: optional variable token substituion
        <(token:.suffix)>: optional variable token substituion
    
    ### Looped Variable Substitution:
    
        token: ['point0', 'point1']
        <@[token]@>: [['point0'], ['point1'], ['point0', 'point1']
    
    ```python
    from subtrix import Mechanism
    
    # Initialize Mechanism
    template = 'Hello, <[name]>!'
    data = {'name': 'World'}
    mech = Mechanism(template, data)
    
    # Perform standard substitution
    result = mech.run()
    print(result)  # Output: Hello, World!
    ```
    
    ## Usage
    
    
    ### Variable Substitution
    
    Inject variables from various sources:
    
    
    ## Development
    
    To set up a development environment and run the test suite locally:
    
    ```bash
    # Clone and install in editable mode with dev extras
    git clone https://github.com/solubrew/subtrix.git
    cd subtrix
    python -m pip install --upgrade pip
    pip install -e ".[dev]"
    pip install pytest pytest-asyncio
    
    # Run the test suite
    pytest tests/ -v
    
    # Lint (matches CI)
    ruff check subtrix/
    
    # Confirm the package imports cleanly
    python -c "import subtrix; print('Import OK:', subtrix.__name__)"
    
    # Render a template from the CLI
    python -m subtrix.cli subtrix "Hello <[name]>!" '{"name": "World"}'
    ```
    
    Before opening a pull request, also run the compliance auditor to verify the
    project is in a releasable state:
    
    ```bash
    PYTHONPATH=...:$TASKAXN_PYTHONPATH python -m sasquatch.cli analyze \
        -p . --agent m3rl1n --skip-pii-secrets
    ```
    
    A score of **>= 90 %** is required to tag a release. See
    [CI_CD.md](CI_CD.md) for the full pipeline description.
    
    ## Contributing
    
    Contributions are welcome! Please follow these steps:
    
    1. Fork the repository.
    2. Create a feature branch (`git checkout -b feature/<FEATURE_NAME>`).
    3. Commit your changes (`git commit -am 'Add some feature'`).
    4. Push to the branch (`git push origin feature/<FEATURE_NAME>`).
    5. Open a Pull Request.
    
    See [CONTRIBUTING.md](CONTRIBUTING.md) for more details.
    
    ## License
    
    This project is licensed under the MIT License - see the [LICENSE](LICENSE.rst) file for details.
    
    ## Acknowledgments
    
    - Built with inspiration from open-source templating and substitution libraries.
    - Thanks to contributors of underlying libraries like re, and Python's built-in eval.

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

subtrix-0.0.1.post2-cp312-cp312-manylinux_2_39_x86_64.whl (31.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

File details

Details for the file subtrix-0.0.1.post2-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for subtrix-0.0.1.post2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 8a841248e22275a0f7efbb6d592f0286355fc95f617e399d0db975a7101f0e1b
MD5 2e5109da4a373ed362393c5fb83d22d2
BLAKE2b-256 b1e49e1a44cdd4f88cd12e04bb4295e7719863d737832a2d90d3b86b040f5fdc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.1.post3

1 file

This release

0.0.1.post2 This release

1 file

0.0.1.post1

1 file

0.0.1

1 file

0.0.0

2 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