Skip to main content

Python SDK for the Branta V2 API — payment destination lookup and registration with zero-knowledge encryption support

Project description

Branta Python SDK

Python SDK for the Branta V2 API — payment destination lookup and registration with zero-knowledge encryption support.

Installation

pip install branta

Integration Guide

Quick start

import asyncio
from branta.enums import BrantaServerBaseUrl, PrivacyMode
from branta.options import BrantaClientOptions
from branta.v2 import BrantaService

options = BrantaClientOptions(
    base_url=BrantaServerBaseUrl.Production,
    privacy=PrivacyMode.Strict,
)
service = BrantaService(options)

async def main():
    result = await service.get_payments_by_qr_code("bitcoin:bc1q...")
    if result.payments:
        print(result.payments[0].get_default_value())

asyncio.run(main())

Privacy modes

Mode Behaviour
PrivacyMode.Strict (default) Only ZK lookups. get_payments() raises BrantaPaymentException for plain addresses. get_payments_by_qr_code() returns empty for plain addresses. add_payment() raises if any destination has is_zk=False.
PrivacyMode.Loose Both plain and ZK lookups are permitted.

Looking up a payment by QR code

result = await service.get_payments_by_qr_code(qr_text)
# result.payments — list of Payment objects (empty if not found)
# result.verify_url — always populated; share with the payer to verify

Prefer get_payments_by_qr_code for QR-driven flows. It handles multi-destination payloads (branta_id / branta_secret fragments) automatically.

Looking up a payment by destination value

# Plain bitcoin address (requires PrivacyMode.Loose or will raise):
result = await service.get_payments("bc1q...")

# ZK-encrypted bitcoin address with secret:
result = await service.get_payments(encrypted_address, destination_encryption_key="my-secret")

# BOLT-11 invoice (hash-ZK — works in strict mode):
result = await service.get_payments("lnbc...")

Registering a payment

from branta.enums import DestinationType

builder = service.create_payment_builder()
payment = (
    builder
    .add_destination("bc1q...", DestinationType.BitcoinAddress).set_zk()
    .add_destination("lnbc...", DestinationType.Bolt11).set_zk()
    .set_description("Donation")
    .add_metadata("email", "donor@example.com")
    .build()
)

result = await service.add_payment(payment, BrantaClientOptions(
    base_url=BrantaServerBaseUrl.Production,
    default_api_key="your-api-key",
    privacy=PrivacyMode.Strict,
))
# result.payment — the registered payment from the server
# result.secret — the random encryption key for the bitcoin address
# result.verify_url — share this URL to verify the payment

Validating an API key

is_valid = await service.is_api_key_valid(BrantaClientOptions(
    base_url=BrantaServerBaseUrl.Production,
    default_api_key="your-api-key",
))

Per-call option overrides

Every public method accepts an optional BrantaClientOptions parameter that overrides the service's default options for that call only:

service = BrantaService(default_options)
result = await service.get_payments("lnbc...", options=override_options)

ZK destination types

Type Encryption
BitcoinAddress Random secret (GUID) per payment
Bolt11 Deterministic: SHA256 of lowercase invoice
ArkAddress Deterministic: SHA256 of lowercase address
SilentPayment Deterministic: SHA256 of lowercase address

Development

pip install -e ".[dev]"
pytest tests/ --ignore=tests/test_integration.py     # unit tests
pytest tests/test_integration.py                     # integration (requires network)
coverage run -m pytest tests/ --ignore=tests/test_integration.py && coverage report

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

branta-3.2.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

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

branta-3.2.0-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file branta-3.2.0.tar.gz.

File metadata

  • Download URL: branta-3.2.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for branta-3.2.0.tar.gz
Algorithm Hash digest
SHA256 30b5c6df372e92aded3e2366eacbf26ed0a75f7eed4d232614a56fe88b5a10b5
MD5 d87f781e265b76c56d3ab668d8e1bf00
BLAKE2b-256 9b750c5fb88c840fe8d4e0b089b8925369322007e2385b508f3531dc6bc75a58

See more details on using hashes here.

File details

Details for the file branta-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: branta-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for branta-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b7490386a0b3cc0df1dd1bc1f942956f1356a096f83e11a6ef3625034fc64d2
MD5 057b43c22bcc4120c8b769545944caf0
BLAKE2b-256 a4ec35d7e6038fb7feaf7d701e22894bafcb0f8e9f60a382277fba70bf199e30

See more details on using hashes here.

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