Socket
Socket
Sign inDemoInstall

prefect-alert

Package Overview
Dependencies
15
Maintainers
1
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    prefect-alert

Decorator to send alert when a Prefect task or flow fails


Maintainers
1

Readme

prefect-alert

PyPI

Welcome!

Prefect is an open-source library that allows you to orchestrate and observe your dataflow defined in Python.

prefect-alert is a decorator that allows you to send alert when a Prefect flow fails.

Read this article if you are not familiar with how to send notifications with Prefect.

Getting Started

Python setup

Requires an installation of Python 3.8+.

We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.

The decorator is designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.

Installation

Install prefect-alert with pip:

pip install prefect-alert

Create a notification block

Blocks enable you to store configuration and provide an interface for interacting with external systems.

First, start with creating a notification block through UI or a Python script:

from prefect.blocks.notifications import SlackWebhook

slack_block = SlackWebhook(url="https://hooks.slack.com/services/XXX/XXX/XXX")

Send an alert

Next, use the block created and the decorator prefect_alert.alert_on_failure to send alert when a flow fails.

Send an alert when a flow fails
from prefect import flow, task 
from prefect.blocks.notifications import SlackWebhook
from prefect_alert import alert_on_failure

@task
def may_fail():
    raise ValueError()

@alert_on_failure(block_type=SlackWebhook, block_name="test")
@flow
def failed_flow():
    res = may_fail()
    return res

if __name__=="__main__":
    failed_flow()

And you will see something like this on your Slack:

Send an alert when a asynchronous flow fails
from prefect import flow, task 
from prefect.blocks.notifications import SlackWebhook
from prefect_alert import alert_on_failure
import asyncio

@task
async def may_fail():
    raise ValueError()

@alert_on_failure(block_type=SlackWebhook, block_name="test")
@flow
async def failed_flow():
    res = await may_fail()
    return res

if __name__=="__main__":
    asyncio.run(failed_flow())

Resources

If you encounter any bugs while using prefect-alert, feel free to open an issue in the prefect-alert repository.

If you have any questions or issues while using prefect-alert, you can find help in either the Prefect Discourse forum or the Prefect Slack community.

Feel free to ⭐️ or watch prefect-alert for updates too!

Development

If you'd like to install a version of prefect-alert for development, clone the repository and perform an editable install with pip:

git clone https://github.com/khuyentran1401/prefect-alert.git

cd prefect-alert/

pip install -e ".[dev]"

# Install linting pre-commit hooks
pre-commit install

Keywords

FAQs


Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc