Skip to main content

Python client for working with SMS Aero API.

Project description

Python library for sending SMS messages via SMS Aero API

PyPI version Python Versions Downloads License

Installation (from PyPI):

pip install -U smsaero-api

Usage example:

Get credentials from account settings page: https://smsaero.ru/cabinet/settings/apikey/

from pprint import pprint
from smsaero import SmsAero, SmsAeroException


SMSAERO_EMAIL = "your email"
SMSAERO_API_KEY = "your api key"


def send_sms(phone: int, message: str) -> dict:
    """
    Sends an SMS message

    Parameters:
    phone (int): The phone number to which the SMS message will be sent.
    message (str): The content of the SMS message to be sent.

    Returns:
    dict: A dictionary containing the response from the SmsAero API.
    """
    api = SmsAero(SMSAERO_EMAIL, SMSAERO_API_KEY)
    return api.send_sms(phone, message)


def send_telegram_code(phone: int, code: int, sign: str = None, text: str = None) -> dict:
    """
    Sends a Telegram code

    Parameters:
    phone (int): The phone number to which the Telegram code will be sent.
    code (int): The Telegram code (4 to 8 digits).
    sign (str, optional): The SMS sender name for fallback.
    text (str, optional): The SMS message text for fallback.

    Returns:
    dict: A dictionary containing the response from the SmsAero API.
    """
    api = SmsAero(SMSAERO_EMAIL, SMSAERO_API_KEY)
    return api.send_telegram(phone, code, sign, text)


if __name__ == "__main__":
    try:
        # Send SMS
        result = send_sms(70000000000, "Hello, World!")
        pprint(result)
        
        # Send Telegram code
        telegram_result = send_telegram_code(70000000000, 1234, "SMS Aero", "Your code is 1234")
        pprint(telegram_result)
    except SmsAeroException as e:
        print(f"An error occurred: {e}")

Exceptions:

  • SmsAeroException - base exception class for all exceptions raised by the library.
  • SmsAeroConnectionException - exception raised when there is a connection error.
  • SmsAeroNoMoneyException - exception raised when there is not enough money in the account.

Command line usage:

SMSAERO_EMAIL="your email"
SMSAERO_API_KEY="your api key"

smsaero_send --email "$SMSAERO_EMAIL" --api_key "$SMSAERO_API_KEY" --phone 70000000000 --message 'Hello, World!'

Run on Docker:

docker pull 'smsaero/smsaero_python:latest'
docker run -it --rm 'smsaero/smsaero_python:latest' smsaero_send --email "your email" --api_key "your api key" --phone 70000000000 --message 'Hello, World!'

Compatibility:

  • Currently version of library is compatible with Python 3.6+.
  • Previous versions of Python supported by versions 2.2.0 and below.

License:

MIT License

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

smsaero_api-3.1.1.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

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

smsaero_api-3.1.1-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file smsaero_api-3.1.1.tar.gz.

File metadata

  • Download URL: smsaero_api-3.1.1.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for smsaero_api-3.1.1.tar.gz
Algorithm Hash digest
SHA256 04351a5143f9a175ef3ea7be5e9e9f1ac5bab56604492ed309f1b7c5ba522986
MD5 11be36809b7d18e37da00e98310db34b
BLAKE2b-256 e1787072231ff4e3019b0d6d69049c4d66e399f2b9172a6a1398172b7d5938ac

See more details on using hashes here.

File details

Details for the file smsaero_api-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: smsaero_api-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.20

File hashes

Hashes for smsaero_api-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 62ae665bf8b71ed03f205730f61f7e8d770a6638f88ce7904c77a513342243e7
MD5 14ff5baff24076c70e20739197adcc40
BLAKE2b-256 5749dcca3de52100e27dc5dbff02994c5e55b8301cb66cc0b194ff6fd97c95a3

See more details on using hashes here.

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