Prerequisites

To complete this guide, you will need the following:

1. Install the ZBD Python package

Install the official ZBD Python SDK from PyPI:

pip install zbdpay

2. Send and receive Bitcoin

Get started with just a few lines of code. Here’s how to send a payment to any Lightning Address:

import os
from zbdpay import ZbdPayments

# Initialize the client
client = ZbdPayments(
    apikey=os.environ.get("ZBD_PAYMENTS_API_KEY")
)

# Send instant Bitcoin payment
response = client.lightning_address.send_payment(
    amount="500000",  # Amount in millisatoshis
    comment="Instant global payments",
    ln_address="andre@zbd.gg"
)

print(f"Payment sent! Transaction ID: {response.data.id}")

3. Create a payment request

Accept Bitcoin payments by creating a charge:

# Create a charge (payment request)
charge = client.lightning_charges.create(
    amount="100000",  # 100 satoshis
    description="Payment for your product",
    expires_in=300  # Expires in 5 minutes
)

print(f"Payment Request: {charge.data.invoice.request}")
print(f"QR Code: {charge.data.invoice.uri}")

You’re looking for the data.invoice.request property in the response. It starts with lnbc1 and is the payment request anyone in the Bitcoin Lightning Network can use to pay you.

Payment requests are usually shown to users as QR codes that can be scanned by mobile apps (e.g. ZBD). Read Callbacks to understand how to receive updates about your payments asynchronously.

Async Support

The SDK also supports async operations for better performance:

import asyncio
from zbdpay import AsyncZbdPayments

async def main():
    client = AsyncZbdPayments(
        apikey=os.environ.get("ZBD_PAYMENTS_API_KEY")
    )
    
    # Send payment asynchronously
    await client.lightning_address.send_payment(
        amount="500000",
        comment="Async payment",
        ln_address="andre@zbd.gg"
    )

asyncio.run(main())

Next Steps

Ready to dive deeper? Check out these resources:

Advanced Usage

For more advanced features like custom timeouts, retries, and raw response access, check out the full documentation on PyPI.