Cuenca API Client
Project description
Cuenca – Python client library
Installation
pip install cuenca
Authentication
The preferred way to configure the credentials for the client is to set the
CUENCA_API_KEY
and CUENCA_API_SECRET
environment variables. The client
library will automatically configure based on the values of those variables.
To configure manually:
import cuenca
cuenca.configure(api_key='PKxxxx', api_secret='yyyyyy')
Jwt
JWT tokens can also be used if your credentials have enough permissions. To
do so, you may include the parameter use_jwt
as part of your configure
import cuenca
cuenca.configure(use_jwt=True)
A new token will be created at this moment and automatically renewed before sending any request if there is less than 5 minutes to be expired according to its payload data.
Transfers
Create transfer
import cuenca
cuenca.configure(sandbox=True) # if using sandbox
local_transfer_id = '078efdc20bab456285437309c4b75673'
transfer = cuenca.Transfer.create(
recipient_name='Benito Juárez',
account_number='646180157042875763', # CLABE or card number
amount=12345, # Mx$123.45
descriptor='sending money', # As it'll appear for the customer
idempotency_key=local_transfer_id
)
# To get updated status
transfer.refresh()
Retrieve by id
import cuenca
transfer = cuenca.Transfer.retrieve('tr_123')
Query by idempotency_key
, account_number
and status
Results are always returned in descending order of created_at
The methods that can be used:
one()
- returns a single result. RaisesNoResultFound
if there are no results andMultipleResultsFound
if there are more than onefirst()
- returns the first result orNone
if there aren't anyall()
- returns a generator of all matching results. Pagination is handled automatically as you iterate over the responsecount()
- returns an integer with the count of the matching results
import cuenca
from cuenca.types import Status
# find the unique transfer using the idempotency key
local_transfer_id = '078efdc20bab456285437309c4b75673'
transfer = cuenca.Transfer.one(idempotency_key=local_transfer_id)
# returns a generator of all succeeded transfers to the specific account
transfers = cuenca.Transfer.all(
account_number='646180157000000004',
status=Status.succeeded
)
# the total number of succeeded transfers
count = cuenca.Transfer.count(status=Status.succeeded)
Api Keys
Create new ApiKey
and deactivate old
import cuenca
# Create new ApiKey
new = cuenca.ApiKey.create()
# Have to use the new key to deactivate the old key
old_id = cuenca.session.auth[0]
cuenca.session.configure(new.id, new.secret)
cuenca.ApiKey.deactivate(old_id, 60) # revoke prior API key in an hour
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
File details
Details for the file cuenca-0.6.2.dev1.tar.gz
.
File metadata
- Download URL: cuenca-0.6.2.dev1.tar.gz
- Upload date:
- Size: 18.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d8700cd8a180e6fdbadd65863341010dd12c3351e19f8fa03833a36ef5e8bd4 |
|
MD5 | df288795942bd1211a6b1cdcade5817c |
|
BLAKE2b-256 | 2a32740f5eec9fa7a74c8a39aaa145dda1d26f700278390e64c6e52d4616e1f7 |
File details
Details for the file cuenca-0.6.2.dev1-py3-none-any.whl
.
File metadata
- Download URL: cuenca-0.6.2.dev1-py3-none-any.whl
- Upload date:
- Size: 27.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb5e171bf62ef20da7ce7ad6e0b61c5d9ff5e1c5cda35b39e6ba04bf453f0c1b |
|
MD5 | 10b89be5d3939b08b7ce3880f0f6d4f1 |
|
BLAKE2b-256 | 39bfc6865ad1f9d088480611f866b954c78c5fa66a35dd773ee37a02faed05a3 |