Rollbar Python SDK

1.3.0 · active · verified Fri Apr 10

Rollbar Python SDK (pyrollbar) provides easy and powerful exception tracking with Rollbar. It allows sending messages and exceptions with arbitrary context, enabling aggregation and quick debugging of production issues. The current stable version is 1.3.0, with active development including regular minor and patch releases, and support for newer Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Rollbar SDK and report both an exception and a simple message. Remember to replace 'YOUR_ROLLBAR_ACCESS_TOKEN' with your actual token, preferably via an environment variable. For background thread reports to complete on exit, consider `rollbar.wait()` if the application terminates quickly.

import rollbar
import os

# Configure Rollbar
rollbar.init(
    access_token=os.environ.get('ROLLBAR_ACCESS_TOKEN', 'YOUR_ROLLBAR_ACCESS_TOKEN'),
    environment='development',
    root=os.path.dirname(os.path.abspath(__file__))
)

def main():
    try:
        raise ValueError("This is a test error from Rollbar Python SDK!")
    except Exception:
        rollbar.report_exc_info()
        print("Error reported to Rollbar.")

    rollbar.report_message("Application started successfully.", level='info')
    print("Message reported to Rollbar.")

    # In a real application, ensure background threads have time to send data
    # before exiting. For simple scripts, you might need rollbar.wait().
    # rollbar.wait()

if __name__ == '__main__':
    main()

view raw JSON →