Skip to main content

Context manager to upload explain plans to https://explain.dalibo.com/

Project description

Django Postgres Explain Visualizer (Django-PEV)

PyPI version versions Lint

This tool captures sql queries and uploads the query plan to postgresql explain visualizer (PEV) by dalibo. This is especially helpful for debugging slow queries.

Usage

Wrap some code with the explain context manager. All sql queries are captured alongside a stacktrace (to locate where it was called). The slowest query is accessible via .slowest.

import django_pev

with django_pev.explain(
    title="Analyzing slow User join"
) as e:
    # Every SQL query is captured
    list(User.objects.filter(some__long__join=1).all())

# Rerun the slowest query with `EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)`
pev_response = e.slowest.visualize(
    # By default the text of the query is not uploaded for security reasons
    upload_query=True,
)
print(pev_response.url)

# View the visualization
e.slowest.visualize_in_browser()


# Delete the plan hosted on https://explain.dalibo.com
pev_response.delete()

Debugging a slow endpoint

import django_pev

from django.test import Client as TestClient

client = TestClient()

with django_pev.explain() as e:
    url = "/some_slow_url"
    response = client.get(url)

print(e.slowest.visualize())

Disclaimer

Credit goes to Pierre Giraud (@pgiraud) for PEV2 and Alex Tatiyants (@AlexTatiyants) for the original pev tool.

IN NO EVENT SHALL DALIBO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF DALIBO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

DALIBO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND DALIBO HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_pev-0.1.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

django_pev-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file django_pev-0.1.1.tar.gz.

File metadata

  • Download URL: django_pev-0.1.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.2 Darwin/21.3.0

File hashes

Hashes for django_pev-0.1.1.tar.gz
Algorithm Hash digest
SHA256 06d94c868b872ac7cd1aece4231528d110ddf504af2372f089cb862648fb3410
MD5 1f51a7076bded4d3db49bff8f5504ee9
BLAKE2b-256 49afcc790a19c84ef8077e90b9572ff96565ea6655ef670e58ec3b74cbd79a3d

See more details on using hashes here.

File details

Details for the file django_pev-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_pev-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.2 Darwin/21.3.0

File hashes

Hashes for django_pev-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65125a649808da4c46ec180eafa0a5531700b74f68deee4f4d0b185eef8cf717
MD5 8fa63133cf683234308e37c5a8109d40
BLAKE2b-256 1fb8e44f307e62488848e41ea97b911ca5abe770e5b732eead9d6d4c0cb92fd6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page