Skip to main content

TraceMind

Add one decorator. Run two versions. See exactly what behaviour changed.

PyPI Python License: MIT


What is TraceMind? (the plain English version)

Imagine you take a photo of your kitchen every day. If something goes missing, you can compare today's photo with yesterday's and spot it straight away.

TraceMind does the same thing for software. It quietly records what your functions do: what went in, what came out, how long it took, and whether it failed. Later, you can line up what version 1 of your app did next to what version 2 did, and see what changed.

That matters because software can break without anyone noticing. A small edit to a discount rule, a tax calculation or a billing function can pass every test and still give customers different answers. TraceMind is built to catch that.

Status: TraceMind is young. Recording works today. Comparing versions and AI explanations are being built. See What works today.


A real example

Your shop has a function that works out the price after a discount:

def final_price(price, discount_percent):
    return price - price * discount_percent / 100

A teammate "tidies it up" and accidentally changes the rounding. Your tests still pass, because nobody wrote a test for that exact case. But now some customers are charged a few cents more. Nobody notices for weeks.

With TraceMind, both versions leave a record of what they returned for the same inputs. Comparing the two records shows the difference before customers do.


What works today

Feature Status
Record function calls: inputs, result, errors, timing, app version Available
Works with normal and async functions Available
Safe by default: big or odd values are shortened, a tracking problem never breaks your app Available
Read the recorded traces from Python, or turn them into plain data (JSON friendly) Available
Save traces to disk, so version 1 and version 2 can be run separately Planned
Compare two versions and list what changed Planned
Plain language explanations from a local AI model (through Ollama) Planned
Store traces in PostgreSQL Planned

These are honest statuses. The "Planned" rows are not built yet.


Quick start

1. Install

pip install "tracemind-regression>=0.1.2"

You need Python 3.10 or newer. TraceMind has no dependencies, so it will not pull extra packages into your project.

You install tracemind-regression, but you import it as tracemind.

2. Add the decorator

import tracemind


@tracemind.track
def final_price(price, discount_percent):
    return price - price * discount_percent / 100


@tracemind.track
def divide(a, b):
    return a / b

Your functions behave exactly as before. Return values are unchanged, and your own errors are raised as usual.

3. Call them and look at what was recorded

final_price(200, 10)

try:
    divide(1, 0)
except ZeroDivisionError:
    pass

for trace in tracemind.get_records():
    print(trace.function_name, trace.status.value, trace.args, trace.return_value)

Output:

final_price success [200, 10] 180.0
divide error [1, 0] None

Each record is a Trace object. Call .to_dict() to turn it into plain data:

{
    'id': 'f93833137ec7449fa9f89367e66d737a',
    'schema_version': 1,
    'function_name': 'final_price',
    'function_module': '__main__',
    'args': [200, 10],
    'kwargs': {},
    'return_value': 180.0,
    'status': 'success',
    'error_type': None,
    'error_message': None,
    'error_traceback': None,
    'started_at': '2026-11-19T22:23:02.382133+00:00',
    'duration_ms': 0.003,
    'app_version': 'v1',
    'metadata': {},
}

4. Label your app version

Comparing versions only works if each trace knows which version made it. Set the label with an environment variable before you start your app:

# macOS / Linux
TRACEMIND_APP_VERSION=v1 python your_app.py

# Windows PowerShell
$env:TRACEMIND_APP_VERSION = "v1"; python your_app.py

If you do not set it, traces are labelled unknown.


Using TraceMind in your own open source project

  1. Install it as a development tool, for example with pip install tracemind-regression, or add tracemind-regression>=0.1.2 to your dev requirements.
  2. Pick the functions that matter most. Good candidates are the ones where a silent change would hurt: pricing, discounts, tax, scoring, parsing, permissions. You do not need to track everything.
  3. Add @tracemind.track above each one. That is the whole change to your code.
  4. Set TRACEMIND_APP_VERSION when you run each release or branch, for example to your version number or git commit.
  5. Run your tests or a sample workload. The recorded calls become the "photo" of that version's behaviour.
  6. Read the traces with tracemind.get_records().

Use tracemind.clear_records() to empty the store, which is handy between test cases.

TraceMind keeps traces in memory for now. Saving them to a file and comparing two versions are the next things on the roadmap.


What gets recorded

Field What it holds
function_name, function_module Which function ran
args, kwargs What it was called with, as they were before the call
return_value What it returned
status success or error
error_type, error_message, error_traceback What went wrong, if anything
started_at When the call started, in UTC
duration_ms How long it took, in milliseconds
app_version The version label you set
metadata A free space for extra notes
id, schema_version A unique id and the record format version

Traces are immutable. Once a trace is created it describes the past and is not edited.


Safe by default

  • It never breaks your app. If recording fails for any reason, your function still returns its result. Your own exceptions are always re-raised unchanged.
  • Inputs are saved before your function runs. If a function changes its own arguments, the trace still shows what it was originally given.
  • Values are kept small and clean. Long text is shortened, large lists are trimmed, loops in data are cut, and odd values (such as NaN, raw bytes or memory addresses) are turned into safe text.
  • Everything stays on your machine. TraceMind does not send data anywhere.

Please be careful with sensitive data

Arguments and return values are recorded as they are. Automatic redaction of secrets (passwords, tokens, personal data) is not built yet. Until it is, do not decorate functions that receive secrets or personal data.


How it works

Your function (decorated with @track)
        |
   tracker.py      watches the call: inputs, output, timing, errors
        |
   models.py       builds a structured, immutable Trace
        |
   collector.py    stores the traces (in memory for now)
        |
   comparison engine (planned)   compares traces between app versions
        |
   llm_client.py (planned)       asks a local Ollama model to explain the differences

Each part has one job, so storage can later move from memory to PostgreSQL without touching the decorator.


Frequently asked questions

Do I need to know AI or machine learning? No. Recording works with plain Python. The AI explanations are planned and will be optional.

Will it slow down my app? The decorator adds a small amount of work to each tracked call, so track the functions that matter, not everything. Planned settings will let you sample calls or turn tracking off.

Does it send my data to the cloud? No. Traces stay in your process. The planned AI explanations use a model running on your own computer through Ollama.

Is this a replacement for tests? No. Tests check what you expected. TraceMind shows what changed, including things you did not think to test.

Does it work with async code? Yes. async def functions are tracked the same way.


Roadmap

  • Function execution tracking (@tracemind.track)
  • Immutable, JSON friendly trace records
  • In-memory collector with an optional size limit
  • Automated tests
  • Configuration (config.py): app version, sampling, size limits, on/off switch
  • Save and load traces
  • Version comparison engine
  • Local AI explanations through Ollama
  • PostgreSQL storage
  • Automatic redaction of sensitive values

Contributing

Contributions, ideas and bug reports are welcome. Please open an issue first for larger changes.

To work on TraceMind itself:

git clone https://github.com/TejasDharmale/TraceMind.git
cd TraceMind
python -m venv .venv
# activate it, then:
pip install -e .
pip install pytest
python -m pytest

The code lives in sdk/tracemind/:

File Job
tracker.py The @track decorator
models.py The Trace record and Status
collector.py Stores traces
serialize.py Makes values safe and small
config.py Settings (planned)

License

MIT. See LICENSE.

Metadata

Release files for tracemind-regression 0.1.2

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

Source distribution (sdist)

Source distribution for tracemind-regression 0.1.2
File Size Uploaded Provenance Actions
tracemind_regression-0.1.2.tar.gz 15.3 kB Without provenance Details for tracemind_regression-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tracemind-regression 0.1.2
File Interpreter ABI Platform Actions
tracemind_regression-0.1.2-py3-none-any.whl Python 3 none any Details for tracemind_regression-0.1.2-py3-none-any.whl

Total release size: 27.1 kB

Release files / tracemind_regression-0.1.2.tar.gz

Download URL tracemind_regression-0.1.2.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b3d9494f5fd463c1a3809c246378218ac2376fbf4ab077833942260666729202
BLAKE2b-256 checksum
How to use checksums
ce42bad7c9bb380fbf338f429a73a6f56539401d8a80621397b53931da2eddc8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / tracemind_regression-0.1.2-py3-none-any.whl

Download URL tracemind_regression-0.1.2-py3-none-any.whl
Size 11.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b43c87a7d2b836604aa5585d12c931acbf27e03da6ac96718a3e736a0ac412c7
BLAKE2b-256 checksum
How to use checksums
3aa805ccb1de6af0fc325b8574062942dd55f902f7d40b3b5419cfb98e48afd3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for tracemind-regression 0.1.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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