Skip to main content

A Python wrapper for the SmsHub API supporting synchronous and asynchronous requests.

Project description

SmsHub API Wrapper

This library provides a simple and intuitive Python wrapper around the SmsHub API, allowing for both synchronous and asynchronous interaction with the service. With this wrapper, you can easily integrate SmsHub functionality into your Python applications.

Features

  • Synchronous and asynchronous API calls.
  • Comprehensive error handling with custom exceptions.
  • Response parsing utilities.
  • Support RU/EN languages based on system settings.

Installation

To install SmsHub API Wrapper, simply use pip:

pip install pysmshub

Quick Start

Here's a quick example of how you can use the SmsHub API Wrapper:

Synchronous usage

import time
from pysmshub import SyncSmsHubApi
from pysmshub.utils import Status

# Initialize instance with API_KEY. HTTP proxy support available.
hub_api_sync = SyncSmsHubApi(api_key="your_api_key_here", proxy="http://proxyhost:proxyport")

# Get_balance example
balance = hub_api_sync.get_balance()
print(f"Current balance: {balance}")

# Get_number example
num_id, phone = hub_api_sync.get_number(service="ya", max_price=2)

# Get_status example
for _ in range(10):
    status, code = hub_api_sync.get_status("your_num_id")
    if status == Status.SUCCESS:
        print(code)
        break
    time.sleep(1)

# Set_status example
hub_api_sync.set_status("your_num_id", Status.CANCEL)

Asynchronous usage

import asyncio
from pysmshub import AsyncSmsHubApi
from pysmshub.utils import Status


async def async_example():
    # Initialize instance with API_KEY
    hub_api_async = AsyncSmsHubApi(api_key="your_api_key_here")

    # Get_balance example
    balance = await hub_api_async.get_balance()
    print(f"Current balance: {balance}")

    # Get_number example
    num_id, phone = await hub_api_async.get_number(service="ya", max_price=2)

    # Get_status example
    for _ in range(10):
        status, code = await hub_api_async.get_status("your_num_id")
        if status == Status.SUCCESS:
            print(code)
            break
        await asyncio.sleep(1)

    # Set_status example
    await hub_api_async.set_status("your_num_id", Status.CANCEL)


# Run the async example
asyncio.run(async_example())

Error handling

from pysmshub import SyncSmsHubApi

hub_api_sync = SyncSmsHubApi(api_key="your_api_key_here")
try:
    num_id, phone = hub_api_sync.get_number(service="ya", max_price=2)
except SmsHubApiException as e:
    print(e)

Proxy support

from pysmshub import SyncSmsHubApi, AsyncSyncSmsHubApi

SyncSmsHubApi(api_key="your_api_key_here", proxy="http://proxyhost:proxyport")
AsyncSyncSmsHubApi(api_key="your_api_key_here", proxy="http://proxyhost:proxyport")

Documentation

For detailed information about all the functionality available in this wrapper, please refer to the official SmsHub API documentation.

Contributing

Contributions are welcome! If you have an improvement or a bug fix, feel free to fork this repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you need help or have any questions, please open an issue in the GitHub issue tracker.

Disclaimer

This library is not affiliated with SmsHub and is developed as an independent project.

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

pysmshub-0.1.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

pysmshub-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pysmshub-0.1.3.tar.gz.

File metadata

  • Download URL: pysmshub-0.1.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pysmshub-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4e4e62b72290ea010370f9e98d7954710883e1af496339116f7102ca00cc7efa
MD5 cc612c60337c5043e7252ca8dfcfba61
BLAKE2b-256 ccdbf82cd7652ad76ffc54dc79c3195113a25a320a0fd89d3ff2e38050c8afb2

See more details on using hashes here.

File details

Details for the file pysmshub-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pysmshub-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for pysmshub-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 378d4e8c284e87a25981ac9a0769718ac3c989adc90963a4e20d208d80248a6d
MD5 fafaf79faf6849a9233b720858c3a3c8
BLAKE2b-256 29e9227d3d00a9adec3935110e4c693ee10ae9e563931d0c6e30d7fadc2acc6c

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