Name | prefect-email JSON |
Version |
0.3.3
JSON |
| download |
home_page | None |
Summary | Prefect integrations for interacting with email. |
upload_time | 2024-04-25 19:22:41 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | Apache License 2.0 |
keywords |
prefect
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# prefect-email
<p align="center">
<a href="https://pypi.python.org/pypi/prefect-email/" alt="PyPI version">
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-email?color=0052FF&labelColor=090422"></a>
<a href="https://pepy.tech/badge/prefect-email/" alt="Downloads">
<img src="https://img.shields.io/pypi/dm/prefect-email?color=0052FF&labelColor=090422" /></a>
</p>
Visit the full docs [here](https://PrefectHQ.github.io/prefect-email) to see additional examples and the API reference.
`prefect-email` is a collection of prebuilt Prefect integrations that can be used to interact with email services.
## Getting Started
### Integrate with Prefect flows
`prefect-email` makes sending emails effortless, giving you peace of mind that your emails are being sent as expected.
First, install [prefect-email](#installation) and [save your email credentials to a block](#saving-credentials-to-block) to run the examples below!
```python
from prefect import flow
from prefect_email import EmailServerCredentials, email_send_message
@flow
def example_email_send_message_flow(email_addresses):
email_server_credentials = EmailServerCredentials.load("BLOCK-NAME-PLACEHOLDER")
for email_address in email_addresses:
subject = email_send_message.with_options(name=f"email {email_address}").submit(
email_server_credentials=email_server_credentials,
subject="Example Flow Notification using Gmail",
msg="This proves email_send_message works!",
email_to=email_address,
)
example_email_send_message_flow(["EMAIL-ADDRESS-PLACEHOLDER"])
```
Outputs:
```bash
16:58:27.646 | INFO | prefect.engine - Created flow run 'busy-bat' for flow 'example-email-send-message-flow'
16:58:29.225 | INFO | Flow run 'busy-bat' - Created task run 'email someone@gmail.com-0' for task 'email someone@gmail.com'
16:58:29.229 | INFO | Flow run 'busy-bat' - Submitted task run 'email someone@gmail.com-0' for execution.
16:58:31.523 | INFO | Task run 'email someone@gmail.com-0' - Finished in state Completed()
16:58:31.713 | INFO | Flow run 'busy-bat' - Finished in state Completed('All states completed.')
```
Please note, many email services, like Gmail, require an [App Password](https://support.google.com/accounts/answer/185833) to successfully send emails. If you encounter an error similar to `smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted...`, it's likely you are not using an App Password.
### Capture exceptions and notify by email
Perhaps you want an email notification with the details of the exception when your flow run fails.
`prefect-email` can be wrapped in an `except` statement to do just that!
```python
from prefect import flow
from prefect.context import get_run_context
from prefect_email import EmailServerCredentials, email_send_message
def notify_exc_by_email(exc):
context = get_run_context()
flow_run_name = context.flow_run.name
email_server_credentials = EmailServerCredentials.load("email-server-credentials")
email_send_message(
email_server_credentials=email_server_credentials,
subject=f"Flow run {flow_run_name!r} failed",
msg=f"Flow run {flow_run_name!r} failed due to {exc}.",
email_to=email_server_credentials.username,
)
@flow
def example_flow():
try:
1 / 0
except Exception as exc:
notify_exc_by_email(exc)
raise
example_flow()
```
## Resources
For more tips on how to use tasks and flows in a Collection, check out [Using Collections](https://docs.prefect.io/collections/usage/)!
### Installation
Install `prefect-email` with `pip`:
```bash
pip install prefect-email
```
Then, register to [view the block](https://docs.prefect.io/ui/blocks/) on Prefect Cloud:
```bash
prefect block register -m prefect_email
```
Note, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://docs.prefect.io/ui/blocks/).
Requires an installation of Python 3.8+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2. For more information about how to use Prefect, please refer to the [Prefect documentation](https://docs.prefect.io/).
### Saving credentials to block
Note, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://docs.prefect.io/ui/blocks/).
Below is a walkthrough on saving block documents through code.
Create a short script, replacing the placeholders.
```python
from prefect_email import EmailServerCredentials
credentials = EmailServerCredentials(
username="EMAIL-ADDRESS-PLACEHOLDER",
password="PASSWORD-PLACEHOLDER", # must be an app password
)
credentials.save("BLOCK-NAME-PLACEHOLDER")
```
Congrats! You can now easily load the saved block, which holds your credentials:
```python
from prefect_email import EmailServerCredentials
EmailServerCredentials.load("BLOCK_NAME_PLACEHOLDER")
```
!!! info "Registering blocks"
Register blocks in this module to
[view and edit them](https://docs.prefect.io/ui/blocks/)
on Prefect Cloud:
```bash
prefect block register -m prefect_email
```
Raw data
{
"_id": null,
"home_page": null,
"name": "prefect-email",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "prefect",
"author": null,
"author_email": "\"Prefect Technologies, Inc.\" <help@prefect.io>",
"download_url": "https://files.pythonhosted.org/packages/d6/bd/030a3e73239706f58f01fa54df49ed055d50b3e2d020bdc71562b2adc609/prefect_email-0.3.3.tar.gz",
"platform": null,
"description": "# prefect-email\n\n<p align=\"center\">\n <a href=\"https://pypi.python.org/pypi/prefect-email/\" alt=\"PyPI version\">\n <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/prefect-email?color=0052FF&labelColor=090422\"></a>\n <a href=\"https://pepy.tech/badge/prefect-email/\" alt=\"Downloads\">\n <img src=\"https://img.shields.io/pypi/dm/prefect-email?color=0052FF&labelColor=090422\" /></a>\n</p>\n\nVisit the full docs [here](https://PrefectHQ.github.io/prefect-email) to see additional examples and the API reference.\n\n`prefect-email` is a collection of prebuilt Prefect integrations that can be used to interact with email services.\n\n## Getting Started\n\n### Integrate with Prefect flows\n\n`prefect-email` makes sending emails effortless, giving you peace of mind that your emails are being sent as expected.\n\nFirst, install [prefect-email](#installation) and [save your email credentials to a block](#saving-credentials-to-block) to run the examples below!\n\n```python\nfrom prefect import flow\nfrom prefect_email import EmailServerCredentials, email_send_message\n\n@flow\ndef example_email_send_message_flow(email_addresses):\n email_server_credentials = EmailServerCredentials.load(\"BLOCK-NAME-PLACEHOLDER\")\n for email_address in email_addresses:\n subject = email_send_message.with_options(name=f\"email {email_address}\").submit(\n email_server_credentials=email_server_credentials,\n subject=\"Example Flow Notification using Gmail\",\n msg=\"This proves email_send_message works!\",\n email_to=email_address,\n )\n\nexample_email_send_message_flow([\"EMAIL-ADDRESS-PLACEHOLDER\"])\n```\n\nOutputs:\n\n```bash\n16:58:27.646 | INFO | prefect.engine - Created flow run 'busy-bat' for flow 'example-email-send-message-flow'\n16:58:29.225 | INFO | Flow run 'busy-bat' - Created task run 'email someone@gmail.com-0' for task 'email someone@gmail.com'\n16:58:29.229 | INFO | Flow run 'busy-bat' - Submitted task run 'email someone@gmail.com-0' for execution.\n16:58:31.523 | INFO | Task run 'email someone@gmail.com-0' - Finished in state Completed()\n16:58:31.713 | INFO | Flow run 'busy-bat' - Finished in state Completed('All states completed.')\n```\n\nPlease note, many email services, like Gmail, require an [App Password](https://support.google.com/accounts/answer/185833) to successfully send emails. If you encounter an error similar to `smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted...`, it's likely you are not using an App Password.\n\n### Capture exceptions and notify by email\n\nPerhaps you want an email notification with the details of the exception when your flow run fails.\n\n`prefect-email` can be wrapped in an `except` statement to do just that!\n\n```python\nfrom prefect import flow\nfrom prefect.context import get_run_context\nfrom prefect_email import EmailServerCredentials, email_send_message\n\ndef notify_exc_by_email(exc):\n context = get_run_context()\n flow_run_name = context.flow_run.name\n email_server_credentials = EmailServerCredentials.load(\"email-server-credentials\")\n email_send_message(\n email_server_credentials=email_server_credentials,\n subject=f\"Flow run {flow_run_name!r} failed\",\n msg=f\"Flow run {flow_run_name!r} failed due to {exc}.\",\n email_to=email_server_credentials.username,\n )\n\n@flow\ndef example_flow():\n try:\n 1 / 0\n except Exception as exc:\n notify_exc_by_email(exc)\n raise\n\nexample_flow()\n```\n\n## Resources\n\nFor more tips on how to use tasks and flows in a Collection, check out [Using Collections](https://docs.prefect.io/collections/usage/)!\n\n### Installation\n\nInstall `prefect-email` with `pip`:\n\n```bash\npip install prefect-email\n```\n\nThen, register to [view the block](https://docs.prefect.io/ui/blocks/) on Prefect Cloud:\n\n```bash\nprefect block register -m prefect_email\n```\n\nNote, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://docs.prefect.io/ui/blocks/).\n\nRequires an installation of Python 3.8+.\n\nWe recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.\n\nThese tasks are designed to work with Prefect 2. For more information about how to use Prefect, please refer to the [Prefect documentation](https://docs.prefect.io/).\n\n### Saving credentials to block\n\nNote, to use the `load` method on Blocks, you must already have a block document [saved through code](https://docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://docs.prefect.io/ui/blocks/).\n\nBelow is a walkthrough on saving block documents through code.\n\nCreate a short script, replacing the placeholders.\n\n```python\nfrom prefect_email import EmailServerCredentials\n\ncredentials = EmailServerCredentials(\n username=\"EMAIL-ADDRESS-PLACEHOLDER\",\n password=\"PASSWORD-PLACEHOLDER\", # must be an app password\n)\ncredentials.save(\"BLOCK-NAME-PLACEHOLDER\")\n```\n\nCongrats! You can now easily load the saved block, which holds your credentials:\n\n```python\nfrom prefect_email import EmailServerCredentials\n\nEmailServerCredentials.load(\"BLOCK_NAME_PLACEHOLDER\")\n```\n\n!!! info \"Registering blocks\"\n\n Register blocks in this module to\n [view and edit them](https://docs.prefect.io/ui/blocks/)\n on Prefect Cloud:\n\n ```bash\n prefect block register -m prefect_email\n ```\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Prefect integrations for interacting with email.",
"version": "0.3.3",
"project_urls": {
"Homepage": "https://github.com/PrefectHQ/prefect/tree/main/src/integrations/prefect-email"
},
"split_keywords": [
"prefect"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "fa0d7844c9c881f40bfc43aeef845f5e7e05f1b95e8200498cea111581d1a934",
"md5": "97b622194aed523f40639932f0c50356",
"sha256": "64e99e95ad0fb2c12680e3400af85f410d2e3193bc1eb4f995bb9bad4fa8c5ac"
},
"downloads": -1,
"filename": "prefect_email-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "97b622194aed523f40639932f0c50356",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 8232,
"upload_time": "2024-04-25T19:22:39",
"upload_time_iso_8601": "2024-04-25T19:22:39.702784Z",
"url": "https://files.pythonhosted.org/packages/fa/0d/7844c9c881f40bfc43aeef845f5e7e05f1b95e8200498cea111581d1a934/prefect_email-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d6bd030a3e73239706f58f01fa54df49ed055d50b3e2d020bdc71562b2adc609",
"md5": "5ab49d24d6f7a600fd79f65a204512dd",
"sha256": "ecfc715f1c5e82a330606338d6e080567661d2daa12e66bbce18a11959956c8d"
},
"downloads": -1,
"filename": "prefect_email-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "5ab49d24d6f7a600fd79f65a204512dd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10218,
"upload_time": "2024-04-25T19:22:41",
"upload_time_iso_8601": "2024-04-25T19:22:41.356826Z",
"url": "https://files.pythonhosted.org/packages/d6/bd/030a3e73239706f58f01fa54df49ed055d50b3e2d020bdc71562b2adc609/prefect_email-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-25 19:22:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PrefectHQ",
"github_project": "prefect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"circle": true,
"requirements": [],
"lcname": "prefect-email"
}