Skip to main content

BitMomo Python SDK

Accept crypto payments in your Python application and verify BitMomo webhooks. Sync and async clients, exact Decimal money, and one dependency (httpx).

Test money only. BitMomo currently runs on test networks. Live API keys are disabled, so nothing you do with this SDK moves real money.

Guides and the API reference: https://docs.bitmomo.app

Install

pip install bitmomo

Python 3.10 or newer.

Create a payment

import bitmomo

client = bitmomo.Client(
    api_key=os.environ["BITMOMO_API_KEY"],
    base_url="https://api.dev.bitmomo.app",
)

payment = client.create_payment(
    amount="150.00",                 # GHS, as a string, int or Decimal; never a float
    crypto_type="USDT_TRC20",
    order_id="order-1001",
    idempotency_key="order-1001",    # reuse the same key if you retry
)
print(payment.deposit_address, payment.crypto_amount, payment.qr_code_data)

Show the customer qr_code_data (or deposit_address and crypto_amount). Then wait for the webhook, or poll:

status = client.get_payment_status(payment.id)   # "pending", "confirmed", "completed", ...
detail = client.get_payment(payment.id)           # economics, payout state, order terms

Async

async with bitmomo.AsyncClient(api_key=key, base_url="https://api.dev.bitmomo.app") as client:
    payment = await client.create_payment(amount="150.00", crypto_type="USDT_TRC20")

Verify webhooks

Verify the raw request body, before parsing it. Keep both secrets during the 24 hours after you rotate.

from bitmomo import webhooks

dedupe = webhooks.DeliveryDedupeCache()

def handle(request):
    result = webhooks.verify_event(
        request.body,                                   # bytes, exactly as received
        request.headers["X-Webhook-Signature"],
        secrets=[webhooks.WebhookSecret(version=1, secret=WEBHOOK_SECRET)],
        timestamp=request.headers.get("X-Webhook-Timestamp"),
        key_version=request.headers.get("X-Webhook-Key-Version"),
    )
    if not result:
        return 400                                      # result.reason says why
    if dedupe.seen(result.envelope.delivery_id):
        return 200                                      # already handled
    event = json.loads(request.body)
    ...
    return 200

Deliveries arrive at least once. The in-memory cache is enough for one process; store processed delivery_ids durably if a duplicate would cause a second effect (shipping twice, crediting twice).

Everything the client can do

Method API
create_payment(...) POST /api/v1/gateway/payments
get_payment(payment_id) GET /api/v1/gateway/payments/{id}
get_payment_status(payment_id) GET /api/v1/payments/{id}/status
list_payments(page=, limit=, status=) GET /api/v1/gateway/payments
request_payout(amount=, idempotency_key=, settlement_method=) POST /api/v1/gateway/payouts
get_rates() GET /api/v1/rates
get_balances() GET /api/v1/gateway/balances
get_webhook_config() GET /api/v1/gateway/webhooks/config
update_webhook_config(url=, events=, is_active=) PUT /api/v1/gateway/webhooks/config
rotate_webhook_secret() POST /api/v1/gateway/webhooks/config/rotate
delete_webhook_config() DELETE /api/v1/gateway/webhooks/config
create_payment_link(name=, ...) POST /api/v1/gateway/payment-links
list_payment_links() GET /api/v1/gateway/payment-links
get_payment_link(link_id) GET /api/v1/gateway/payment-links/{id}

Each API key carries scopes. A key without the right scope gets a BitmomoError with status 403.

Errors and retries

Every failure raises bitmomo.BitmomoError with status, code, message, request_id and retriable. status is 0 when no response arrived (NETWORK_ERROR) or the response broke the contract (SCHEMA_ERROR).

  • Reads retry automatically on 429 and 5xx, twice by default (max_retries=), honouring Retry-After up to 60 seconds.
  • Writes are never retried for you. Retry them yourself with the same idempotency key; request_payout refuses to send without one.
  • Redirects are refused, so your API key is never sent to another host.
  • base_url must be an HTTPS origin (plain HTTP only for localhost).

Money

Money fields are decimal.Decimal. Use format(value, "f") to print them without scientific notation. Amounts you send may be Decimal, int or a decimal string; floats are refused because they cannot hold cents exactly.

License

MIT

Metadata

Release files for bitmomo 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitmomo 0.1.0
File Size Uploaded Provenance Actions
bitmomo-0.1.0.tar.gz 21.6 kB Without provenance Details for bitmomo-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitmomo 0.1.0
File Interpreter ABI Platform Actions
bitmomo-0.1.0-py3-none-any.whl Python 3 none any Details for bitmomo-0.1.0-py3-none-any.whl

Total release size: 41.9 kB

Release files / bitmomo-0.1.0.tar.gz

Download URL bitmomo-0.1.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2832daf978f9792b7c4d5f32e78c8cfb81bd228c3d413dda2127b4c117c7082b
BLAKE2b-256 checksum
How to use checksums
505bde475ae485b1b470650c9188d87a3ecadbb7b6f296b11d713aa4c9207305
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / bitmomo-0.1.0-py3-none-any.whl

Download URL bitmomo-0.1.0-py3-none-any.whl
Size 20.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5fd7a4d440cca5e4ec2334a134977312545b0496c19f6dbf3a43b6b46c5f2d2f
BLAKE2b-256 checksum
How to use checksums
a580aef81d59b3ca368dfbf8bfe1375f3fda30919514679614d2d8264fa1e6b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for bitmomo 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page