Skip to main content

Generate console base notification messages.

Project description

DevelopersToolbox logo
Github Build Status License Created
Release Released Commits since release

Overview

The Notify package provides a set of utility functions for printing formatted messages to the terminal. The main purpose of this module is to facilitate the display of success, warning, error, informational, and system messages with specific color and style formatting using predefined constants.

Features

  • Display success messages with green text.
  • Display warning messages with yellow text.
  • Display error messages with red text.
  • Display informational messages with cyan text.
  • Display system messages with grey text.
  • Support for custom colors, prompts, and formatting scopes.
  • Error handling for invalid colors and scopes.

Installation

To install the Notify package, use the following command:

pip install wolfsoftware.notify

Usage

Here is an example of how to use the notification functions provided by the Notify package:

from wolfsoftware.notify import success_message, warning_message, error_message, info_message, system_message

print(success_message("Operation completed successfully."))
print(warning_message("This is a warning message."))
print(error_message("An error occurred."))
print(info_message("This is some information."))
print(system_message("System update available."))

Functions

success_message

Print a success message with a specific format.

def success_message(
        message: str,
        color: str = 'green+bold',
        prompt: str = 'Success',
        scope: str = 'prompt_text',
        prompt_prefix: str = '[ ',
        prompt_suffix: str = ' ]'
    ) -> str:

warning_message

Print a warning message with a specific format.

def warning_message(
        message: str,
        color: str = 'yellow+bold',
        prompt: str = 'Warning',
        scope: str = 'prompt_text',
        prompt_prefix: str = '[ ',
        prompt_suffix: str = ' ]'
    ) -> str:

error_message

Print an error message with a specific format.

def error_message(
        message: str,
        color: str = 'red+bold',
        prompt: str = 'Error',
        scope: str = 'prompt_text',
        prompt_prefix: str = '[ ',
        prompt_suffix: str = ' ]'
    ) -> str:

failure_message

Alias for error_message, but with a prompt='Failure'.

failure_message = error_message

info_message

Print an informational message with a specific format.

def info_message(
        message: str,
        color: str = 'cyan+bold',
        prompt: str = 'Info',
        scope: str = 'prompt_text',
        prompt_prefix: str = '[ ',
        prompt_suffix: str = ' ]'
    ) -> str:

system_message

Print a system message with a specific format.

def system_message(
        message: str,
        color: str = 'grey+bold',
        prompt: str = 'System',
        scope: str = 'prompt_text',
        prompt_prefix: str = '[ ',
        prompt_suffix: str = ' ]'
    ) -> str:

Customization

You can customize the color, prompt text, and the scope of the color application using the provided parameters. Here are some examples:

Custom Colors

print(success_message("Operation completed successfully.", color="blue+bold"))

Custom Prompts

print(success_message("Operation completed successfully.", prompt="Completed"))

Custom Scopes

  • all: Applies the color to the entire message.
  • prompt: Applies the color to the prompt only.
  • prompt_text: Applies the color to the text inside the brackets.
print(success_message("Operation completed successfully.", scope="prompt"))
print(success_message("Operation completed successfully.", scope="prompt_text"))

Custom Prefixes and Suffixes

You can also customize the prompt prefix and suffix.

print(success_message("Operation completed successfully.", prompt_prefix="<<", prompt_suffix=">>"))

Error Handling

The Notify package includes error handling for invalid color and scope inputs. If an invalid color or scope is provided, a NotifyValueError will be raised with an appropriate error message.

from wolfsoftware.notify import NotifyValueError

try:
    print(success_message("Operation completed successfully.", color="invalid"))
except NotifyValueError as e:
    print(f"Error: {e}")

Testing

The Notify package includes a comprehensive test suite to ensure the correct functionality of all message formatting functions. The tests verify that the package version is defined, the message functions return correctly formatted strings, and exceptions are raised appropriately for invalid inputs.

Running Tests

To run the tests, use a testing framework such as pytest:

pytest tests/test_notify.py

Acknowledgements

The Notify package uses the colorama library for cross-platform support of ANSI color codes. Many thanks to the contributors of the colorama project for their excellent work.


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

wolfsoftware_notify-0.1.2.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

wolfsoftware.notify-0.1.2-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file wolfsoftware_notify-0.1.2.tar.gz.

File metadata

  • Download URL: wolfsoftware_notify-0.1.2.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for wolfsoftware_notify-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2935064ab0448e958a61f5de43dcb34bcc83735c5df13da1bc1ddc2f5f748c0a
MD5 da835fc02f5aab991b88ed371158fbf3
BLAKE2b-256 f952d3cab4e104bbf84054d99393d004cd026217a1397983f0a7463330ce71ee

See more details on using hashes here.

File details

Details for the file wolfsoftware.notify-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for wolfsoftware.notify-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2a8d3e58d2226d6e166f6ab37e529500babc02a11e0f37a3e61cd57a1cb9e490
MD5 e97ef5cf3d67793b2b0debea7aa7168f
BLAKE2b-256 7e49eaef5c34820b82561e3d3e2fcf289da7f5750e09fb78ecfd7470fbb2c6a4

See more details on using hashes here.

Supported by

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