Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Cuenca – Python client library

test codecov PyPI

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. Raises NoResultFound if there are no results and MultipleResultsFound if there are more than one
  • first() - returns the first result or None if there aren't any
  • all() - returns a generator of all matching results. Pagination is handled automatically as you iterate over the response
  • count() - 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 0.14.2.dev201

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cuenca 0.14.2.dev201
File Size Uploaded Provenance Actions
cuenca-0.14.2.dev201.tar.gz 34.5 kB Without provenance Details for cuenca-0.14.2.dev201.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cuenca 0.14.2.dev201
File Interpreter ABI Platform Actions
cuenca-0.14.2.dev201-py3-none-any.whl Python 3 none any Details for cuenca-0.14.2.dev201-py3-none-any.whl

Total release size: 94.7 kB

Release files / cuenca-0.14.2.dev201.tar.gz

Download URL cuenca-0.14.2.dev201.tar.gz
Size 34.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2d18cb7acb567012cc23f1a98ac41a19d095fa72fa5bf361d91a0cf3dc5552b
BLAKE2b-256 checksum
How to use checksums
41c5f22760fc9b30aa36e418182e622699423d5bf87b5d175bafb94d2eb43ea9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / cuenca-0.14.2.dev201-py3-none-any.whl

Download URL cuenca-0.14.2.dev201-py3-none-any.whl
Size 60.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62573f45cb141e3a72e40d42bb197178c277ddbf61a6d96fd363ad80134f5781
BLAKE2b-256 checksum
How to use checksums
5e2102d874368cd97b3ae91ff1867d504de478360ae640ad010dab0ea0f205e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Security for cuenca 0.14.2.dev201

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page