A simple notification library for Google Cloud projects. Sends alerts via Email and Google Chat.
Project description
GCP Notifier
Synchronous Usage
Import and use in your Python code:
from gcp_notifier import notify, notify_on_failure
# Send a notification (choose channels: "email", "gchat", or both)
notify(
subject="Alert Subject",
body="Alert body text",
channels=["email", "gchat"] # or ["email"] or ["gchat"]
)
# Use as tenacity retry_error_callback
from tenacity import retry, stop_after_attempt
@retry(stop=stop_after_attempt(3), retry_error_callback=notify_on_failure)
def always_fails():
# This function will always fail, triggering notify_on_failure after retries
raise ValueError("This is a test error for notification.")
always_fails()
Async Usage
You can send notifications asynchronously using the async API.
Async notify example
import asyncio # only if running a script, otherwise, do not import
from gcp_notifier import async_notify
async def main():
await async_notify(
subject="Async Alert",
body="This is an async alert!",
channels=["email", "gchat"]
)
asyncio.run(main()) # if running a script
await main() # if using a notebook
Async tenacity error callback example
import asyncio # only if running a script, otherwise, do not import
from gcp_notifier import async_notify_on_failure
from tenacity import retry, stop_after_attempt
@retry(stop=stop_after_attempt(3), retry_error_callback=async_notify_on_failure)
async def always_fails_async():
raise ValueError("This is a test error for async notification.")
asyncio.run(always_fails_async()) # if running a script
await always_fails_async() # if using a notebook
Installation
Install from PyPI (recommended):
pip install gcp-notifier
For async features (async_notify, async_notify_on_failure), install with the optional async dependencies:
pip install 'gcp-notifier[async]'
This will install the package plus the required async libraries (aiosmtplib, httpx).
Quick Start
-
Install the package (see Installation above).
-
The account (personal or service) running this code must have the 'Secret Manager Secret Accessor' role in your GCP project.
-
The required secrets must be in the same GCP project where your Python script or notebook is running.
-
Add your required secrets to Google Secret Manager in your GCP project:
GCHAT_WEBHOOK_URL(for Google Chat)EMAIL_SENDER(sender email address for Email)EMAIL_PASSWORD(password or app password for sender)EMAIL_RECIPIENTS(comma-separated list of recipient email addresses)
-
Import and use
notifyin your code as shown below.
Building and Publishing
This project uses a modern Python packaging workflow with pyproject.toml.
To build the package:
python -m pip install --upgrade build
python -m build
To check and upload to PyPI:
python -m pip install --upgrade twine
twine check dist/*
twine upload dist/*
See Python Packaging User Guide for more details.
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gcp_notifier-0.1.6.tar.gz.
File metadata
- Download URL: gcp_notifier-0.1.6.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dc4afdb00a28f2e9dd42df163b13ffe1ff4047cd6f9179308fff402b597830e
|
|
| MD5 |
653b27e4cdb420602531ebc2a636e6ee
|
|
| BLAKE2b-256 |
9fd6719fba33c03c0b2f7efc75d2dfc8e11cef16baf2ebb4209f2d1246bb3785
|
Provenance
The following attestation bundles were made for gcp_notifier-0.1.6.tar.gz:
Publisher:
python-publish.yml on marcellusmontilla/gcp_notifier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gcp_notifier-0.1.6.tar.gz -
Subject digest:
2dc4afdb00a28f2e9dd42df163b13ffe1ff4047cd6f9179308fff402b597830e - Sigstore transparency entry: 417341307
- Sigstore integration time:
-
Permalink:
marcellusmontilla/gcp_notifier@0ebc649843b6d4c90d83dd2642ac543a7ca3f641 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/marcellusmontilla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0ebc649843b6d4c90d83dd2642ac543a7ca3f641 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gcp_notifier-0.1.6-py3-none-any.whl.
File metadata
- Download URL: gcp_notifier-0.1.6-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff1771767d2f8ffc90f52a891edb879d05f352a742a7b9b737de93576f68e0bf
|
|
| MD5 |
9143b34089c0e43d2b053c722e22d9a4
|
|
| BLAKE2b-256 |
6bfe941f0bfa13b17aba6de11f1d068d5788120f0c67e753dd8ed3855d183236
|
Provenance
The following attestation bundles were made for gcp_notifier-0.1.6-py3-none-any.whl:
Publisher:
python-publish.yml on marcellusmontilla/gcp_notifier
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gcp_notifier-0.1.6-py3-none-any.whl -
Subject digest:
ff1771767d2f8ffc90f52a891edb879d05f352a742a7b9b737de93576f68e0bf - Sigstore transparency entry: 417341320
- Sigstore integration time:
-
Permalink:
marcellusmontilla/gcp_notifier@0ebc649843b6d4c90d83dd2642ac543a7ca3f641 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/marcellusmontilla
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@0ebc649843b6d4c90d83dd2642ac543a7ca3f641 -
Trigger Event:
release
-
Statement type: