Growl Notification Transport Protocol for Python
80
The gntp.config module provides enhanced versions of the notification API that automatically read default settings from a configuration file. This enables shared configuration across multiple applications and simplified deployment scenarios.
The configuration API reads settings from ~/.gntp using the following format:
[gntp]
hostname = growl.example.com
password = mypassword
port = 23053All settings are optional and fall back to the same defaults as the standard API.
Enhanced version of the mini() function that reads default settings from the configuration file.
def mini(description, **kwargs):
"""
Single notification function using config-aware GrowlNotifier.
Reads default hostname, password, and port from ~/.gntp configuration file.
All parameters from gntp.notifier.mini() are supported.
Parameters:
- description (str): Notification message (required)
- **kwargs: All parameters supported by gntp.notifier.mini()
Returns:
bool or tuple: True on success, error tuple on failure
"""Enhanced GrowlNotifier class that reads configuration file settings and merges them with provided parameters.
class GrowlNotifier(gntp.notifier.GrowlNotifier):
"""
ConfigParser enhanced GrowlNotifier object.
Reads default values from ~/.gntp configuration file before applying
constructor parameters. Configuration file settings are overridden by
explicit constructor arguments.
"""
def __init__(self, *args, **kwargs):
"""
Initialize config-aware GrowlNotifier.
Reads ~/.gntp configuration file and uses those values as defaults.
Explicit constructor arguments override configuration file values.
Parameters:
Same as gntp.notifier.GrowlNotifier, with config file providing defaults
Configuration Resolution Order:
1. Built-in defaults (hostname='localhost', port=23053, password=None)
2. ~/.gntp configuration file values
3. Constructor arguments (highest priority)
"""Create ~/.gntp configuration file:
[gntp]
hostname = growl.mycompany.com
password = company-growl-password
port = 23053Then use the configuration API:
import gntp.config
# Uses settings from ~/.gntp automatically
gntp.config.mini("Deployment completed successfully!")
# Config settings are used as defaults, can be overridden
gntp.config.mini(
"Critical error occurred",
hostname="emergency-server.com", # Overrides config file
priority=2
)import gntp.config
# Create notifier using configuration file defaults
app = gntp.config.GrowlNotifier(
applicationName="Web Server Monitor",
notifications=["Server Down", "High Load", "Disk Full"],
defaultNotifications=["Server Down", "Disk Full"]
# hostname, password, port read from ~/.gntp
)
# Register and send notifications
app.register()
app.notify(
"High Load",
"Server Load Warning",
"CPU usage is 89% for the last 5 minutes"
)import gntp.config
# Some settings from config file, others specified at runtime
app = gntp.config.GrowlNotifier(
applicationName="Backup System",
notifications=["Backup Started", "Backup Completed", "Backup Failed"],
# Use different server than config file for backup notifications
hostname="backup-alerts.company.com",
# But still use password from config file
)
app.register()
app.notify("Backup Started", "Daily Backup", "Starting backup of /home")import gntp.config
import logging
# The config module gracefully handles missing ~/.gntp file
# Falls back to standard defaults if file doesn't exist or has no [gntp] section
logging.basicConfig(level=logging.INFO)
# This works even if ~/.gntp doesn't exist
gntp.config.mini("Application started")
# You can check if config was loaded by examining log output
# "Info reading ~/.gntp config file" appears if file is missing/invalidFor enterprise deployments, you can create a standard ~/.gntp file:
[gntp]
hostname = notifications.company.com
password = enterprise-password-2023
port = 23053Then all applications using gntp.config automatically use the enterprise notification server:
import gntp.config
# Automatically uses enterprise settings
build_notifier = gntp.config.GrowlNotifier(
applicationName="CI/CD Pipeline",
notifications=["Build Started", "Build Success", "Build Failed"]
)
deployment_notifier = gntp.config.GrowlNotifier(
applicationName="Deployment System",
notifications=["Deploy Started", "Deploy Success", "Deploy Failed"]
)
monitoring_notifier = gntp.config.GrowlNotifier(
applicationName="System Monitor",
notifications=["Alert", "Warning", "Info"]
)
# All three use the same enterprise Growl server automaticallyThe configuration file uses Python's ConfigParser format:
[gntp]
# Growl server hostname or IP address
hostname = growl.example.com
# Network password for authentication (optional)
password = your-password-here
# Growl server port number
port = 23053Settings are resolved in this order (later values override earlier ones):
hostname='localhost', port=23053, password=None~/.gntp fileThe configuration module handles missing or invalid configuration files gracefully:
~/.gntp doesn't exist: Uses built-in defaults, logs info message[gntp] section: Creates empty section, uses defaultsThis ensures applications continue working even in environments without configuration files.
Install with Tessl CLI
npx tessl i tessl/pypi-gntpevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10