Modules Reference

This is the reference of cantal_tools package modules.

WSGI metrics

werkzeug_serving

Module provides wrapper around werkzeug’s BaseWSGIServer.

class cantal_tools.werkzeug_serving.CantaledWSGIServer

Wrapper around BaseWSGIServer from werkzeug.serving

Usage:

import cantal
from cantal_tools import werkzeug_serving

cantal.start()

werkzeug_serving.CantaledWSGIServer(
    host='0.0.0.0',
    port=8080,
    ).server_forever()

Web metrics

flask

Module provides Flask application mixin overriding several methods for request tracing.

class cantal_tools.flask.FlaskMixin

Mixin overriding internal application’s methods

Parameters:metrics – Metrics instance

Usage:

import flask
import cantal
from cantal_tools.flask import FlaskMixin

class App(FlaskMixin, flask.Flask):
    pass

cantal.start()

app = App(__name__)
app.run()

Appflow metrics

redis

This module provides patch_redis function and a custom Connection class:

cantal_tools.redis.patch_redis(Redis)

patches execute_command method of supplied Redis class

Usage:

import cantal
import redis
from cantal_tools.redis import patch_redis

 cantal.start()

 patch_redis(redis.Redis)
 client = Redis(host='localhost', port=6379)
 client.get('some-key')

If you don’t like monkey-patching you can use the following connection class, however you’d need to instantiate redis.ConnectionPool yourself.

class cantal_tools.redis.CantaledConnection

Wrapper around redis.Connection


elasticsearch

class cantal_tools.elasticsearch.CantaledTransport

Wrapper around elasticsearch.Transport. Overrides perform_request method.


sqlalchemy

cantal_tools.sqlalchemy.attach_to_engine(engine)

Attaches listeners to before_cursor_execute and after_cursor_execute engine events.

Parameters:engine – SQLAlchemy db engine

Usage:

import cantal
import sqlalchemy as sa
from cantal_tools.sqlalchemy import attach_to_engine

cantal.start()

db_engine = sa.create_engine('sqlite:///db.sqlite')
attach_to_engine(db_engine)

django

cantal_tools.django.patch_models_manager(django.db.models.Manager)

Patches supplied django models django.db.models.Manager class (wraps get_queryset method).

Usage:

from cantal_tools.django import patch_models_manager
from django.db import models

# NOTE: we patch default manager!
patch_models_manager(models.Manager)