Skip to main content

Official Python SDK for the NezaHub API

Project description

NezaHub Python SDK

Official Python client for the NezaHub REST API (/api/v1/).

Install

pip install nezahub

Local development (monorepo):

cd sdks/python
pip install -e ".[dev]"
# or from repo root:
make sdk-python

Requires Python 3.10+.

Environments

Environment base_url
Local dev http://localhost:8000 (default)
Sandbox https://sandbox-api.nezahub.com
Live https://api.nezahub.com
export NEZAHUB_BASE_URL=https://api.nezahub.com
export NEZAHUB_API_KEY=nz_live_...

Server client (API key)

from nezahub import NezaHubClient, nezahub_setup

nezahub_setup(api_key="nz_test_xxx", on_error=print)

with NezaHubClient() as client:
    print(client.health())
    for product in client.products.list_auto():
        print(product["name"])

Server client (JWT login)

from nezahub import NezaHubClient

bootstrap = NezaHubClient(base_url="http://localhost:8000")

# Phone + password
session = bootstrap.auth.login(phone="+254700000099", password="demo12345")

client = NezaHubClient(access_token=session["tokens"]["access"])
print(client.auth.me())

Email + password login is supported by the API (POST /auth/login/ with email) but not yet on auth.login — use client._http.request("POST", "/api/v1/auth/login/", json={...}) or REST directly.

Phone OTP login uses POST /auth/otp/send/ and POST /auth/otp/verify/ — call via HTTP until dedicated SDK methods ship.

Browser-safe checkout

No API key — public checkout endpoints only:

from nezahub.checkout import NezaHubCheckoutClient

with NezaHubCheckoutClient(environment="test") as checkout:
    session = checkout.start_from_link("your-link-slug", customer_phone="+254700000099")
    checkout.confirm_stk(session["id"], otp_code="123456")

For hosted sandbox, set base_url="https://sandbox-api.nezahub.com".

Resources

Namespace Examples
client.auth login, me, refresh_token, verify_2fa
client.products list, create, update, delete
client.prices create, update, charge distribution
client.checkout create_session, confirm
client.transactions list, get
client.agents CRUD, assignments
client.payouts balance, create (2FA)
client.wallets FX quote, transfer (2FA)

Webhooks

from nezahub.webhooks import construct_event

event = construct_event(payload, signature, secret)

Integration tests

make dev && make migrate
# seed demo seller (see ../flows/README.md)

cd sdks/python
NEZAHUB_INTEGRATION=1 NEZAHUB_2FA_CODE=123456 pytest tests/test_integration_flow.py -v

Tests (unit)

pytest

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

nezahub-0.2.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

nezahub-0.2.1-py3-none-any.whl (22.7 kB view details)

Uploaded Python 3

File details

Details for the file nezahub-0.2.1.tar.gz.

File metadata

  • Download URL: nezahub-0.2.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for nezahub-0.2.1.tar.gz
Algorithm Hash digest
SHA256 db904c939ff020abd6d4c6eabdcf5379da945d1ee07edb355f2ae5060a79200f
MD5 74cdcb88da52b67e3f8632b375a15dc6
BLAKE2b-256 211aa223d304663b20194b7dfad398a9ca02f82a642e58127889b17207defb11

See more details on using hashes here.

File details

Details for the file nezahub-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nezahub-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 22.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for nezahub-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 463e14018439b8bd1bd24fe74f59b189b22d02ffb20a07a4332c1c8ecf1bba50
MD5 98c73f731c6a8c797d5b1c0ea1e7d9aa
BLAKE2b-256 7d045dc01c9658487144549717cdc49d65759993fc17242bc114929849cef19d

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