A Python library for sending notifications to Google Spaces with trading holiday awareness
Project description
gnotify
A Python library for sending notifications to Google Spaces and Slack with trading holiday awareness.
Installation
pip install gnotify
Setup
Environment Variables
You can create a .env file in your project root or set environment variables directly in your system. Or you can pass a custom configuration dictionary to the send_gspaces_message function.
Create a .env file in your project root or set environment variables for your Google Spaces webhooks:
Example .env file:
MY_WEBHOOK=https://chat.googleapis.com/v1/spaces/YOUR_SPACE_ID/messages?key=YOUR_API_KEY&token=YOUR_TOKEN
Note: Environment variable names should follow the pattern GSPACES_WEBHOOK_{CHANNEL_NAME} where CHANNEL_NAME is uppercase.
Usage
from dotenv import load_dotenv, dotenv_values
load_dotenv(".env") # Load environment variables from .env file
from gnotify import send_gspaces_message, is_it_holiday, get_available_channels
# Check available channels
print("Available channels:", get_available_channels())
# Send a Google Spaces message
send_gspaces_message(
message="Hello from gnotify!",
channel="your_channel_name",
message_type="info"
)
# Check if it's a holiday
is_holiday = is_it_holiday("us", "20250101") # True for New Year's Day
# Add a webhook dynamically (optional)
from gnotify import add_webhook
add_webhook("new_channel", "https://chat.googleapis.com/v1/spaces/...")
Overwrite the webhook URL for an existing channel
from dotenv import load_dotenv, dotenv_values
from gnotify import send_gspaces_message
config = dotenv_values(".env") # Load environment variables from .env file
# Send an info message
send_gspaces_message(
message="Hello from gnotify",
channel="your_channel_name",
message_type="info",
webhooks=config
)
from gnotify import send_gspaces_message
your_custom_config = {
"your_channel_name": "https://chat.googleapis.com/v1/spaces/YOUR_SPACE_ID/messages?key=YOUR"
}
send_gspaces_message(
message="Hello from gnotify!",
channel="your_channel_name",
message_type="info",
webhooks=your_custom_config
)
Features
- Google Spaces integration with environment-based webhook configuration
- Trading holiday awareness for US, EU, and JP regions
- Multiple message types (info, warning, error, success)
- Environment-based message filtering
- Secure webhook configuration via environment variables
- Dynamic webhook management
API Reference
send_gspaces_message
Send a message to Google Spaces channel.
Parameters:
message(str): Message to send to channelchannel(str): Name of channel (default: "emn_data_processing")message_type(str): Type of message - "warning", "error", "info", "success" (default: "error")env(str): Environment - "test" or "prod" (default: "prod")region(str): Region for holiday checking - "us", "eu", "jp" (default: "us")webhooks(dict, optional): Custom webhook URLsskip_holiday_check(bool): Skip holiday checking (default: False)
get_available_channels
Get list of available channels from environment variables.
Returns:
list: List of available channel names
add_webhook
Dynamically add a webhook URL for a channel.
Parameters:
channel(str): Channel namewebhook_url(str): Webhook URL
is_it_holiday
Check if a given date is a holiday in the specified region.
Parameters:
region(str): The region to check for holidays ("us", "eu", "jp")_in_date(str): The date to check in format "YYYYMMDD"
Returns:
bool: True if the date is a holiday, False otherwise
Security
- Webhook URLs are loaded from environment variables, not hard-coded
- Use
.envfiles for development and proper environment variables in production - Never commit
.envfiles to version control
License
MIT License
Project details
Release history Release notifications | RSS feed
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 gnotify-0.0.1.tar.gz.
File metadata
- Download URL: gnotify-0.0.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
948169e397c30493b4b60fab74f1244ef0fa5b0a7aa403449a0ee224c6411ef0
|
|
| MD5 |
de7e394411ee4ef2057b00a581c55720
|
|
| BLAKE2b-256 |
9911bbce006028e6f9ae39009a24ef0cd36270ab8ae4a4c016529138799b0a23
|
File details
Details for the file gnotify-0.0.1-py3-none-any.whl.
File metadata
- Download URL: gnotify-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0189cd34c10673f537423096b0dfdacfd69d346392c3873a20b6e95d5ff35b99
|
|
| MD5 |
9e88445ee6f295a812ac0b14737ebd45
|
|
| BLAKE2b-256 |
597b768765d6c843ecc3378fc243e02a4b3872fb5d2f942f80b973298707fe14
|