Py
Python SDK
The official Python library: add crypto payments to Django, Flask or FastAPI in a few lines.
Installation
With pip (recommended):
pip install mercanpay
For offline servers download the .whl file and run pip install mercanpay-1.0.0-py3-none-any.whl.
Creating an invoice
from mercanpay import MercanPay
zp = MercanPay("https://mercanpay.com", "mp_...") # API key from your merchant panel
# USD-priced invoice: the customer picks the coin on the payment page
inv = zp.create_invoice(price_usd="25", order_id="order-1001", callback_url="https://shop.example/hook")
print(inv["payment_url"])
Verifying webhooks (Flask)
from mercanpay import verify_webhook
@app.post("/hook")
def hook():
if not verify_webhook(SECRET, request.get_data(), request.headers.get("X-MercanPay-Signature", "")):
abort(401)
event = request.get_json()
if event["type"] == "invoice.paid":
... # mark the order as paid
return "ok"
Payouts
w = zp.create_withdrawal("USDT", "10", "T...", idempotency_key="wd-123")
print(w["status"]) # queued -> processing -> completed
Errors raise MercanPayError (.status, .code, .message). See the documentation for every endpoint.