{"id":2754,"library":"rollbar","title":"Rollbar Python SDK","description":"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.","status":"active","version":"1.3.0","language":"en","source_language":"en","source_url":"https://github.com/rollbar/pyrollbar/","tags":["error-tracking","monitoring","logging","observability","exceptions"],"install":[{"cmd":"pip install rollbar","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Initializes the Rollbar SDK with configuration.","wrong":"from rollbar import init # while technically possible, typically rollbar is imported as a module and init called on it for clarity.","symbol":"init","correct":"import rollbar\nrollbar.init(...)"},{"note":"Reports the current exception info to Rollbar.","symbol":"report_exc_info","correct":"import rollbar\nrollbar.report_exc_info()"},{"note":"Reports a simple message to Rollbar.","symbol":"report_message","correct":"import rollbar\nrollbar.report_message('Hello Rollbar!')"},{"note":"Logging handler for integrating with Python's standard logging module.","symbol":"RollbarHandler","correct":"from rollbar.logger import RollbarHandler"}],"quickstart":{"code":"import rollbar\nimport os\n\n# Configure Rollbar\nrollbar.init(\n    access_token=os.environ.get('ROLLBAR_ACCESS_TOKEN', 'YOUR_ROLLBAR_ACCESS_TOKEN'),\n    environment='development',\n    root=os.path.dirname(os.path.abspath(__file__))\n)\n\ndef main():\n    try:\n        raise ValueError(\"This is a test error from Rollbar Python SDK!\")\n    except Exception:\n        rollbar.report_exc_info()\n        print(\"Error reported to Rollbar.\")\n\n    rollbar.report_message(\"Application started successfully.\", level='info')\n    print(\"Message reported to Rollbar.\")\n\n    # In a real application, ensure background threads have time to send data\n    # before exiting. For simple scripts, you might need rollbar.wait().\n    # rollbar.wait()\n\nif __name__ == '__main__':\n    main()","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to version 3.7 or higher. Rollbar Python SDK v1.3.0 supports Python 3.7 to 3.13.","message":"Support for Python 3.6 was removed in Rollbar Python SDK v1.3.0. Installations on Python 3.6 will fail or encounter issues.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Ensure `rollbar.init()` is called once at the start of your application's lifecycle with correct `access_token` and `environment` values.","message":"The `rollbar.init()` call must occur before any `rollbar.report_*` functions are called. Incorrect or missing `access_token` or `environment` parameters will prevent reports from being sent.","severity":"gotcha","affected_versions":"All"},{"fix":"For applications that terminate quickly, call `rollbar.wait()` to ensure all buffered items are sent before the process exits. For web applications, this is typically handled by the framework integration.","message":"Rollbar uses background threads to send reports asynchronously. If your application exits immediately after an error, reports may not be sent. For command-line scripts or short-lived processes, `rollbar.wait()` might be necessary before exit.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review the data being sent to Rollbar. If truncation is an issue, consider adjusting configuration options like `locals_max_size` or implementing custom payload transforms (v1.2.0+) to filter sensitive or excessively large data.","message":"Reports with very large payloads (e.g., huge local variables or deep call stacks) may be truncated due to size limits. The SDK has internal shortening logic (improved in v1.1.0-alpha).","severity":"gotcha","affected_versions":"All"},{"fix":"Consult the Rollbar documentation for your specific web framework and implement the recommended integration (e.g., `rollbar.contrib.django.middleware.RollbarMiddleware`).","message":"For popular web frameworks (Django, Flask, FastAPI, Pyramid), it's highly recommended to use the dedicated Rollbar integrations (e.g., middleware) rather than just `rollbar.init()`. These integrations handle context, request data, and proper error capturing within the framework's lifecycle.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}