{"id":21760628,"url":"https://github.com/khuyentran1401/prefect-alert","last_synced_at":"2025-04-13T12:50:47.394Z","repository":{"id":61835824,"uuid":"555004843","full_name":"khuyentran1401/prefect-alert","owner":"khuyentran1401","description":"A decorator that sends alert when a Prefect flow fails","archived":false,"fork":false,"pushed_at":"2023-04-05T05:07:43.000Z","size":1005,"stargazers_count":14,"open_issues_count":5,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T22:03:14.301Z","etag":null,"topics":["data","data-engineering","data-science","prefect","python"],"latest_commit_sha":null,"homepage":"https://khuyentran1401.github.io/prefect-alert/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khuyentran1401.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-20T19:32:14.000Z","updated_at":"2025-04-06T18:48:51.000Z","dependencies_parsed_at":"2024-11-26T11:44:59.517Z","dependency_job_id":"84b26d7c-f59b-4dae-bed8-92db6e93dcc5","html_url":"https://github.com/khuyentran1401/prefect-alert","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":0.12,"last_synced_commit":"0616a3c69628047b688f08c315ef22e47dc00955"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khuyentran1401%2Fprefect-alert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khuyentran1401%2Fprefect-alert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khuyentran1401%2Fprefect-alert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khuyentran1401%2Fprefect-alert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khuyentran1401","download_url":"https://codeload.github.com/khuyentran1401/prefect-alert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248717252,"owners_count":21150388,"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":["data","data-engineering","data-science","prefect","python"],"created_at":"2024-11-26T11:44:52.991Z","updated_at":"2025-04-13T12:50:47.357Z","avatar_url":"https://github.com/khuyentran1401.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# prefect-alert\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://pypi.python.org/pypi/prefect-alert/\" alt=\"PyPI version\"\u003e\n        \u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/prefect-alert?color=0052FF\u0026labelColor=090422\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://prefect-community.slack.com\" alt=\"Slack\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF\u0026labelColor=090422\u0026logo=slack\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://discourse.prefect.io/\" alt=\"Discourse\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF\u0026labelColor=090422\u0026logo=discourse\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Welcome!\n\n[Prefect](https://www.prefect.io/) is an open-source library that allows you to orchestrate and observe your dataflow defined in Python.\n\nprefect-alert is a decorator that allows you to send an alert when a Prefect flow fails.\n\nRead [this article](https://medium.com/the-prefect-blog/sending-slack-notifications-in-python-with-prefect-840a895f81c?sk=ab9bba5b59c8f3468bb01cabe04b2953) if you are not familiar with how to send notifications with Prefect. \n\n## Getting Started\n### Python setup\n\nRequires an installation of Python 3.8+.\n\nWe recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.\n\nThe decorator is designed to work with Prefect 2. For more information about how to use Prefect, please refer to the [Prefect documentation](https://orion-docs.prefect.io/).\n\n### Installation\n\nInstall `prefect-alert` with `pip`:\n\n```bash\npip install prefect-alert\n```\n### Create a notification block\n[Blocks](https://docs.prefect.io/concepts/blocks/) enable you to store configuration and provide an interface for interacting with external systems. \n\nFirst, start with creating a [notification block](https://docs.prefect.io/api-ref/prefect/blocks/notifications/) through [UI](https://docs.prefect.io/ui/blocks/) or a Python script:\n\n```python\nfrom prefect.blocks.notifications import SlackWebhook\n\nslack_block = SlackWebhook(url=\"https://hooks.slack.com/services/XXX/XXX/XXX\")\nslack_block.save(name=\"test\")\n``` \n### Send an alert\nNext, use the block created and the decorator `prefect_alert.alert_on_failure` to send alert when a flow fails.\n#### Send an alert when a flow fails\n\n```python\nfrom prefect import flow, task \nfrom prefect.blocks.notifications import SlackWebhook\nfrom prefect_alert import alert_on_failure\n\n@task\ndef may_fail():\n    raise ValueError()\n\n@alert_on_failure(block_type=SlackWebhook, block_name=\"test\")\n@flow\ndef failed_flow():\n    res = may_fail()\n    return res\n\nif __name__==\"__main__\":\n    failed_flow()\n```\nAnd you will see something like this on your Slack:\n![](img/slack-notification.png)\n\n#### Send an alert when an asynchronous flow fails\n\n```python\nfrom prefect import flow, task \nfrom prefect.blocks.notifications import SlackWebhook\nfrom prefect_alert import alert_on_failure\nimport asyncio\n\n@task\nasync def may_fail():\n    raise ValueError()\n\n@alert_on_failure(block_type=SlackWebhook, block_name=\"test\")\n@flow\nasync def failed_flow():\n    res = await may_fail()\n    return res\n\nif __name__==\"__main__\":\n    asyncio.run(failed_flow())\n```\n## Resources\n\nIf you encounter any bugs while using `prefect-alert`, feel free to open an issue in the [prefect-alert](https://github.com/khuyentran1401/prefect-alert) repository.\n\nIf you have any questions or issues while using `prefect-alert`, you can find help in either the [Prefect Discourse forum](https://discourse.prefect.io/) or the [Prefect Slack community](https://prefect.io/slack).\n\nFeel free to ⭐️ or watch [`prefect-alert`](https://github.com/khuyentran1401/prefect-alert) for updates too!\n\n## Development\n\nIf you'd like to install a version of `prefect-alert` for development, clone the repository and perform an editable install with `pip`:\n\n```bash\ngit clone https://github.com/khuyentran1401/prefect-alert.git\n\ncd prefect-alert/\n\npip install -e \".[dev]\"\n\n# Install linting pre-commit hooks\npre-commit install\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhuyentran1401%2Fprefect-alert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhuyentran1401%2Fprefect-alert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhuyentran1401%2Fprefect-alert/lists"}