Python SDK - FastAPI & Flask
FastAPI and Flask. Requires Python 3.9+.
Install
pip install kohi-python python-dotenvAdd to .env:
KOHI_PROJECT_KEY=pk_your_project_keyKOHI_SECRET_KEY=your_secret_keyFastAPI
Monitor() goes right after app = FastAPI() and must be before any @app.get/@app.post route definitions.
import osfrom dotenv import load_dotenvfrom fastapi import FastAPIfrom kohi import Monitor
load_dotenv()
app = FastAPI()
monitor = Monitor( app, project_key=os.getenv("KOHI_PROJECT_KEY"), secret_key=os.getenv("KOHI_SECRET_KEY"),)Flask
Monitor() goes right after app = Flask(__name__) and must be before any @app.route definitions.
import osfrom dotenv import load_dotenvfrom flask import Flaskfrom kohi import Monitor
load_dotenv()
app = Flask(__name__)
monitor = Monitor( app, project_key=os.getenv("KOHI_PROJECT_KEY"), secret_key=os.getenv("KOHI_SECRET_KEY"),)Error tracking
Uncaught exceptions and 5xx responses are captured automatically in both FastAPI and Flask. Thread-level exceptions are also caught via threading.excepthook.
To capture errors manually (store the Monitor() return value as shown above):
try: risky_operation()except Exception as exc: monitor.capture_exception(exc)capture_exception(exc, fingerprint="custom-id") records the exception type, message, and full traceback. The optional fingerprint keyword groups related errors. 5xx responses and unhandled exceptions are captured automatically.
See configuration reference for all available options, security & privacy for redacted fields, or troubleshooting if something isn’t working.