Skip to main content

A simple notification library for Google Cloud projects. Sends alerts via Email and Google Chat.

Project description

GCP Notifier

Upload Python Package

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:

import asyncio
from gcp_notifier import async_notify, async_notify_on_failure

# Send a notification asynchronously
async def main():
  await async_notify(
    subject="Async Alert",
    body="This is an async alert!",
    channels=["email", "gchat"]
  )

asyncio.run(main())

# Use as tenacity retry_error_callback (async)
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())

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

  1. Install the package (see Installation above).

  2. The account (personal or service) running this code must have the 'Secret Manager Secret Accessor' role in your GCP project.

  3. The required secrets must be in the same GCP project where your Python script or notebook is running.

  4. 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)
  5. Import and use notify in 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

gcp_notifier-0.1.5.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gcp_notifier-0.1.5-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file gcp_notifier-0.1.5.tar.gz.

File metadata

  • Download URL: gcp_notifier-0.1.5.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

Hashes for gcp_notifier-0.1.5.tar.gz
Algorithm Hash digest
SHA256 abbaa565da9d376f3316be497f19d2ef4e0d89177df828540f58b1b5f78f24d9
MD5 3c8c0beeb0e7ae414c0ed94fe7530e15
BLAKE2b-256 5072827a077a10f16a9076aac9afc0a2c348f8e850d75debf97fc982139b8530

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcp_notifier-0.1.5.tar.gz:

Publisher: python-publish.yml on marcellusmontilla/gcp_notifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gcp_notifier-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: gcp_notifier-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gcp_notifier-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 79b6194f7ea8c614493600f377e59160072311c557d5414fff30cb3c5b61a963
MD5 3f68f766efb58196cc77438295ac4f7e
BLAKE2b-256 8ce591a7f2f9a44cadc788a12357a302fdbeb0244cc5c4e7811aa548d2a760b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for gcp_notifier-0.1.5-py3-none-any.whl:

Publisher: python-publish.yml on marcellusmontilla/gcp_notifier

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page