Skip to main content

Async Python client for HeroSMS (sms-activate.ru compatible) API

Project description

herosms

Async and sync Python client for HeroSMS (SMS-Activate compatible API).

Features

  • Async-first client with context-manager support
  • Synchronous wrapper for non-async projects
  • Activation lifecycle helpers (create, wait, resend, complete, cancel)
  • Rent APIs support
  • Reference data helpers (countries, services, operators, prices)
  • Typed models with Pydantic v2
  • Custom exception hierarchy
  • Webhook payload parsing for incoming SMS events

Installation

pip install herosms

For development:

uv sync --extra dev

Quickstart (async)

import asyncio

from herosms import HeroSMSClient


async def main() -> None:
    async with HeroSMSClient(api_key="YOUR_API_KEY") as client:
        balance = await client.get_balance()
        print(f"Balance: {balance}")

        async with await client.activations.create(service="tg", country=6) as activation:
            status = await activation.wait_for_sms(timeout=120)
            print("Code:", status.code)
            await activation.complete()


asyncio.run(main())

Quickstart (sync)

from herosms import SyncHeroSMSClient


with SyncHeroSMSClient(api_key="YOUR_API_KEY") as client:
    balance = client.get_balance()
    print(f"Balance: {balance}")

Activation lifecycle

Create activation and wait for code:

async with await client.activations.create(service="tg", country=6) as activation:
    status = await activation.wait_for_sms(timeout=120)
    print(status.code)

Request another SMS:

await activation.request_sms()

Complete or cancel:

await activation.complete()
# or
await activation.cancel()

Get all OTP messages for activation:

messages = await activation.get_all_sms()

Legacy status endpoint (getStatus)

Use get_status_v1 if you need raw text-compatible status values from legacy integrations:

raw_status = await client.get_status_v1(activation_id=123456)
print(raw_status)  # e.g. STATUS_WAIT_CODE or STATUS_OK:1234

Sync variant:

raw_status = client.get_status_v1(activation_id=123456)

Rent flow

Check availability:

availability = await client.get_rent_availability(service="tg", country=6)
print(availability)

Rent a number:

rent_activation = await client.rent_number(service="tg", country=6, duration=2)
print(rent_activation.phone)

Sync variants are available with the same method names.

Reference data APIs

countries = await client.get_countries()
services = await client.get_services(country=6)
operators = await client.get_operators(country=6)
prices = await client.get_prices(service="tg", country=6)
top = await client.get_top_countries(service="tg", by_rank=True)

Error handling

All library exceptions inherit from HeroSMSError.

from herosms import HeroSMSError


try:
    ...
except HeroSMSError as exc:
    print(f"HeroSMS error: {exc}")

Webhook payload parsing (smsIncoming)

Parse and validate incoming webhook payload with Pydantic model:

from herosms import WebhookSMSIncoming

payload = {
    "activationId": "635468024",
    "service": "tg",
    "text": "Telegram code 123456",
    "code": "123456",
    "country": 6,
    "receivedAt": "2026-02-16T12:36:59+03:00",
}

event = WebhookSMSIncoming.model_validate(payload)
print(event.activation_id, event.code)

API compatibility note

HeroSMS is compatible with SMS-Activate-style API actions. This library targets HeroSMS endpoints while preserving familiar SMS-Activate action semantics.

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

herosms-0.1.0.tar.gz (56.8 kB view details)

Uploaded Source

Built Distribution

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

herosms-0.1.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file herosms-0.1.0.tar.gz.

File metadata

  • Download URL: herosms-0.1.0.tar.gz
  • Upload date:
  • Size: 56.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for herosms-0.1.0.tar.gz
Algorithm Hash digest
SHA256 635e35c3f3242643be651593829930caf348be76efac0a30f133f75cc5f30b3b
MD5 392bd8cd1943691c1b54f88fbc451d5d
BLAKE2b-256 754b43a784ecbef37de40804d9ed4d17884f42780a3ab83cc0313f2216e8aaa9

See more details on using hashes here.

File details

Details for the file herosms-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: herosms-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.8

File hashes

Hashes for herosms-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f856f1dac0f18065fc1a26f09bd75976bc8a31f218ad9af1529298aedaa6e99b
MD5 f0bccc5a3aa4a5ab55a12bb746835c82
BLAKE2b-256 3cf4a6afea65d2052145acc5d792801482d2ee0210505547e11257fc64dd3801

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