Skip to main content

Official NakoPay SDK for Python. Accept Bitcoin, Lightning, Litecoin, Monero and more with a Stripe-style API.

Project description

nakopay

PyPI Python License

Official NakoPay SDK for Python. Accept Bitcoin, Lightning, Litecoin, Monero and more with a developer-first REST API.

Install

pip install nakopay

Requires Python 3.8+.

Quickstart (sync)

import os
from nakopay import NakoPay

client = NakoPay(api_key=os.environ["NAKOPAY_SECRET_KEY"])

invoice = client.invoices.create(
    amount="19.99",
    currency="USD",
    coin="BTC",
    description="Pro plan",
    metadata={"order_id": "ORD-1042"},
    idempotency_key="ord_1042",
)

print(invoice.id, invoice.checkout_url)

Async client

import asyncio
from nakopay import AsyncNakoPay

async def main():
    async with AsyncNakoPay() as client:
        invoice = await client.invoices.create(
            amount="9.99",
            currency="USD",
            coin="BTC",
        )
        print(invoice.checkout_url)

        # Async pagination
        page = await client.invoices.list(status="paid")
        async for inv in page.auto_paging_iter():
            print(inv.id, inv.amount)

asyncio.run(main())

Verifying webhooks (Flask)

from flask import request
from nakopay import NakoPay, NakoPayError

client = NakoPay(api_key=os.environ["NAKOPAY_SECRET_KEY"])

@app.post("/webhook")
def webhook():
    try:
        event = client.webhooks.construct_event(
            payload=request.data,
            signature_header=request.headers["X-NakoPay-Signature"],
            secret=os.environ["NAKOPAY_WEBHOOK_SECRET"],
        )
    except NakoPayError:
        return "", 400

    if event.type == "invoice.paid":
        fulfill(event.data["object"])

    return "", 200

Error handling

from nakopay import NakoPayError, AuthenticationError, RateLimitError, IdempotencyError

try:
    client.invoices.create(amount="0", currency="USD", coin="BTC")
except AuthenticationError as e:
    print("Bad API key:", e.message)
except RateLimitError as e:
    print("Slow down:", e.message)
except IdempotencyError as e:
    print("Duplicate request with different params:", e.message)
except NakoPayError as e:
    print(e.code, e.message, e.param, e.request_id, e.http_status)

Pagination

for inv in client.invoices.list(status="paid").auto_paging_iter():
    print(inv.id, inv.amount)

Links

License

MIT

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

nakopay-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

nakopay-1.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file nakopay-1.0.0.tar.gz.

File metadata

  • Download URL: nakopay-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nakopay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b82c8f3372e5d15bb9fa07779769318e488e8f8df57f0d847d0c2c20adab5a6a
MD5 a57e36b7c2442788942d8122ffd203f4
BLAKE2b-256 9d1355a4f9dc449579244a506658a49e0d74ba2166b337afcc8d3358e391f20f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nakopay-1.0.0.tar.gz:

Publisher: release-python.yml on NakoPayHQ/nako-pay-v2-production

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nakopay-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: nakopay-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nakopay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72c5fe913d156a89cba1cb5a7d324cec87f3adf54a86934b4bf49ce2e5b5cd52
MD5 027731b26e4d4085a19264134a7bcfc3
BLAKE2b-256 e38c154b972b97733275d50f9787ccf44971e04330d27192493a2c53c113e138

See more details on using hashes here.

Provenance

The following attestation bundles were made for nakopay-1.0.0-py3-none-any.whl:

Publisher: release-python.yml on NakoPayHQ/nako-pay-v2-production

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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