Skip to main content

Cuenca API Client

Project description

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

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

cuenca-0.7.14.dev0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

cuenca-0.7.14.dev0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file cuenca-0.7.14.dev0.tar.gz.

File metadata

  • Download URL: cuenca-0.7.14.dev0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cuenca-0.7.14.dev0.tar.gz
Algorithm Hash digest
SHA256 394b4f84b571ec1db8aba3d9aacc9db17bd80eda5ac30b425744fd505691b8e6
MD5 96bc6a80c609a796b835cd29805b7b84
BLAKE2b-256 7ccc50c3e73262097ffdf6e627d3df33606ea5d45d4ec162a9a32f6285705c0c

See more details on using hashes here.

File details

Details for the file cuenca-0.7.14.dev0-py3-none-any.whl.

File metadata

  • Download URL: cuenca-0.7.14.dev0-py3-none-any.whl
  • Upload date:
  • Size: 43.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for cuenca-0.7.14.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 384e25718aee75fdc3da272de7eb5c8e40fb5923c060290b3acee9c31d5c855e
MD5 7e73fefa07900b38beef17346655ab12
BLAKE2b-256 fd4be3e611eaf0c39c393b33fe0402517ee10c0820b870beb6ddbe901350da35

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page