Skip to main content

errorgap

Python notifier for Errorgap. Captures exceptions, normalizes tracebacks with bounded source excerpts for readable frames, and ships notices to an Errorgap server. Single package covers plain Python, Django, Flask, and FastAPI.

Install

pip install errorgap

For framework integrations:

pip install "errorgap[django]"   # or [flask], [fastapi]

Requires Python 3.9+.

Configure

import errorgap

errorgap.init(
    endpoint=...,
    project_slug=...,
    api_key=...,
    environment="production",
)

init reads the same values from ERRORGAP_ENDPOINT, ERRORGAP_PROJECT_SLUG, ERRORGAP_PROJECT_ID, and ERRORGAP_API_KEY if you don't pass them. By default it installs a sys.excepthook to catch uncaught exceptions in scripts; pass capture_globals=False to skip.

Manual notification

try:
    risky()
except Exception as exc:
    errorgap.notify(exc, context={"component": "billing"})
    raise

notify returns a DeliveryResult (status, body, error, queued). The SDK never raises.

Django

Add to MIDDLEWARE:

MIDDLEWARE = [
    "errorgap.django.ErrorgapMiddleware",
    # ... your existing middleware ...
]

Flask

from flask import Flask
from errorgap.flask import init_app

app = Flask(__name__)
init_app(app)

init_app also times each request as an APM transaction (sent with apm_enabled=True) grouped by its URL rule (/orders/<int:id>), and errors raised during the request carry its transaction id. Record spans from a view with errorgap.flask.spans():

from errorgap.flask import spans

@app.route("/orders/<int:order_id>")
def order(order_id):
    started = time.perf_counter()
    row = db.execute("SELECT * FROM orders WHERE id = %s", (order_id,)).fetchone()
    spans().database("SELECT * FROM orders WHERE id = %s", (time.perf_counter() - started) * 1000)
    return row

WSGI

Any WSGI app gets the same request transactions from errorgap.wsgi.ErrorgapMiddleware. Set environ["errorgap.route"] to the matched route template to group requests (otherwise the raw path is used).

from errorgap.wsgi import ErrorgapMiddleware

application = ErrorgapMiddleware(application)

Transactions and jobs

with errorgap.track_transaction("GET", "/orders/{id}", "/orders/123") as txn:
    txn.spans.database("SELECT * FROM orders WHERE id = 123", 4.2)
    txn.status_code = 200

with errorgap.track_job("ReceiptJob", queue="mailers") as txn:
    send_receipt()

Both time the block and deliver on exit even if it raises. Errors reported inside carry the transaction id (context.transaction_id), so errorgap shows the error a request raised on its trace. The id lives in a ContextVar, so concurrent threads and asyncio tasks never share one; errorgap.current_transaction_id() returns the id in effect.

When the errorgap browser SDK (@errorgap/browser 0.3+) is on the page, its API calls send an x-errorgap-trace header. The WSGI middleware (and so init_app) records it, and track_transaction(..., trace_id=header) accepts it, so errorgap's browser Performance view links each call to the server request that answered it. Malformed values are ignored.

FastAPI

from fastapi import FastAPI
from errorgap.fastapi import ErrorgapMiddleware

app = FastAPI()
app.add_middleware(ErrorgapMiddleware)

Configuration reference

Argument Default Notes
endpoint ERRORGAP_ENDPOINT or http://127.0.0.1:3030 Base URL, no trailing slash
project_slug ERRORGAP_PROJECT_SLUG Required
project_id ERRORGAP_PROJECT_ID Optional, embedded in payload
api_key ERRORGAP_API_KEY Sent as x-errorgap-project-key
environment ERRORGAP_ENVIRONMENT, ENV, or development
root_directory os.getcwd() Marks application frames; readable dependency frames also include bounded source excerpts
async_ True Background-thread delivery
logger logging.getLogger("errorgap") Pass None to silence
filter_keys ("password", "token", ...) Substring match, case-insensitive
apm_enabled False Send APM transactions
apm_sample_rate 1.0 Fraction of transactions sent (errors are unaffected)
capture_globals True Install sys.excepthook

Graceful shutdown

errorgap.flush(timeout=5)     # wait for queued deliveries
errorgap.shutdown(timeout=5)  # flush + tear down background thread

Verify

curl -sS -X POST "$ERRORGAP_ENDPOINT/api/projects/$ERRORGAP_PROJECT_SLUG/notices" \
  -H "content-type: application/json" \
  -H "x-errorgap-project-key: $ERRORGAP_API_KEY" \
  -d '{"errors":[{"type":"ErrorgapInstallTest","message":"Errorgap install verification"}],"context":{"environment":"development"}}'

Then trigger a real error and confirm it appears in the Errorgap UI.

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT.

Metadata

Release files for errorgap 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for errorgap 0.2.0
File Size Uploaded Provenance Actions
errorgap-0.2.0.tar.gz 19.4 kB With provenance Details for errorgap-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for errorgap 0.2.0
File Interpreter ABI Platform Actions
errorgap-0.2.0-py3-none-any.whl Python 3 none any Details for errorgap-0.2.0-py3-none-any.whl

Total release size: 38.7 kB

Release files / errorgap-0.2.0.tar.gz

Download URL errorgap-0.2.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
92608b2afeb05979ded6562a5ded76156f9b6a7d73cbb58ddc862cbf978a3ea4
BLAKE2b-256 checksum
How to use checksums
65bcf0ee0efdca64bb313224e2023f7cfa4f450b8564524fb9a682c933962e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Release files / errorgap-0.2.0-py3-none-any.whl

Download URL errorgap-0.2.0-py3-none-any.whl
Size 19.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95d10b5c0f63d1624749fa19e1490ca7fc49d5f84812492bba028cbc800e94ac
BLAKE2b-256 checksum
How to use checksums
8c48b75d1afe410879fbff6a464c1426b7b11cda80500cba71bc37b2e7e23fa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

Security for errorgap 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for errorgap-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page