CControxity Docs
GuidesReferenceHTTP APIOpen Controxity
Platforms

Python

Flask, FastAPI, Starlette, Django or plain Python 3.9 and newer. No dependencies.

1. Install#

The SDK is one file, kept with your code (it isn't on PyPI yet). In your server's folder, with your Controxity's address:

curl -fsSL https://controxity.example.com/sdk/python.py -o controxity.py

import controxity then finds it beside your code.

Get a key under Where it runs → Add a place and keep it in CONTROXITY_KEY.

2. Start it, as early as you can#

import os, controxity

controxity.init(os.environ["CONTROXITY_KEY"], os.environ["CONTROXITY_URL"], version="1.4.2")

3. Connect your framework#

Don't skip this. Frameworks catch your routes' errors and answer with a 500, so Controxity never sees them without this line.
controxity.flask(app)        # older Flask also needs: pip install blinker

4. Check it works#

print(controxity.check())   # (True, "Connected to controxity.example.com")

Then make one route raise: it's on Problems within a minute.

The hooks send the request's route, params and query with each error, as steps and a shape (Flask and Django: its body too). Each request keeps its own steps.

5. Ship safely (optional)#

# What must always be true. A broken one is a problem, but nothing is raised:
controxity.expect("total-not-negative", total >= 0, input={"cart": cart})

# New or risky code, off until a person turns it on, and off again by itself if it hurts:
if controxity.flag("new-checkout", id=user.id):
    return new_checkout(cart)

# A step worth seeing before an error (routes, calls out and events are noted by themselves):
controxity.step("cart.loaded")

Expectations · Switches · Steps before an error. In CI: Releases from CI.

Also useful#

controxity.capture_error(error, where="orders")        # an error you caught
controxity.health("database", False, "high")           # down; health("database", True) clears it
controxity.event("payment_failed")                     # counted
controxity.report(title="Booking failed", what=text)   # what a person told you
controxity.problems()                                  # where your errors stand

Every function, with what it sends: Python SDK reference.

Is it up?#

It sends a heartbeat once a minute. If they stop for 3 minutes, the server shows Down. shutdown(), called by itself when Python exits normally, says it's stopping on purpose. In a script that isn't a server, pass heartbeat=False.

If nothing shows up#

Turning things off#

Argument of init()Off means
capture_input=FalseNo input shapes
breadcrumbs=FalseNo steps
capture_uncaught=FalseUncaught exceptions aren't reported
heartbeat=FalseNo heartbeat (not a server)
Controxity 1.132.0These pages are in the repository: docs/site