Skip to main content

Auditing and profiling multi-tool

Project description

Seagrass

PyPI package version Docs Build status

A Python event auditing and profiling multitool

Seagrass is a library providing fast, pluggable hooks for instrumenting Python code.

Installation

You can install the latest version of Seagrass using pip:

pip install seagrass

Introduction

At a low level, Seagrass is just a wrapper around Python's context managers and function decorators. Working in conjunction, these two features make it possible to instrument and attach context to arbitrary functions and blocks of code. However, at the far end it can be tedious to have to manage, configure, and toggle code hooks using just the standard library.

Seagrass provides a framework for developing hot-swappable hooks and managing them at scale. For instance, suppose you wanted to count the number of times a function was entered and see how much time was spent in it. You could use Seagrass's built-in CounterHook and TimerHook as follows:

import seagrass
from seagrass import Auditor
from seagrass.hooks import CounterHook, TimerHook

auditor = Auditor()
hooks = [CounterHook(), TimerHook()]

@auditor.audit(seagrass.auto, hooks=hooks)
def some_function_i_want_to_audit():
    ...

with auditor.start_auditing(log_results=True):
    some_function_i_want_to_audit()

Alternatively, you could use the ProfilerHook hook to get finer-grained performance statistics based on Python's cProfile module.

Seagrass really starts to shine once you start writing your own hooks through the ProtoHook interface, or using one of the lightly-configurable hooks such as LoggingHook or ContextManagerHook. You can write one set of hooks that transfer across multiple projects and toggle them on-demand, filter them by event name, attach logging context with them, and so on.

Check out the quickstart tutorial for a longer crash course on using Seagrass.

Documentation

The full documentation for Seagrass is available on ReadTheDocs: https://seagrass.readthedocs.io/en/stable/

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

seagrass-0.10.2.tar.gz (37.4 kB view details)

Uploaded Source

Built Distribution

seagrass-0.10.2-py3-none-any.whl (52.0 kB view details)

Uploaded Python 3

File details

Details for the file seagrass-0.10.2.tar.gz.

File metadata

  • Download URL: seagrass-0.10.2.tar.gz
  • Upload date:
  • Size: 37.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for seagrass-0.10.2.tar.gz
Algorithm Hash digest
SHA256 d7170717f54fea37b802a2f625331cc4b81b7e6e544c38a68cfaf07320a289c5
MD5 6fde01deb123666fb0cf124d7e7ebf4f
BLAKE2b-256 4007b0dcb39974fb57fadbe5edd1a244df5a4688e336df7712519be21e0a551f

See more details on using hashes here.

File details

Details for the file seagrass-0.10.2-py3-none-any.whl.

File metadata

  • Download URL: seagrass-0.10.2-py3-none-any.whl
  • Upload date:
  • Size: 52.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for seagrass-0.10.2-py3-none-any.whl
Algorithm Hash digest
SHA256 92fe39a32c335eaf7eb9f507c838ab0887bb5facb1bf51024a8d83afbec39865
MD5 c5b8cd03fd04ca00d9f5ec3250df6454
BLAKE2b-256 564dce6a502ab6b3f12344f574d867d2b9c3eaa790a5fc8c65cce1cc6a8fd707

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