Typer for Python

Learn how to use Sentry to capture Typer exceptions.

The TyperIntegration captures exceptions raised when using Typer CLI applications.

Install Typer and the Sentry Python SDK.

Copied
pip install "sentry-sdk" "typer"

To enable the TyperIntegration, add it to the integrations list of your sentry_sdk.init.

Copied
import sentry_sdk
from sentry_sdk.integrations.typer import TyperIntegration

sentry_sdk.init(
    dsn="___PUBLIC_DSN___",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    integrations=[TyperIntegration()],
)

Create a small CLI application:

Copied
import typer
import sentry_sdk
from sentry_sdk.integrations.typer import TyperIntegration

sentry_sdk.init(...)  # see above

def main():
    1 / 0

if __name__ == "__main__":
    typer.run(main)

When you run this, Sentry will capture the ZeroDivisionError from the main() function and you'll be able to see it on sentry.io.

Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").