{"id":13421625,"url":"https://github.com/airbrake/airbrake-python","last_synced_at":"2025-09-11T23:20:29.656Z","repository":{"id":14249485,"uuid":"16956940","full_name":"airbrake/airbrake-python","owner":"airbrake","description":"Airbrake Python","archived":false,"fork":false,"pushed_at":"2022-09-12T11:33:45.000Z","size":236,"stargazers_count":51,"open_issues_count":14,"forks_count":24,"subscribers_count":26,"default_branch":"master","last_synced_at":"2024-10-27T22:27:30.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/airbrake.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-18T17:17:59.000Z","updated_at":"2024-07-21T14:17:47.000Z","dependencies_parsed_at":"2022-08-19T16:50:16.662Z","dependency_job_id":null,"html_url":"https://github.com/airbrake/airbrake-python","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fairbrake-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fairbrake-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fairbrake-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/airbrake%2Fairbrake-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/airbrake","download_url":"https://codeload.github.com/airbrake/airbrake-python/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243718912,"owners_count":20336590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T23:00:27.239Z","updated_at":"2025-03-15T10:31:15.454Z","avatar_url":"https://github.com/airbrake.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://airbrake-github-assets.s3.amazonaws.com/brand/airbrake-full-logo.png\" width=\"200\"\u003e\n\u003c/p\u003e\n\nairbrake-python\n===============\n\n*Note*. Python 3.4+ are advised to use new [Airbrake Python notifier](https://github.com/airbrake/pybrake) which supports async API and code hunks. Python 2.7 users should continue to use this notifier.\n\n[Airbrake](https://airbrake.io/) integration for python that quickly and easily plugs into your existing code.\n\n```python\nimport airbrake\n\nlogger = airbrake.getLogger()\n\ntry:\n    1/0\nexcept Exception:\n    logger.exception(\"Bad math.\")\n\n```\nairbrake-python is used most effectively through its [logging](http://docs.python.org/2/library/logging.html) handler, and uses the [Airbrake V3 API](https://airbrake.io/docs/api/) for error reporting.\n\n### install\nTo install airbrake-python, run:\n```bash\n$ pip install -U airbrake\n```\n\n### setup\nThe easiest way to get set up is with a few environment variables:\n```bash\nexport AIRBRAKE_API_KEY=*****\nexport AIRBRAKE_PROJECT_ID=12345\nexport AIRBRAKE_ENVIRONMENT=dev\n```\nand you're done!\n\n\nOtherwise, you can instantiate your `AirbrakeHandler` by passing these values as arguments to the `getLogger()` helper:\n```python\nimport airbrake\n\nlogger = airbrake.getLogger(api_key=*****, project_id=12345)\n\ntry:\n    1/0\nexcept Exception:\n    logger.exception(\"Bad math.\")\n```\n\nBy default, airbrake will catch and send uncaught exceptions. To avoid this behaviour, use the send_uncaught_exc option:\n`logger = airbrake.getLogger(api_key=*****, project_id=12345, send_uncaught_exc=False)`\n\n### setup for Airbrake On-Premise and other compatible back-ends (e.g. Errbit)\n\nAirbrake [Enterprise](https://airbrake.io/enterprise) and self-hosted alternatives, such as [Errbit](https://github.com/errbit/errbit), provide a compatible API.\n\nYou can configure a different endpoint than the default (`https://api.airbrake.io`) by either:\n\n * Setting an environment variable:\n\n```bash\nexport AIRBRAKE_HOST=https://self-hosted.errbit.example.com/\n```\n\n * Or passing a `host` argument to the `getLogger()` helper:\n\n```python\nimport airbrake\n\nlogger = airbrake.getLogger(api_key=*****, project_id=12345, host=\"https://self-hosted.errbit.example.com/\")\n```\n\n#### adding the AirbrakeHandler to your existing logger\n```python\nimport logging\n\nimport airbrake\n\nyourlogger = logging.getLogger(__name__)\nyourlogger.addHandler(airbrake.AirbrakeHandler())\n```\n_by default, the `AirbrakeHandler` only handles logs level ERROR (40) and above_\n\n#### Additional Options\nMore options are available to configure this library.\n\nFor example, you can set the environment to add more context to your errors.\nOne way is by setting the AIRBRAKE_ENVIRONMENT env var.\n```\nexport AIRBRAKE_ENVIRONMENT=staging\n```\nOr you can set it more explicitly when you instantiate the logger.\n```python\nimport airbrake\n\nlogger = airbrake.getLogger(api_key=*****, project_id=12345, environment='production')\n```\n\nThe available options are:\n- environment, defaults to env var `AIRBRAKE_ENVIRONMENT`\n- host, defaults to env var `AIRBRAKE_HOST` or https://api.airbrake.io\n- root_directory, defaults to None\n- timeout, defaults to 5. (Number of seconds before each request times out)\n- send_uncaught_exc, defaults to True (Whether or not to send uncaught exceptions)\n\n#### giving your exceptions more context\n```python\nimport airbrake\n\nlogger = airbrake.getLogger()\n\ndef bake(**goods):\n    try:\n        temp = goods['temperature']\n    except KeyError as exc:\n        logger.error(\"No temperature defined!\", extra=goods)\n```\n\n#### Setting severity\n\n[Severity][what-is-severity] allows categorizing how severe an error is. By\ndefault, it's set to `error`. To redefine severity, simply `build_notice` with\nthe needed severity value. For example:\n\n```python\nnotice = airbrake.build_notice(exception, severity=\"critical\")\nairbrake.notify(notice)\n```\n\n### Using this library without a logger\n\nYou can create an instance of the notifier directly, and send\nerrors inside exception blocks.\n```python\nfrom airbrake.notifier import Airbrake\n\nab = Airbrake(project_id=1234, api_key='fake')\n\ntry:\n    amazing_code()\nexcept ValueError as e:\n    ab.notify(e)\nexcept:\n    # capture all other errors\n    ab.capture()\n```\n\n\n#### Running Tests Manually\nCreate your environment and install the test requirements\n```\nvirtualenv venv\nsource venv/bin/activate\npip install .\npython setup.py test\n```\n\nTo run via nose (unit/integration tests):\n```\nsource venv/bin/activate\npip install -r ./test-requirements.txt\nsource venv/bin/activate\nnosetests\n```\n\nRun all tests, including multi-env syntax, and coverage tests.\n```\npip install tox\ntox -v --recreate\n```\n\nIt's suggested to make sure tox will pass, as CI runs this.\ntox needs to pass before any PRs are merged.\n\n-----------------\n\nThe [airbrake.io](https://airbrake.io/) api docs used to implement airbrake-python are here:\nhttps://airbrake.io/docs/api/\n\n[[what-is-severity]: https://airbrake.io/docs/airbrake-faq/what-is-severity/]\n","funding_links":[],"categories":["Exception tracking"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairbrake%2Fairbrake-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fairbrake%2Fairbrake-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fairbrake%2Fairbrake-python/lists"}