This release is a pre-release and may not be stable for production use.
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. RaisesNoResultFoundif there are no results andMultipleResultsFoundif there are more than onefirst()- returns the first result orNoneif 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)
Balance
Current balance
import cuenca
# balance is the amount in cents
balance = cuenca.get_balance()
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
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')
... # authenticated operation
cuenca.UserLogin.logout()
Create login token for biometrics
# Must be logged in
cuenca.UserLogin.create(password='1234567890')
token = cuenca.LoginToken.create()
cuenca.UserLogin.logout()
# Then you can use the token which lasts for 7 days
cuenca.configure(login_token=token)
... # authenticated operation
Metadata
Release files for cuenca 2.2.5.dev0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cuenca-2.2.5.dev0.tar.gz | 43.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cuenca-2.2.5.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 123.4 kB
Release files / cuenca-2.2.5.dev0.tar.gz
| Download URL | cuenca-2.2.5.dev0.tar.gz |
|---|---|
| Size | 43.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b389f5df61180493f48e2d654a430067b2add5e68a972ab20412d93a41b4ccff
|
|
BLAKE2b-256 checksum How to use checksums |
3ece3acb70b020aad177796b9c566e33258d99ee1b8c778c6993138430bbd024
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / cuenca-2.2.5.dev0-py3-none-any.whl
| Download URL | cuenca-2.2.5.dev0-py3-none-any.whl |
|---|---|
| Size | 80.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
acc2163c5aa34e8407f54b388d3a2349452437c30bdb2d46bca6033685d9d047
|
|
BLAKE2b-256 checksum How to use checksums |
7b93a2324a0f16aa12e69267b2fab29c9f0ffd6084992d0d51a4332467780c6a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|