CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-gntp

Growl Notification Transport Protocol for Python

80

1.25x
Overview
Eval results
Files

config-api.mddocs/

Configuration-Aware API

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.

Configuration File

The configuration API reads settings from ~/.gntp using the following format:

[gntp]
hostname = growl.example.com
password = mypassword
port = 23053

All settings are optional and fall back to the same defaults as the standard API.

Capabilities

Configuration-Aware Fire-and-Forget Notifications

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
    """

Configuration-Aware GrowlNotifier

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)
        """

Usage Examples

Basic Configuration File Usage

Create ~/.gntp configuration file:

[gntp]
hostname = growl.mycompany.com
password = company-growl-password
port = 23053

Then 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
)

Application with Shared Configuration

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"
)

Mixed Configuration and Runtime Settings

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")

Handling Missing Configuration File

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/invalid

Enterprise Deployment Example

For enterprise deployments, you can create a standard ~/.gntp file:

[gntp]
hostname = notifications.company.com
password = enterprise-password-2023
port = 23053

Then 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 automatically

Configuration File Format Details

The 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 = 23053

Configuration Resolution

Settings are resolved in this order (later values override earlier ones):

  1. Built-in defaults: hostname='localhost', port=23053, password=None
  2. Configuration file values: Read from ~/.gntp file
  3. Constructor arguments: Explicitly passed to GrowlNotifier constructor

Error Handling

The configuration module handles missing or invalid configuration files gracefully:

  • If ~/.gntp doesn't exist: Uses built-in defaults, logs info message
  • If file exists but has no [gntp] section: Creates empty section, uses defaults
  • If file has invalid format: Uses built-in defaults, may log warnings
  • If specific keys are missing: Uses built-in defaults for those keys

This ensures applications continue working even in environments without configuration files.

Install with Tessl CLI

npx tessl i tessl/pypi-gntp

docs

cli.md

config-api.md

errors.md

high-level-api.md

index.md

protocol.md

tile.json