Python wrapper for Paystack API
Project description
Paystack4Python
A Python SDK for integrating with the Paystack payment gateway. This library provides a simple and consistent interface for interacting with Paystack's API, making it easy to manage customers, transactions, plans, and more from your Python applications.
Features
- Customer management (create, fetch, update, list)
- Transaction initialization, verification, and listing
- Plan creation and management
- Utilities for validating data
- Custom error handling
- Designed for easy integration with Django, Flask, or any Python project
Installation
Install via pip (recommended):
pip install paystack4python
Or clone this repository and install locally:
git clone https://github.com/yourusername/paystack4python.git
cd paystack4python
pip install .
Requirements
- Python 3.6+
- Requests (install via pip if not already present)
Usage
Basic Setup
from paystack4python.baseapi import PaystackAPI
# Initialize with your secret key
gateway = PaystackAPI(secret_key='sk_test_xxx')
Customers
# Create a customer
customer = gateway.customers.create(email='user@example.com', first_name='John', last_name='Doe')
# Fetch a customer
customer = gateway.customers.fetch(customer_id='CUS_xxxxx')
# List customers
customers = gateway.customers.list()
Transactions
# Initialize a transaction
transaction = gateway.transactions.initialize(email='user@example.com', amount=5000)
# Verify a transaction
result = gateway.transactions.verify(reference='txn_ref')
Plans
# Create a plan
plan = gateway.plans.create(name='Monthly Plan', amount=10000, interval='monthly')
# List plans
plans = gateway.plans.list()
Utilities
from paystack4python.utils import validate_amount, validate_interval
validate_amount(1000) # Returns 1000
validate_interval('monthly') # Returns 'monthly'
Error Handling
All errors are raised as subclasses of paystack4python.errors.InvalidDataError for easy exception handling.
from paystack4python.errors import InvalidDataError
try:
validate_amount('abc')
except InvalidDataError as e:
print(f"Validation failed: {e}")
Running Tests
Tests are located in the tests/ directory. To run all tests:
python -m unittest discover tests
Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/YourFeature) - Open a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgements
- Paystack Documentation
- Inspired by the official Paystack Python SDKs and community libraries
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
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 paystack4python-1.1.tar.gz.
File metadata
- Download URL: paystack4python-1.1.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fe97f36c41d9788cc8e74207c64a8928aec76822e05fc2af9b9197c1adb04d6
|
|
| MD5 |
e50ba895c61fc9c7786ceaec6768d12f
|
|
| BLAKE2b-256 |
3a97d4281e5f26aa0c1a3144fbb1a4cf1b6efbdccfbd021ab508aee323026e3d
|
File details
Details for the file paystack4python-1.1-py3-none-any.whl.
File metadata
- Download URL: paystack4python-1.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
289c5cdc621398a60b6dd6ef6f7d9e58fe579a6e866d17534b7cd577a2a4d392
|
|
| MD5 |
563f195d72602e0629bc6a9897b820ed
|
|
| BLAKE2b-256 |
38cffa39ba470953d233a35261c9853c5a7e2c6708c0c97f86d57d79402f12d8
|