pysmsboxnet

SMSBox API client module.

class pysmsboxnet.api.Client(session: ClientSession, host: str, cle_api: str)

API client class.

Parameters:
  • session (aiohttp.ClientSession) – the aiohttp session to use

  • host (str) – the API endpoint host, for example api.smsbox.pro (HTTPS is enforced)

  • cle_api (str) – the SMSBox API key; the parameter name is in French to match the official documentation

async get_credits() float

Return the number of credits as a float.

Raises:

pysmsboxnet.exceptions.SMSBoxException – result is not OK

async send(dest: str, msg: str, mode: str, parameters: dict[str, str] | None = None) int

Send an SMS.

Parameters:
  • dest (str) – SMS recipient(s); see the API documentation for the required format

  • msg (str) – the SMS message

  • mode (str) – send mode (the mode API parameter)

  • parameters (dict) – optional API parameters (e.g., strategy), or a charset other than UTF-8

Returns:

SMS ID if the id parameter is set to 1; otherwise 0

Return type:

int

Exceptions

The following exceptions can be thrown.

Not all exceptions apply to every case, but some are common (for example, internal errors or an invalid API key).

Exceptions for the SMSBox API.

exception pysmsboxnet.exceptions.AuthException

Exception raised when the API returns ERROR 02.

exception pysmsboxnet.exceptions.BillingException

Exception raised when the API returns ERROR 03.

exception pysmsboxnet.exceptions.HTTPException(error_code: int)

Exception raised when the HTTP status is not successful.

exception pysmsboxnet.exceptions.InternalErrorException

Exception raised when the API returns ERROR 05.

exception pysmsboxnet.exceptions.ParameterErrorException

Exception raised when the API returns ERROR 01.

exception pysmsboxnet.exceptions.SMSBoxException(message: str = 'Unknown API error')

Base exception for SMSBox API.

exception pysmsboxnet.exceptions.WrongRecipientException

Exception raised when the API returns ERROR 04.