A Python client library for the Paystack API. This package provides convenient access to Paystack's payment services, allowing you to manage customers, transactions, plans, and more from your Python applications.
- Easy integration with Paystack's RESTful API
- Manage customers, transactions, and plans
- Error handling and utility functions
- Pythonic interface for common Paystack operations
Install via pip:
pip install paystack4pythonOr clone this repository and install locally:
git clone https://github.com/mwaiseghegift/paystack4python.git
cd paystack4python
pip install .First, import the relevant classes and initialize the API with your secret key:
from paystack4python.baseapi import PaystackBaseAPI
from paystack4python.customers import CustomersAPI
from paystack4python.transactions import TransactionsAPI
from paystack4python.plans import PlansAPI
# Initialize the base API with your Paystack secret key
api = PaystackBaseAPI(secret_key='sk_test_xxx')
# Customers
customers = CustomersAPI(api)
response = customers.create(email='[email protected]', first_name='John', last_name='Doe')
# Transactions
transactions = TransactionsAPI(api)
response = transactions.initialize(email='[email protected]', amount=5000)
# Plans
plans = PlansAPI(api)
response = plans.create(name='Monthly Plan', amount=10000, interval='monthly')All API requests require your Paystack secret key. Pass it when initializing PaystackBaseAPI.
baseapi.py: Core API request logic and authenticationcustomers.py: Customer management (create, fetch, update, list)transactions.py: Transaction initialization, verification, listingplans.py: Plan creation, update, listingerrors.py: Custom exceptions for error handlingutils.py: Helper functions
from paystack4python.baseapi import PaystackBaseAPI
from paystack4python.customers import CustomersAPI
api = PaystackBaseAPI(secret_key='sk_test_xxx')
customers = CustomersAPI(api)
response = customers.create(email='[email protected]', first_name='Jane', last_name='Doe')
print(response)from paystack4python.baseapi import PaystackBaseAPI
from paystack4python.transactions import TransactionsAPI
api = PaystackBaseAPI(secret_key='sk_test_xxx')
transactions = TransactionsAPI(api)
response = transactions.initialize(email='[email protected]', amount=10000)
print(response)All API errors raise custom exceptions defined in errors.py. Use try/except blocks to handle errors gracefully.
from paystack4python.errors import PaystackAPIError
try:
# ... your code ...
except PaystackAPIError as e:
print(f"Paystack error: {e}")Run tests using pytest:
pytest tests/Contributions are welcome! Please open issues or submit pull requests for bug fixes, features, or improvements.
- 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
This project is licensed under the MIT License. See the LICENCE file for details.