{"id":25488022,"url":"https://github.com/mwja/python-tri","last_synced_at":"2026-04-22T18:51:03.643Z","repository":{"id":51997230,"uuid":"365490969","full_name":"mwja/python-tri","owner":"mwja","description":"Prettier error handling for Python","archived":false,"fork":false,"pushed_at":"2021-07-02T17:36:30.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-12-03T05:27:04.266Z","etag":null,"topics":["error-handling","pip","pypi","pypi-package","python","python-3","python3"],"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/mwja.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":"2021-05-08T10:57:27.000Z","updated_at":"2021-09-09T00:37:25.000Z","dependencies_parsed_at":"2022-09-12T14:32:36.536Z","dependency_job_id":null,"html_url":"https://github.com/mwja/python-tri","commit_stats":null,"previous_names":["starsflower/python-tri","jacobmacweb/python-tri","mwja/python-tri","raclettes/python-tri"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mwja/python-tri","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpython-tri","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpython-tri/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpython-tri/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpython-tri/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mwja","download_url":"https://codeload.github.com/mwja/python-tri/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mwja%2Fpython-tri/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32150396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-22T17:06:48.269Z","status":"ssl_error","status_checked_at":"2026-04-22T17:06:19.037Z","response_time":58,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["error-handling","pip","pypi","pypi-package","python","python-3","python3"],"created_at":"2025-02-18T20:39:10.194Z","updated_at":"2026-04-22T18:51:03.382Z","avatar_url":"https://github.com/mwja.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tri/bi\nThis package provides wrappers around functions that nicely handle errors. Reducing code clutter and allowing better responses to uses. This package is inspired by [tri-fp](https://www.npmjs.com/package/tri-fp)\n\n[![](https://img.shields.io/pypi/v/tribi.svg)](https://pypi.org/project/tribi/)\n[![](https://img.shields.io/pypi/implementation/tribi.svg)](https://pypi.org/project/tribi/)\n\n## Tri\nTri still lets native exceptions (usually more severe errors) throw, but catches any other errors\n```python\n\u003e\u003e\u003e from tri import tri, bi\n\u003e\u003e\u003e def my_function():\n...    return 1 / 0 # Zero division error!\n\n\u003e\u003e\u003e # This function raises a \"native\" exception\n\u003e\u003e\u003e tri(my_function)()\nTraceback (most recent call last):\n   ...\nZeroDivisionError: division by zero\n\n\u003e\u003e\u003e def my_other_function():\n...    raise Exception\n\n\u003e\u003e\u003e # This only raises a standard exception, so doesn't fail\n\u003e\u003e\u003e tri(my_other_function)()\n(Exception(), None)\n```\n\n\n### Bi\nBi, on the contrary, handles all errors blindly. This should only be used if you know what you're doing.\n```python\n\u003e\u003e\u003e bi(my_function)()\n(ZeroDivisionError('division by zero'), None)\n```\n\n\n## Async\nBoth `tri` and `bi` support async.\n\n### Tri\n```python\n\u003e\u003e\u003e # Assuming running in async\n\u003e\u003e\u003e from tri import atri, abi\n\u003e\u003e\u003e async def divide(a, b):\n...     return a / b\n\n\u003e\u003e\u003e # Let's try to divide by zero\n\u003e\u003e\u003e await atri(divide(1, 0))\nTraceback (most recent call last):\n   ...\nZeroDivisionError: division by zero\n\n\u003e\u003e\u003e # And with abi?\n\u003e\u003e\u003e await abi(divide(1, 0))\n(ZeroDivisionError('division by zero'), None)\n\n\u003e\u003e\u003e # If the function takes no params, we can just pass the function name\n\u003e\u003e\u003e async def func():\n...     return \"hello\"\n\n\u003e\u003e\u003e await atri(func)\n(None, \"hello\")\n```\n\n\n## Real life example\nSome examples include...\n\n### Safer JSON loading\n```python\nfrom tri import bi\n\nsafer_loads = bi(json.loads)\nerror, result = safer_loads(data)\n\nif error:\n   # Error handling JSON\n   print(\"Invalid JSON\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwja%2Fpython-tri","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmwja%2Fpython-tri","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmwja%2Fpython-tri/lists"}