A fork of PyPaystack. A simple python wrapper for Paystack API.
Project description
PyPaystack2
A fork of PyPaystack. A simple python wrapper for Paystack API. Checkout Documentation
Installation
- Create your Paystack account to get your Authorization key that is required to use this package.
- Store your authorization key in your environment variable as
PAYSTACK_AUTHORIZATION_KEY
or pass it into the pypaystack api wrappers at instantiation. - Install pypaystack2 package.
pip install -U pypaystack2
What's Pypaystack2
So Paystack provides RESTful API endpoints for developers from different platforms
to integrate their services into their projects. So for python developers, to use
this endpoints, you might opt for a package like requests
to handle all the
API calls which involves a lot of boilerplate. Pypaystack2 abstracts this process
by handling all this complexities under the hood and exposing simple APIs for
your python project. for example
from pypaystack2.api import Miscellaneous # assumes you have installed pypaystack2
from pypaystack2.utils import Country
miscellaneous_wrapper = Miscellaneous() # assumes that your paystack auth key is in
# your enviromental variables i.e PAYSTACK_AUTHORIZATION_KEY=your_key otherwise instatiate
# the Miscellaneous API wrapper as it is done below.
# miscellaneous_wrapper = Miscellaneous(auth_key=your_paystack_auth_key)
response = miscellaneous_wrapper.get_banks(country=Country.NIGERIA,use_cursor=False) # Requires internet connection.
print(response)
With the code snippet above, you have successfully queried Paystack's Miscellaneous API
to get a list of banks supported by paystack. A requests
equivalent of the above will
be like
import requests # assumes you have requests installed.
headers = {
"Content-Type":"application/json",
"Authorization": "Bearer <your_auth_key>"
}
paystack_url = 'https://api.paystack.co/bank?perPage=50&country=ng&use_cursor=false'
response = requests.get(paystack_url,headers=headers) # requires internet connection
print(response.json())
While both approaches achieve the same goal, pypaystack2
uses requests
under the hood and
manages the headers and URL routes to endpoints so you can focus more on the actions. with the miscellaneous_wrapper
in the example above. you can call all endpoints associated with the Miscellaneous API with methods
provided like .get_banks
, .get_providers
, .get_countries
and .get_states
.
Pypaystack2 provides wrappers to all of Paystack APIs in its pypaystack2.api
subpackage.
each of the wrappers are classes named to closely match the Paystack API. so say you want
to use Paystack's Invoices API, you'd import the wrapper with from pypaystack2.api import Invoice
for the Invoices API. All endpoints available on the Invoices API are available as methods
in the Invoice
wrapper. Say you wanted to create an invoice by sending a
POST
request to Paystack's Invoice API endpoint /paymentrequest
, you'll call
Invoice
wrapper's .create
method.
from pypaystack2.api import Invoice
invoice_wrapper = Invoice()
response = invoice_wrapper.create(customer="CUS_xwaj0txjryg393b",amount=10000) # Creates an invoice with a charge of ₦100
print(response)
From here you can check out the tutorials section to get more examples and get familiar or surf the documentation for wrappers and methods you'll need for your next project. Hurray! Documentation
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
Hashes for pypaystack2-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c212abe9aed1b2e1e134d7c62a8d9e53426bc577a390d113318b67155ec7d9da |
|
MD5 | 084d24fe674fb93a0a8d2bf368d3e057 |
|
BLAKE2b-256 | 435de798445a6fd225e2f774ebf546e51205a8cc9887c6fb56ba0ff8a46949d6 |