Класс для работы с API на Python

Класс для работы с API на Python

Установка

pip install -U smsaero-api

Асинхронная версия

pip install -U smsaero-api-async

Использование

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)


if __name__ == '__main__':
    try:
        result = send_sms(70000000000, 'Hello, World!')
        pprint(result)
    except SmsAeroException as e:
        print(f"An error occurred: {e}")

Доступные методы и параметры вызова смотрите в исходном коде.

Асинхронное использование
import pprint
import asyncio
import smsaero


SMSAERO_EMAIL = 'your email'
SMSAERO_API_KEY = 'your api key'


async def send_sms(phone: int, message: str) -> None:
    """
    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.
    """
    api = smsaero.SmsAero(SMSAERO_EMAIL, SMSAERO_API_KEY)
    try:
        result = await api.send_sms(phone, message)
        pprint.pprint(result)
    finally:
        await api.close_session()


if __name__ == '__main__':
    asyncio.run(send_sms(70000000000, 'Hello, World!'))

Доступные методы и параметры вызова смотрите в исходном коде асинхронной версии.