Skip to main content

A Python library for sending SMS, email and WhatsApp messages

Project description

TextTalk Communication Library

A Python library for sending SMS, email and WhatsApp messages. This package provides a simple and efficient interface for sending both individual and bulk messages across multiple communication channels.

Features

  • Send individual and bulk SMS messages
  • Send individual and bulk email messages
  • Send individual and bulk WhatsApp messages
  • Configurable through environment variables or direct configuration
  • Comprehensive error handling
  • Type hints for better IDE support
  • Simple and intuitive API

Installation

  1. Clone the repository:
git clone <repository-url>
cd chat
  1. Install the required dependencies:
pip install -r requirements.txt

Configuration

You can configure the SMS client in two ways:

1. Using Environment Variables

Set the following environment variables:

export SMS_API_KEY='your_api_key'
export SMS_PARTNER_ID='your_partner_id'
export SMS_SHORTCODE='your_shortcode'

2. Using Direct Configuration

from sms import SMSConfig

config = SMSConfig(
    api_key='your_api_key',
    partner_id='your_partner_id',
    shortcode='your_shortcode'
)

Usage

Basic Usage

from sms import SMSClient

# Using environment variables
client = SMSClient()

# Send a single SMS
success = client.send_sms(
    to_number='+254713164545',
    message='Hello from TextTalk!'
)

# Send bulk SMS
success = client.send_bulk_sms(
    message='Hello from TextTalk!',
    to_numbers=['+254713164545', '+254713164546']
)

With Custom Configuration

from sms import SMSClient, SMSConfig

config = SMSConfig(
    api_key='your_api_key',
    partner_id='your_partner_id',
    shortcode='your_shortcode'
)

client = SMSClient(config)

Error Handling

The library provides custom exceptions for better error handling:

from sms import SMSClient, SMSException, ConfigurationError, MessageError

try:
    client = SMSClient()
    client.send_sms(to_number='+254713164545', message='Hello!')
except ConfigurationError as e:
    print(f"Configuration error: {e}")
except MessageError as e:
    print(f"Message error: {e}")
except SMSException as e:
    print(f"General SMS error: {e}")

API Reference

SMSClient

__init__(config: Optional[SMSConfig] = None)

Initialize the SMS client with configuration.

send_sms(to_number: str, message: str) -> bool

Send a single SMS message.

Parameters:

  • to_number (str): The recipient's phone number
  • message (str): The message content

Returns:

  • bool: True if the message was sent successfully

send_bulk_sms(message: str, to_numbers: List[str]) -> bool

Send SMS messages to multiple recipients.

Parameters:

  • message (str): The message content
  • to_numbers (List[str]): List of recipient phone numbers

Returns:

  • bool: True if the messages were sent successfully

SMSConfig

Configuration class for managing API credentials and settings.

Parameters:

  • api_key (Optional[str]): API key for authentication
  • partner_id (Optional[str]): Partner ID for the service
  • shortcode (Optional[str]): Shortcode for sending messages

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

texttalk-0.0.6.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

texttalk-0.0.6-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file texttalk-0.0.6.tar.gz.

File metadata

  • Download URL: texttalk-0.0.6.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for texttalk-0.0.6.tar.gz
Algorithm Hash digest
SHA256 f48c4318eac7796740c3b5874b8b2fcde74c70b265edc1b8d416e4f58eaa4439
MD5 2fe0ee30d29d2da7d3a878cbe91cb78f
BLAKE2b-256 854de9e430bbc76278d24860e319e4758dd30658a51e48762595f2d8a55fe009

See more details on using hashes here.

Provenance

The following attestation bundles were made for texttalk-0.0.6.tar.gz:

Publisher: release.yaml on thaka-creations/chat

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

File details

Details for the file texttalk-0.0.6-py3-none-any.whl.

File metadata

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

File hashes

Hashes for texttalk-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5410ff7895bfba14b5d9dd23f3a802c1effc34f8739dfdfe0e463934d28d18f2
MD5 766f8dde0fcc536937eb6f7b0eb57ec9
BLAKE2b-256 1ab449b2700d07ca36728fef2eb9c83bb5762851c586c2d0e5eaf46ce6e75611

See more details on using hashes here.

Provenance

The following attestation bundles were made for texttalk-0.0.6-py3-none-any.whl:

Publisher: release.yaml on thaka-creations/chat

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