sqa-tracker


Namesqa-tracker JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
SummaryA tool to track SQLAlchemy query modifications with a structured execution tree and diffs.
upload_time2025-02-25 23:56:25
maintainerNone
docs_urlNone
authorJiri Otoupal
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SQLAlchemy Query Tracker

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](https://github.com/Textualize/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:

```bash
git clone https://github.com/jiri-otoupal/sqlalchemy-query-tracker.git
cd sqlalchemy-query-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:

```python
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.

## Requirements

- Python 3.10+
- [SQLAlchemy](https://www.sqlalchemy.org/)
- [Rich](https://github.com/Textualize/rich)

## 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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "sqa-tracker",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Jiri Otoupal",
    "author_email": "jiri-otoupal@ips-database.eu",
    "download_url": "https://files.pythonhosted.org/packages/fd/f6/07b22f0bf3f8dd1181f42b4fb700ff3a105352a5e8083349b6d306c446b1/sqa_tracker-0.1.1.tar.gz",
    "platform": null,
    "description": "# SQLAlchemy Query Tracker\n\nSQLAlchemy Query Tracker is a Python package that lets you track modifications made to SQLAlchemy query objects in real time. Using Python\u2019s `sys.settrace` along with the [Rich](https://github.com/Textualize/rich) library, it generates a detailed, nested execution tree showing function calls, conditional branches (if, elif, else, case, switch), and recognized query modifications\u2014with unified diffs between query states.\n\n## Features\n\n- **Real-time Tracking:** Monitor SQLAlchemy query changes as they occur.\n- **Rich Execution Tree:** Visualize function calls, conditionals, and query modifications as a nested tree.\n- **Unified Diff Output:** Display differences between the SQL before and after each modification.\n- **Easy Integration:** Wrap your session code with a simple context manager\u2014no modifications to your existing queries are needed.\n\n## Installation\n\nDownload or clone the repository:\n\n```bash\ngit clone https://github.com/jiri-otoupal/sqlalchemy-query-tracker.git\ncd sqlalchemy-query-tracker\n```\n\nAlternatively, download the ZIP archive from the repository page and extract it.\n\n## Usage\n\nWrap your SQLAlchemy query code using the context manager provided by the package. For example:\n\n```python\nfrom sqlalchemy.orm import Session\nfrom query_tracker import sql_query_trace\nfrom query_printer import print_query_log\n\n# Define your compile function (this example uses SQLAlchemy's compile)\ndef compile_sqlalchemy_query(query):\n    return str(query.statement.compile(compile_kwargs={\"literal_binds\": True}))\n\n# Within your session, wrap your code with sql_query_trace\nwith Session(engine) as session:\n    with sql_query_trace(compile_sqlalchemy_query, Path(__file__).name) as tracer:\n        q = session.query(User)\n        # ... perform query modifications here ...\n        q = q.filter(User.active == True)\n        q = q.order_by(User.name.asc())\n    print_query_log(tracer.root)\n```\n\nA complete example is provided in the `test_query_tracking.py` file.\n\n## Requirements\n\n- Python 3.10+\n- [SQLAlchemy](https://www.sqlalchemy.org/)\n- [Rich](https://github.com/Textualize/rich)\n\n## License\n\nThis project is licensed under the MIT License.\n\n## Contributing\n\nContributions are welcome! Please fork the repository and submit a pull request with your enhancements or bug fixes.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A tool to track SQLAlchemy query modifications with a structured execution tree and diffs.",
    "version": "0.1.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "40d39ff76d94bee7c153ea2a1c326cb946728fb7a7d6a0825e324c69f1f9efbd",
                "md5": "d52bbdafef489fff2ad5896b6f6d91ff",
                "sha256": "58a832b54e583daf4624fb95e0458d82e7a5bbf47047968189735dd29206292e"
            },
            "downloads": -1,
            "filename": "sqa_tracker-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d52bbdafef489fff2ad5896b6f6d91ff",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6490,
            "upload_time": "2025-02-25T23:56:23",
            "upload_time_iso_8601": "2025-02-25T23:56:23.261614Z",
            "url": "https://files.pythonhosted.org/packages/40/d3/9ff76d94bee7c153ea2a1c326cb946728fb7a7d6a0825e324c69f1f9efbd/sqa_tracker-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fdf607b22f0bf3f8dd1181f42b4fb700ff3a105352a5e8083349b6d306c446b1",
                "md5": "475851ddae18cd58d0e989e2fa847677",
                "sha256": "164790b181cd13e3863af873d91e2d0b6f93fc4fb2da5fe6ca7065213b0f1665"
            },
            "downloads": -1,
            "filename": "sqa_tracker-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "475851ddae18cd58d0e989e2fa847677",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 5435,
            "upload_time": "2025-02-25T23:56:25",
            "upload_time_iso_8601": "2025-02-25T23:56:25.044413Z",
            "url": "https://files.pythonhosted.org/packages/fd/f6/07b22f0bf3f8dd1181f42b4fb700ff3a105352a5e8083349b6d306c446b1/sqa_tracker-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-25 23:56:25",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sqa-tracker"
}
        
Elapsed time: 0.87382s