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)
local_transfer_id = '078efdc20bab456285437309c4b75673'
transfer = cuenca.Transfer.create(
recipient_name='Benito Juárez',
account_number='646180157042875763',
amount=12345,
descriptor='sending money',
idempotency_key=local_transfer_id
)
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. Raises NoResultFound
if there are no
results and MultipleResultsFound
if there are more than onefirst()
- returns the first result or None
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
local_transfer_id = '078efdc20bab456285437309c4b75673'
transfer = cuenca.Transfer.one(idempotency_key=local_transfer_id)
transfers = cuenca.Transfer.all(
account_number='646180157000000004',
status=Status.succeeded
)
count = cuenca.Transfer.count(status=Status.succeeded)
Balance
Current balance
import cuenca
balance = cuenca.get_balance()
Api Keys
Create new ApiKey
and deactivate old
import cuenca
new = cuenca.ApiKey.create()
old_id = cuenca.session.auth[0]
cuenca.session.configure(new.id, new.secret)
cuenca.ApiKey.deactivate(old_id, 60)
Login
Create a new password
cuenca.UserCredential.create(password='1234567890')
To update your password
cuenca.UserCredential.update(password='1234567890')
To reset password
cuenca.UserCredential.update(password=None)
Login in and out
cuenca.UserLogin.create(password='1234567890')
...
cuenca.UserLogin.logout()
Create login token for biometrics
cuenca.UserLogin.create(password='1234567890')
token = cuenca.LoginToken.create()
cuenca.UserLogin.logout()
cuenca.configure(login_token=token)
...