Visualize your Python code execution flow as Mermaid Sequence Diagrams.
Project description
MermaidTrace: The Python Logger That Draws Diagrams
Stop reading logs. Start watching them.
MermaidTrace is a specialized logging tool that automatically generates Mermaid JS sequence diagrams from your code execution. It's perfect for visualizing complex business logic, microservice interactions, or asynchronous flows.
✨ Features
- Decorator-Driven: Just add
@traceor@trace_interactionto your functions. - Auto-Diagramming: Generates
.mmdfiles that can be viewed in VS Code, GitHub, or Mermaid Live Editor. - Async Support: Works seamlessly with
asynciocoroutines. - Context Inference: Automatically tracks nested calls and infers
sourceparticipants usingcontextvars. - FastAPI Integration: Includes middleware for zero-config HTTP request tracing.
- CLI Tool: Built-in viewer to preview diagrams in your browser.
🚀 Quick Start
Installation
pip install mermaid-trace
Basic Usage
from mermaid_trace import trace, configure_flow
import time
# 1. Configure output
configure_flow("my_flow.mmd")
# 2. Add decorators
@trace(source="Client", target="PaymentService", action="Process Payment")
def process_payment(amount):
if check_balance(amount):
return "Success"
return "Failed"
@trace(source="PaymentService", target="Database", action="Check Balance")
def check_balance(amount):
return True
# 3. Run your code
process_payment(100)
Nested Calls (Context Inference)
You don't need to specify source every time. MermaidTrace infers it from the current context.
@trace(source="Client", target="API")
def main():
# Inside here, current participant is "API"
service_call()
@trace(target="Service") # source inferred as "API"
def service_call():
pass
FastAPI Integration
from fastapi import FastAPI
from mermaid_trace.integrations.fastapi import MermaidTraceMiddleware
app = FastAPI()
app.add_middleware(MermaidTraceMiddleware, app_name="MyAPI")
@app.get("/")
async def root():
return {"message": "Hello World"}
CLI Viewer
Visualize your generated .mmd files instantly:
mermaid-trace serve my_flow.mmd
📂 Documentation
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
📄 License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mermaid_trace-0.3.1.tar.gz.
File metadata
- Download URL: mermaid_trace-0.3.1.tar.gz
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e9f894a906f5c3419c8653ef75dae83d5295103b84e1f0ec735bcc5264e3719
|
|
| MD5 |
fe7a3255495c8a9aba82c463ecf6008a
|
|
| BLAKE2b-256 |
401128d36103af6b8b4a60087cb5b8f6d887b0ce680dec5b94a28a8646c370df
|
Provenance
The following attestation bundles were made for mermaid_trace-0.3.1.tar.gz:
Publisher:
release.yml on xt765/mermaid-trace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mermaid_trace-0.3.1.tar.gz -
Subject digest:
7e9f894a906f5c3419c8653ef75dae83d5295103b84e1f0ec735bcc5264e3719 - Sigstore transparency entry: 854587962
- Sigstore integration time:
-
Permalink:
xt765/mermaid-trace@703beca3e2db7f7e0fb3d02504aab574490b9fbb -
Branch / Tag:
refs/tags/V0.3.1 - Owner: https://github.com/xt765
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@703beca3e2db7f7e0fb3d02504aab574490b9fbb -
Trigger Event:
release
-
Statement type:
File details
Details for the file mermaid_trace-0.3.1-py3-none-any.whl.
File metadata
- Download URL: mermaid_trace-0.3.1-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d80a993be4a6341ea4e36feb99215eeda0200719556c5689e149f778d10a0270
|
|
| MD5 |
30f596eab8307efca293f60cac9e7dad
|
|
| BLAKE2b-256 |
e2cf548bfe7a503f88533a117136470dd834a42a69cdf49676e256982864747f
|
Provenance
The following attestation bundles were made for mermaid_trace-0.3.1-py3-none-any.whl:
Publisher:
release.yml on xt765/mermaid-trace
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mermaid_trace-0.3.1-py3-none-any.whl -
Subject digest:
d80a993be4a6341ea4e36feb99215eeda0200719556c5689e149f778d10a0270 - Sigstore transparency entry: 854587965
- Sigstore integration time:
-
Permalink:
xt765/mermaid-trace@703beca3e2db7f7e0fb3d02504aab574490b9fbb -
Branch / Tag:
refs/tags/V0.3.1 - Owner: https://github.com/xt765
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@703beca3e2db7f7e0fb3d02504aab574490b9fbb -
Trigger Event:
release
-
Statement type: