Skip to main content

afrikdp

Official Python client for the AfriKDP Publishing API — publishing infrastructure for Africa. Upload a book once, sell it everywhere, without building storage, checkout, or delivery yourself.

Requires Python 3.8+.

Install

pip install afrikdp

Quick start

from afrikdp import AfriKDPClient

client = AfriKDPClient(secret_key="sk_live_...")

book = client.upload_book(
    title="Ubuntu",
    description="A short reflection on community and shared humanity.",
    price=2500,       # whole currency units — 2500 = ₦2,500. 0 = free.
    currency="NGN",
    file="./ubuntu.pdf",
    cover="./cover.jpg",
)

print(book["book_id"], book["slug"])
# → bk_8937  ubuntu-8937a1c2

That's it — AfriKDP stores the file, generates the book's slug, and it's ready to sell.

Two kinds of keys

Key Used for Where it belongs
sk_live_... (secret) Uploading/updating books, webhooks, distribution Your server only
pk_live_... (public) Listing/fetching books, checkout, verify Safe in a browser, but this package is meant for your backend
# Full access
client = AfriKDPClient(secret_key="sk_live_...")

# Read-only — fine if this process should never be able to upload/edit
client = AfriKDPClient(public_key="pk_live_...")

If you pass secret_key, it's used for everything (including reads). Pass only public_key if you deliberately want a read-only client.

Uploading a book

result = client.upload_book(
    title="Ubuntu",
    description="...",
    price=2500,
    currency="NGN",              # optional, defaults to NGN
    file="./ubuntu.pdf",         # a file path, or raw bytes
    cover="./cover.jpg",         # optional — a file path, or raw bytes
    visibility="public",         # "public" | "private" | "unlisted"
    external_book_id="my-db-id-123",  # optional — your own ID, for mapping back
)

Updating a book

Editing a book that already exists on AfriKDP — only pass the fields that changed:

client.update_book("bk_8937", price=3000)

# Replacing the file too:
client.update_book("bk_8937", price=3000, file="./ubuntu-v2.pdf")

Listing and fetching books

books = client.list_books()
one = client.get_book("bk_8937")

Checkout (server-side)

Most integrations should use the browser SDK for checkout — it opens a branded modal and handles Paystack's inline popup for you. Use this only if you're building your own checkout UI:

order = client.checkout(
    book_id="bk_8937",
    buyer_email="reader@example.com",
    buyer_country="NG",  # optional
)

if order["free"]:
    # order["order_id"] is already paid — go straight to get_download_link()
    pass
else:
    # order["reference"], order["amount"], order["paystack_public_key"]
    # → hand these to Paystack's inline.js in the browser
    pass

After the buyer pays:

result = client.verify_payment(order["reference"])
if result["status"] == "paid":
    link = client.get_download_link(result["order_id"])
    # link["download_url"] is valid for 2 minutes

Distribution

marketplace = client.create_marketplace(
    marketplace_name="Sarah's Bookstore",
    domain="books.sarah.com",
    visibility="private",
)

client.push_distribution(
    book_id="bk_8937",
    marketplace_ids=[marketplace["marketplace"]["id"]],
)

Webhooks

hook = client.register_webhook(
    url="https://yoursite.com/hooks/afrikdp",
    events=["book.created", "sale.completed"],
)
print(hook["secret"])  # shown once — store it now

Verifying an incoming webhook (use the raw request body, not a re-parsed dict) — example with Flask:

from flask import Flask, request
from afrikdp import AfriKDPClient
import os

app = Flask(__name__)

@app.route("/hooks/afrikdp", methods=["POST"])
def afrikdp_webhook():
    signature = request.headers.get("X-AfriKDP-Signature", "")
    valid = AfriKDPClient.verify_webhook_signature(
        request.get_data(), signature, os.environ["AFRIKDP_WEBHOOK_SECRET"]
    )
    if not valid:
        return "Invalid signature", 401

    event = request.get_json()
    # handle event["event"], event["data"]
    return "", 200

Error handling

Every method raises AfriKDPError on a non-2xx response:

from afrikdp import AfriKDPClient, AfriKDPError

try:
    client.upload_book(title="t", description="d", price=0, file=b"...")
except AfriKDPError as err:
    print(err.status, str(err), err.body)

Configuration

AfriKDPClient(
    secret_key="sk_live_...",
    api_base="https://afrikdp.com/v1",  # optional override
    timeout=30,                          # optional, seconds
)

License

MIT

Metadata

Release files for afrikdp 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afrikdp 1.0.0
File Size Uploaded Provenance Actions
afrikdp-1.0.0.tar.gz 8.1 kB Without provenance Details for afrikdp-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for afrikdp 1.0.0
File Interpreter ABI Platform Actions
afrikdp-1.0.0-py3-none-any.whl Python 3 none any Details for afrikdp-1.0.0-py3-none-any.whl

Total release size: 15.8 kB

Release files / afrikdp-1.0.0.tar.gz

Download URL afrikdp-1.0.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d7c6c32748034e83eda00c8b57fd120d0212d0eac291cb06472dcd3c7a9095e7
BLAKE2b-256 checksum
How to use checksums
58412600c89f188b3dc150a1825858d00935e29def3f9e6d9b1d1da1a9ff09a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / afrikdp-1.0.0-py3-none-any.whl

Download URL afrikdp-1.0.0-py3-none-any.whl
Size 7.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
caac62aee5ee3a2602aef8ff92e59243379ad15cf400effc5c2b2e03c9eb359c
BLAKE2b-256 checksum
How to use checksums
57e211a652a5ecbf0f87292626d2aa339d9ace2091ca2fc21471239afebca021
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for afrikdp 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page