{"id":22410603,"url":"https://github.com/potatohd404/py-exceptions","last_synced_at":"2025-03-27T02:42:24.440Z","repository":{"id":62580232,"uuid":"394723017","full_name":"PotatoHD404/py-exceptions","owner":"PotatoHD404","description":"A simple python exception reporter","archived":false,"fork":false,"pushed_at":"2021-08-19T08:43:51.000Z","size":746,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T01:46:42.172Z","etag":null,"topics":["aws-lambda","python","serverless"],"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/PotatoHD404.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-10T17:08:36.000Z","updated_at":"2022-02-03T23:02:44.000Z","dependencies_parsed_at":"2022-11-03T20:49:35.871Z","dependency_job_id":null,"html_url":"https://github.com/PotatoHD404/py-exceptions","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoHD404%2Fpy-exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoHD404%2Fpy-exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoHD404%2Fpy-exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PotatoHD404%2Fpy-exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PotatoHD404","download_url":"https://codeload.github.com/PotatoHD404/py-exceptions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245772983,"owners_count":20669718,"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":["aws-lambda","python","serverless"],"created_at":"2024-12-05T13:09:48.510Z","updated_at":"2025-03-27T02:42:24.416Z","avatar_url":"https://github.com/PotatoHD404.png","language":"Python","readme":"# py-exceptions [![PyPI version](https://badge.fury.io/py/py-exceptions.svg)](https://badge.fury.io/py/py-exceptions)\n\n## *A simple python exception reporter*\n\n### Description\n\nThis library provides great stacktrace and web request information like Django does It can save it to html, return html\nto your code or even response in AWS lambda format\n\nThe library nicely covers all your secret variables and request data in its report\n\n### Screenshots\n\n![Beautiful image](https://raw.githubusercontent.com/potatohd404/py-exceptions/master/images/demo.png)\n\n![Another beautiful image](https://raw.githubusercontent.com/potatohd404/py-exceptions/master/images/demo2.png)\n\n## Quickstart\n\n### Installation\n\n```sh\npip install py-exception\n```\n\n### Simple example\n\nAdd decorator to function\n\n```python\nfrom pyexceptions import handle_exceptions\n\n\ndef divide(a, b):\n    return a / b\n\n\n@handle_exceptions\ndef main():\n    i = 5\n    j = 0\n    c = divide(i, j)\n    print(c)\n\n\nif __name__ == '__main__':\n    main()\n```\n\nYou can also override folder for exception reports\n\n```python\nfrom pyexceptions import handle_exceptions\n\n\ndef divide(a, b):\n    return a / b\n\n\n@handle_exceptions(exceptions_folder=f'./SomeFolderPath')\ndef main():\n    i = 5\n    j = 0\n    c = divide(i, j)\n    print(c)\n\n\nif __name__ == '__main__':\n    main()\n```\n\n### AWS Lambda example\n\nIt is hard to determine what's went wrong when you are using AWS lambda. So you can use the example not only to get full\nstacktrace but to get lambda event and context information:\n\n```python\nfrom pyexceptions import handle_exceptions\n\n\n@handle_exceptions(is_lambda=True)\ndef lambda_handler(event, context):\n    message = f\"Hello {event['first_name']} {event['last_name']}!\"\n    return {\n        'message': message\n    }\n```\n\n### Exclude from stacktrace\n\nThere may be situations when you don't want to see part of stacktrace\n\nSo if your application looks like this:\n\n```python\nfrom pyexceptions import handle_exceptions\n\ndef divide(a, b):\n    return a / b\n\ndef real_main():\n    i = 5\n    j = 0\n    c = divide(i, j)\n    print(c)\n    \ndef wrapper():\n    real_main()\n\n@handle_exceptions(exclude = 3)\ndef main():\n    wrapper()\n\nif __name__ == '__main__':\n    main()\n```\n\nand you want to exclude all stacktrace from main to wrapper\nyou need to pass `file_name.function_name` as exclude argument\n\n### Other functions\n\nYou can also want to use these functions:\n\nMake function that returns HTML and don't save the result:\n\n```python\nfrom pyexceptions import handle_exceptions\n\n\n@handle_exceptions(save=False)\ndef main():\n    ...\n```\n\n\nMake function return production html:\n\n```python\nfrom pyexceptions import handle_exceptions\n\n\n@handle_exceptions(production=True)\ndef main():\n    ...\n```\n\n![Beautiful image](https://raw.githubusercontent.com/potatohd404/py-exceptions/master/images/demo3.png)\n\n\nOr you may want to write your own logic To do so you need to import the ExceptionHandler class\n\n```python\nfrom pyexceptions import ExceptionHandler\n```\n\nThat's how it looks like:\n\n```python\n\nclass ExceptionHandler:\n    \"\"\"Organize and coordinate reporting on exceptions.\"\"\"\n\n    def __init__(self, lambda_event: dict = None, context: object = None, exclude: int = 1, production: bool = False):\n        \"\"\"Exception reporter initializer\n\n        Args:\n            lambda_event (dict, optional): AWS lambda event. Defaults to None.\n            context (object, optional): AWS lambda context. Defaults to None.\n            exclude (int, optional): Determines how many frames of traceback to exclude. Defaults None.\n            production (bool, optional): Determines if handler should be enabled. Defaults False.\n        \"\"\"\n        self.__reporter = ExceptionReporter(lambda_event=lambda_event, context=context, exclude=exclude, # noqa\n                                            production=production)\n\n    def get_traceback_html(self):\n        \"\"\"Return HTML version of debug 500 HTTP error page.\"\"\"\n        return self.__reporter.get_traceback_html()\n\n    def get_traceback_lambda(self):\n        \"\"\"Return AWS lambda version of debug 500 HTTP error page.\"\"\"\n        return self.__reporter.get_lambda_response()\n```\n\n## Attribution\n\nThis implementation draws upon work from:\n\n- [Django](https://github.com/django/django)\n\n- [vercel-python-wsgi](https://github.com/ardnt/vercel-python-wsgi)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatohd404%2Fpy-exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpotatohd404%2Fpy-exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpotatohd404%2Fpy-exceptions/lists"}