Giter Club home page Giter Club logo

smshub_py's Introduction

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'

smshub_py's People

Contributors

platon-p avatar yarosvet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

yarosvet

smshub_py's Issues

Error with https url

Url must be http not https if requests.get raise exception
url = 'http://smshub.org/stubs/handler_api.php'
Check the offical site for more details

ВНИМАНИЕ! Если вы подменяете host, то будет ошибка https протокола. Чтобы её избежать, отправляйте запросы без https, используя http

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.