Description
Provides a simple way to find slow SQL queries when using SQLAlchemy.
Hooks into the SQLAlchemy events system to find when queries start and finish. Note that this is not meant to serve as a profiler and will not explain why your queries are slow, just tell you which ones are. See SQLAlchemy docs about performance for profiling if you need to find out how much time a query spends waiting for database response, fetching the data and ORM operations.
Installation
This is a pure python package, so it can be installed with pip install simple-sqla-timer
or any other dependency manager.
Usage
Run this function at the start of your application:
from simple_sqla_timer import setup_query_timer
setup_query_timer()
By default, this will log the start of the statements and their durations to the simple_sqla_timer logger, with
debug level. You can override this behaviour by specifying a custom logging function:
import logging
from simple_sqla_timer import setup_query_timer
def my_log_function(statement: str, duration: float) -> None:
logging.info("Query: %s\nDuration:%f", statement, duration)
setup_query_timer(my_log_function)
Important: The query timer must be set up before the application opens SQLAlchemy Engine connections. Any
connections opened before setting up the timer will not have their statements logged.
Development
This library uses the poetry package manager, which has to be installed before installing
other dependencies. Afterwards, run poetry install to create a virtualenv and install all dependencies.
Black is used (and enforced via workflows) to format all code. Poetry will install it
automatically, but running it is up to the user. To format the entire project, run black ..
Contributing
This project uses the Apache 2.0 license and is maintained by the data science team @ Barbora. All contributions are welcome in the form of PRs or raised issues.
Metadata
Release files for simple-sqla-timer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple-sqla-timer-0.1.0.tar.gz | 7.5 kB | Without provenance | Details for simple-sqla-timer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_sqla_timer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for simple_sqla_timer-0.1.0-py3-none-any.whl |
Total release size: 15.1 kB
Release files / simple-sqla-timer-0.1.0.tar.gz
| Download URL | simple-sqla-timer-0.1.0.tar.gz |
|---|---|
| Size | 7.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eb359cd5c390ee9dc199a1dea196e57c6def976f15a922c5e880c4d3bb78f27
|
|
BLAKE2b-256 checksum How to use checksums |
876a34000529a87c0d78f2d02f1a771dbd1b38162704ebf13ba41e7637b99229
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1039-azure
|
Release files / simple_sqla_timer-0.1.0-py3-none-any.whl
| Download URL | simple_sqla_timer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9ff06edfb898da2134299de592ea69464df8bd9a82029faf9f896708df36e08e
|
|
BLAKE2b-256 checksum How to use checksums |
9808c5cf190e597ceaa5356fc85a9ad02b335536063efdd94b6c149064806188
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.9.6 Linux/5.8.0-1039-azure
|
Security for simple-sqla-timer 0.1.0
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.