Official NakoPay SDK for Python. Accept Bitcoin, Lightning, Litecoin, Monero and more with a Stripe-style API.
Project description
nakopay
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b82c8f3372e5d15bb9fa07779769318e488e8f8df57f0d847d0c2c20adab5a6a
|
|
| MD5 |
a57e36b7c2442788942d8122ffd203f4
|
|
| BLAKE2b-256 |
9d1355a4f9dc449579244a506658a49e0d74ba2166b337afcc8d3358e391f20f
|
Provenance
The following attestation bundles were made for nakopay-1.0.0.tar.gz:
Publisher:
release-python.yml on NakoPayHQ/nako-pay-v2-production
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nakopay-1.0.0.tar.gz -
Subject digest:
b82c8f3372e5d15bb9fa07779769318e488e8f8df57f0d847d0c2c20adab5a6a - Sigstore transparency entry: 1637839361
- Sigstore integration time:
-
Permalink:
NakoPayHQ/nako-pay-v2-production@0710c1c28a9699cb26c7545b45bc1a560c5c83fd -
Branch / Tag:
refs/tags/python-v1.0.0 - Owner: https://github.com/NakoPayHQ
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@0710c1c28a9699cb26c7545b45bc1a560c5c83fd -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72c5fe913d156a89cba1cb5a7d324cec87f3adf54a86934b4bf49ce2e5b5cd52
|
|
| MD5 |
027731b26e4d4085a19264134a7bcfc3
|
|
| BLAKE2b-256 |
e38c154b972b97733275d50f9787ccf44971e04330d27192493a2c53c113e138
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nakopay-1.0.0-py3-none-any.whl -
Subject digest:
72c5fe913d156a89cba1cb5a7d324cec87f3adf54a86934b4bf49ce2e5b5cd52 - Sigstore transparency entry: 1637839527
- Sigstore integration time:
-
Permalink:
NakoPayHQ/nako-pay-v2-production@0710c1c28a9699cb26c7545b45bc1a560c5c83fd -
Branch / Tag:
refs/tags/python-v1.0.0 - Owner: https://github.com/NakoPayHQ
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-python.yml@0710c1c28a9699cb26c7545b45bc1a560c5c83fd -
Trigger Event:
push
-
Statement type: