A Python library for seamlessly integrating the SecurePay payment platform API.
Project description
securepay-api
A Python library for seamlessly integrating the SecurePay payment platform API.
Gives Python developers a clean, typed, fully documented interface - no need to read raw API docs or wire up HTTP calls manually.
Features
- ✅ Fully typed with Pydantic v2 models — request validation + IDE autocomplete
- ✅
httpx-powered HTTP with automatic auth header injection on every request - ✅ UUID-based
X-Request-IDtracing per request - ✅ Automatic retry with exponential back-off via
tenacity - ✅ Structured logging (staging only, auto-disabled in production)
- ✅
SecurePayExceptionhierarchy for clean, specific error handling - ✅ Context manager support (
with SecurePayApi(...) as client:) - ✅ Staging and production environment presets
Installation
pip install securepay-api
Quick Start
from securepay import SecurePayApi, SecurePayConfig
client = SecurePayApi(
api_key="SP-PK-xxxx",
config=SecurePayConfig.staging(enable_logging=True), # Development
# config=SecurePayConfig.production(), # Production
)
Direct Debit — Full Example
from datetime import date
from securepay import (
SecurePayApi, SecurePayConfig,
BankAccount, CreateMandateRequest, DebitFrequency,
InitiateDebitRequest, MandateStatus, UpdateMandateRequest,
)
client = SecurePayApi(api_key="SP-PK-xxxx", config=SecurePayConfig.staging())
# POST — Create a mandate
mandate = client.direct_debit.create_mandate(
CreateMandateRequest(
customer_name="Ada Obi",
customer_email="ada@example.com",
customer_phone="+2348012345678",
bank_account=BankAccount(
account_number="0123456789",
bank_code="058",
account_name="Ada Obi",
),
amount=5000.00,
frequency=DebitFrequency.MONTHLY,
start_date=date(2025, 8, 1),
)
)
print(mandate.mandate_id) # mnd_abc123
# GET — Fetch mandate
fetched = client.direct_debit.get_mandate(mandate.mandate_id)
# GET — List mandates
mandates = client.direct_debit.list_mandates(page=1, page_size=20)
# PUT — Update mandate
updated = client.direct_debit.update_mandate(
mandate.mandate_id,
UpdateMandateRequest(amount=7500.00),
)
# PATCH — Suspend mandate
client.direct_debit.patch_mandate_status(
mandate.mandate_id,
status=MandateStatus.SUSPENDED,
reason="Customer requested pause.",
)
# POST — Initiate a collection
collection = client.direct_debit.initiate_collection(
mandate.mandate_id,
InitiateDebitRequest(amount=5000.00, narration="August subscription"),
)
# DELETE — Cancel mandate
client.direct_debit.cancel_mandate(mandate.mandate_id)
Error Handling
from securepay import (
SecurePayException,
SecurePayUnauthorizedError,
SecurePayValidationError,
SecurePayNotFoundError,
SecurePayNetworkError,
)
try:
mandate = client.direct_debit.get_mandate("mnd_xyz")
except SecurePayUnauthorizedError:
print("Invalid API key")
except SecurePayNotFoundError:
print("Mandate not found")
except SecurePayValidationError as e:
print(f"Bad request: {e.message}")
except SecurePayNetworkError:
print("No internet connection")
except SecurePayException as e:
print(f"Unexpected error: {e}")
Configuration
| Option | Type | Default | Description |
|---|---|---|---|
base_url |
str |
Staging URL | API base URL |
timeout |
float |
30.0 |
Request timeout in seconds |
max_retries |
int |
3 |
Max retry attempts |
enable_logging |
bool |
False |
Log requests/responses |
enable_retry |
bool |
True |
Auto-retry on transient errors |
API Coverage
| Section | Status |
|---|---|
| Direct Debit | ✅ |
| Transfers | ✅ |
| Checkout | ✅ |
| Key Management | ✅ |
Development
# Clone and set up
git clone https://github.com/seniorman-dev/SecurePay-Python-Library.git
cd securepay_python
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
# Run tests
pytest
# Lint
ruff check .
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
securepay_api-0.0.3.tar.gz
(22.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file securepay_api-0.0.3.tar.gz.
File metadata
- Download URL: securepay_api-0.0.3.tar.gz
- Upload date:
- Size: 22.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a5daad655493d9f8bdbd4c445094096d3db7e8f067c05f29dfde47e08099056
|
|
| MD5 |
79a21504832ca6854a606dd691fa68cb
|
|
| BLAKE2b-256 |
4052b5f4d78457bb946fb5cf795762c623416031f0742fecd13427e9a54a5c98
|
File details
Details for the file securepay_api-0.0.3-py3-none-any.whl.
File metadata
- Download URL: securepay_api-0.0.3-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ac6d55ef36baadb2dda646bef8506738e41bd5574368e8df6f0134333006196
|
|
| MD5 |
a410e69ebca6f7aaa54d347328b21ff8
|
|
| BLAKE2b-256 |
b6b2d56a23bce70504bcda63b73520c6ba8ccc773330e3d9cd8e0f05d066dd98
|