/smshub_py

Python client for Smshub API

Primary LanguagePythonMIT LicenseMIT

Python SmsHub API package

Community python module for SmsHub API

  • Python typing
  • Understandable docstrings
  • Asynchronous way available
  • Easy to use

Useful links

Install

pip install ./

Examples

Classic example

Activation

from smshub_py import SmsActivation

a = SmsActivation('YOUR_API_KEY', 'SERVICE_CODE')
print(f"Phone number is +{a.phone}")
# ...
# Do something to send code by SMS
# ...
a.sms_sent()
a.wait_for_sms()
print(f"Code is {a.code}")
# Receive another SMS if expected
a.retry()
a.wait_for_sms()
print(f"Code is {a.code}")
# ...
# Use this code as you want
# ...
# Finish activation if all is OK
a.finish()

Balance and other actions through wrapper

from smshub_py import SmsHubWrapper

w = SmsHubWrapper('YOUR_API_KEY')
print(f"Balance is {w.get_balance()}")
print(w.get_prices()) # Get all prices

Async example

Activation

from smshub_py.asyncio import AsyncSmsActivation
import asyncio


async def main():
    with AsyncSmsActivation('YOUR_API_KEY', 'SERVICE_CODE') as a:
        print(f"Phone number is +{a.phone}")
        # ...
        # Do something to send code by SMS
        # ...
        await a.sms_sent()
        await a.wait_for_sms()
        print(f"Code is {a.code}")
        # Receive another SMS if expected
        await a.retry()
        await a.wait_for_sms()
        print(f"Code is {a.code}")
        # ...
        # Use this code as you want
        # ...
        # Finish activation if all is OK
        await a.finish()


asyncio.run(main())

Balance and other actions through wrapper

from smshub_py.asyncio import AsyncSmsHubWrapper
import asyncio


async def main():
    async with AsyncSmsHubWrapper('YOUR_API_KEY') as w:
        print(f"Balance is {await w.get_balance()}")
        print(await w.get_prices())  # Get all prices


asyncio.run(main())

Some useful utils

from smshub_py.utils import find_min_prices, country_to_id, id_to_country

# Minimal 100 prices of specified service
find_min_prices(wrapper, 'SERVICE_CODE', count=100)

# Convert Alpha-2 country code to SmsHub Country ID
country_to_id('US') # -> 12

# And back
id_to_country(12) # -> 'US'