Star us on GitHub
Star
Menu

Python SDK API Reference

Python SDK

Highlight's Python SDK makes it easy to monitor errors and logs on your Python backend.

Just getting started?

Check out our getting started guide to get up and running quickly.

H()

H() initializes the Highlight backend SDK.

Method Parameters
In Flask, you'll add Highlight in your main app.py entrypoint.
import highlight_io from highlight_io.integrations.flask import FlaskIntegration app = Flask('test-app') H = highlight_io.H("YOUR_PROJECT_ID", integrations=[FlaskIntegration()], record_logs=True)
Copy
In Django, you'll add Highlight to your settings.py file:
import highlight_io from highlight_io.integrations.django import DjangoIntegration H = highlight_io.H("YOUR_PROJECT_ID", integrations=[DjangoIntegration()], record_logs=True)
Copy
In FastAPI, you'll add Highlight as a middleware:
import highlight_io from highlight_io.integrations.fastapi import FastAPIMiddleware H = highlight_io.H("YOUR_PROJECT_ID", record_logs=True) app = FastAPI() app.add_middleware(FastAPIMiddleware)
Copy

H.record_exception()

Record arbitrary exceptions raised within your app.

Method Parameters
try: for i in range(20): result = 100 / (10 - i) print(f'dangerous: {result}') except Exception as e: H.record_exception(e)
Copy

H.trace()

Catch exceptions raised by your app using this context manager. Exceptions will be recorded with the Highlight project and associated with a frontend session when headers are provided. Exceptions will be re-raised in case you want to have them propagate.

Method Parameters
with H.trace(): for idx in range(1000): logging.info(f"hello {idx}") time.sleep(0.001) if random.randint(0, 100) == 1: raise Exception(f"random error! {idx}") logging.warning("made it outside the loop!")
Copy