Skip to main content

SQLAlchemy Query Tracker

Downloads SQLAlchemy Query Tracker is a Python package that lets you track modifications made to SQLAlchemy query objects in real time. Using Python’s sys.settrace along with the Rich library, it generates a detailed, nested execution tree showing function calls, conditional branches (if, elif, else, case, switch), and recognized query modifications—with unified diffs between query states.

Features

  • Real-time Tracking: Monitor SQLAlchemy query changes as they occur.
  • Rich Execution Tree: Visualize function calls, conditionals, and query modifications as a nested tree.
  • Unified Diff Output: Display differences between the SQL before and after each modification.
  • Easy Integration: Wrap your session code with a simple context manager—no modifications to your existing queries are needed.

Installation

Download or clone the repository:

git clone https://github.com/jiri-otoupal/sqa_tracker.git
cd sqa_tracker

Alternatively, download the ZIP archive from the repository page and extract it.

Usage

Wrap your SQLAlchemy query code using the context manager provided by the package. For example:

from sqlalchemy.orm import Session
from query_tracker import sql_query_trace
from query_printer import print_query_log

# Define your compile function (this example uses SQLAlchemy's compile)
def compile_sqlalchemy_query(query):
    return str(query.statement.compile(compile_kwargs={"literal_binds": True}))

# Within your session, wrap your code with sql_query_trace
with Session(engine) as session:
    with sql_query_trace(compile_sqlalchemy_query, Path(__file__).name) as tracer:
        q = session.query(User)
        # ... perform query modifications here ...
        q = q.filter(User.active == True)
        q = q.order_by(User.name.asc())
    print_query_log(tracer.root)

A complete example is provided in the test_query_tracking.py file.

Use print method on tracer to show current status without finish execution

from sqlalchemy.orm import Session
from query_tracker import sql_query_trace


# Define your compile function (this example uses SQLAlchemy's compile)
def compile_sqlalchemy_query(query):
    return str(query.statement.compile(compile_kwargs={"literal_binds": True}))


# Within your session, wrap your code with sql_query_trace
with Session(engine) as session:
    with sql_query_trace(compile_sqlalchemy_query, Path(__file__).name) as tracer:
        q = session.query(User)
        # ... perform query modifications here ...
        q = q.filter(User.active == True)
        tracer.print()
        # other code ...

Requirements

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your enhancements or bug fixes.

Metadata

Release files for sqa-tracker 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 sqa-tracker 0.1.2
File Size Uploaded Provenance Actions
sqa_tracker-0.1.2.tar.gz 5.6 kB Without provenance Details for sqa_tracker-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sqa-tracker 0.1.2
File Interpreter ABI Platform Actions
sqa_tracker-0.1.2-py3-none-any.whl Python 3 none any Details for sqa_tracker-0.1.2-py3-none-any.whl

Total release size: 12.2 kB

Release files / sqa_tracker-0.1.2.tar.gz

Download URL sqa_tracker-0.1.2.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
34c973258e20afcdcc5c0fd15a4d1f1e9dc132d6a4f37f35db696ced07a48614
BLAKE2b-256 checksum
How to use checksums
5e01dcc5382eed58ced8b2aaff314f8693d302c07913f6099d02d2b231bc467f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.0 Windows/10

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

Download URL sqa_tracker-0.1.2-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fead0846969019a38a448c3389dd7ad82d1272c925a962cd5323a66b7468573
BLAKE2b-256 checksum
How to use checksums
77d18187b290454e6c14d1aafa926c0dc65cea805d2022e6ef1d050e5b740678
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.1 CPython/3.13.0 Windows/10

Security for sqa-tracker 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