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
Metadata
Release files for securepay-api 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| securepay_api-0.0.3.tar.gz | 22.0 kB | Without provenance | Details for securepay_api-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| securepay_api-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for securepay_api-0.0.3-py3-none-any.whl |
Total release size: 44.5 kB
Release files / securepay_api-0.0.3.tar.gz
| Download URL | securepay_api-0.0.3.tar.gz |
|---|---|
| Size | 22.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a5daad655493d9f8bdbd4c445094096d3db7e8f067c05f29dfde47e08099056
|
|
BLAKE2b-256 checksum How to use checksums |
4052b5f4d78457bb946fb5cf795762c623416031f0742fecd13427e9a54a5c98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / securepay_api-0.0.3-py3-none-any.whl
| Download URL | securepay_api-0.0.3-py3-none-any.whl |
|---|---|
| Size | 22.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ac6d55ef36baadb2dda646bef8506738e41bd5574368e8df6f0134333006196
|
|
BLAKE2b-256 checksum How to use checksums |
b6b2d56a23bce70504bcda63b73520c6ba8ccc773330e3d9cd8e0f05d066dd98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for securepay-api 0.0.3
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.