Skip to main content

Official Python SDK for the Danipa fintech API

Project description

Danipa Python SDK

PyPI Python License: MIT

Official Python SDK for the Danipa fintech API — collections, disbursements, wallets, payment links, invoices, and webhook signature verification.

Install

pip install danipa

Requires Python 3.10+.

Quick start

import os
from danipa import Danipa, RequestOptions
from danipa.models import CreateCollectionRequest, Payer

# Sandbox vs production is inferred from the API key prefix:
#   dk_test_… → https://api.sandbox.danipa.com
#   dk_live_… → https://api.danipa.com
with Danipa(api_key=os.environ["DANIPA_API_KEY"]) as danipa:
    collection = danipa.collections.create(
        CreateCollectionRequest(
            amount="125.00",
            currency="GHS",
            payer=Payer(phone="+233244112233", name="Ama K."),
        ),
        options=RequestOptions(idempotency_key="order-1234"),
    )

Resources

Resource Methods
danipa.collections create, get
danipa.disbursements create, get
danipa.wallets get_balance
danipa.payment_links create
danipa.invoices create

Errors

from danipa import DanipaApiError, DanipaNetworkError

try:
    danipa.collections.create(...)
except DanipaApiError as exc:
    # Backend returned a non-2xx response
    print(exc.status, exc.code, exc.correlation_id, exc.raw)
except DanipaNetworkError as exc:
    # Transport failure (DNS, TLS, timeout). exc.cause is the underlying httpx error.
    ...

DanipaApiError and DanipaNetworkError both inherit from DanipaError — catch the base class once and narrow if you need the details.

Idempotency, retries, timeouts

  • Pass options=RequestOptions(idempotency_key=...) on every mutating call. Backend dedupes on (merchantId, key) so retries (server- or client-side) won't double-charge.
  • Default retry policy: 3 attempts on 5xx and transport failures, with 200 ms × 2^(attempt - 1) exponential backoff capped at 2 s, plus 0–50 ms jitter. 4xx responses never retry — they indicate a client-side fix is needed.
  • Override per client: Danipa(api_key=..., timeout=30.0, max_retries=3). Override per call: RequestOptions(timeout=10.0).

Webhook signature verification

from danipa import verify_webhook

if not verify_webhook(payload, signature, timestamp, secret):
    raise PermissionError("invalid signature")

Cross-SDK parity: every Danipa SDK (Node, Java, Python, PHP) produces identical signatures for the same (payload, secret, timestamp) triple. Drift is treated as a release-blocker.

Framework examples

FastAPI

from fastapi import FastAPI, Header, HTTPException, Request
from danipa import verify_webhook

app = FastAPI()

@app.post("/webhooks/danipa")
async def webhook(
    request: Request,
    x_danipa_signature: str = Header(...),
    x_danipa_timestamp: str = Header(...),
):
    body = (await request.body()).decode("utf-8")
    if not verify_webhook(body, x_danipa_signature, x_danipa_timestamp, SECRET):
        raise HTTPException(status_code=401, detail="invalid signature")
    ...

Flask

from flask import Flask, request, abort
from danipa import verify_webhook

app = Flask(__name__)

@app.post("/webhooks/danipa")
def webhook():
    if not verify_webhook(
        request.get_data(as_text=True),
        request.headers.get("X-Danipa-Signature", ""),
        request.headers.get("X-Danipa-Timestamp", ""),
        SECRET,
    ):
        abort(401)
    ...

Development

pip install -e '.[dev]'
ruff check
mypy --strict src/danipa tests
pytest

Links

License

MIT — see LICENSE.

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

danipa-0.1.0.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

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

danipa-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file danipa-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for danipa-0.1.0.tar.gz
Algorithm Hash digest
SHA256 784574c6d49b1fc606fabadcb81f712d120489e6d1d6ada86592cf47fe7b5b14
MD5 e2067652fde4c0c7bb9ff04e8614fb8a
BLAKE2b-256 26415a7aa64ccbba2dbf22285f2fed6ec4803d19865ddfc1857ad6e6601ecc51

See more details on using hashes here.

Provenance

The following attestation bundles were made for danipa-0.1.0.tar.gz:

Publisher: sdk-python-publish.yml on paboagye/danipa-digital-platform

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

File details

Details for the file danipa-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for danipa-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d1f474ca85a3fc4a8cd532cd8e0a8c85069f6be9662693c51b4995b6f052201
MD5 b746370418e6df7d69b9d63d79cfa2ea
BLAKE2b-256 93942ab944653baa69009e849bd45819adda8e21416ecce9ba253e81c8a72b95

See more details on using hashes here.

Provenance

The following attestation bundles were made for danipa-0.1.0-py3-none-any.whl:

Publisher: sdk-python-publish.yml on paboagye/danipa-digital-platform

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