# Cuenca – Python client library
[](https://github.com/cuenca-mx/cuenca-python/actions?query=workflow%3Atest)
[](https://codecov.io/gh/cuenca-mx/cuenca-python)
[](https://pypi.org/project/cuenca/)
# 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:
```python
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`
```python
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
```python
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`
```python
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
```python
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
```python
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
```
Raw data
{
"_id": null,
"home_page": "https://github.com/cuenca-mx/cuenca-python",
"name": "cuenca",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Cuenca",
"author_email": "dev@cuenca.com",
"download_url": "https://files.pythonhosted.org/packages/5c/51/0e2c209de4c8e9e2b6963885fc8bde3112fc40f53790824c89c8401fdcb8/cuenca-0.6.1.tar.gz",
"platform": "",
"description": "# Cuenca \u2013 Python client library\n\n[](https://github.com/cuenca-mx/cuenca-python/actions?query=workflow%3Atest)\n[](https://codecov.io/gh/cuenca-mx/cuenca-python)\n[](https://pypi.org/project/cuenca/)\n\n# Installation\n\n`pip install cuenca`\n\n# Authentication\n\nThe preferred way to configure the credentials for the client is to set the\n`CUENCA_API_KEY` and `CUENCA_API_SECRET` environment variables. The client\nlibrary will automatically configure based on the values of those variables.\n\nTo configure manually:\n```python\nimport cuenca\n\ncuenca.configure(api_key='PKxxxx', api_secret='yyyyyy')\n```\n\n### Jwt\n\nJWT tokens can also be used if your credentials have enough permissions. To\ndo so, you may include the parameter `use_jwt` as part of your `configure`\n\n```python\nimport cuenca\n\ncuenca.configure(use_jwt=True)\n```\n\nA new token will be created at this moment and automatically renewed before\nsending any request if there is less than 5 minutes to be expired according\nto its payload data.\n\n\n## Transfers\n\n### Create transfer\n\n```python\nimport cuenca\n\ncuenca.configure(sandbox=True) # if using sandbox\n\nlocal_transfer_id = '078efdc20bab456285437309c4b75673'\n\ntransfer = cuenca.Transfer.create(\n recipient_name='Benito Ju\u00e1rez',\n account_number='646180157042875763', # CLABE or card number\n amount=12345, # Mx$123.45\n descriptor='sending money', # As it'll appear for the customer\n idempotency_key=local_transfer_id\n)\n\n# To get updated status\ntransfer.refresh()\n```\n\n\n### Retrieve by `id`\n\n```python\nimport cuenca\n\ntransfer = cuenca.Transfer.retrieve('tr_123')\n```\n\n### Query by `idempotency_key`, `account_number` and `status`\n\nResults are always returned in descending order of `created_at`\n\nThe methods that can be used:\n- `one()` - returns a single result. Raises `NoResultFound` if there are no\nresults and `MultipleResultsFound` if there are more than one\n- `first()` - returns the first result or `None` if there aren't any\n- `all()` - returns a generator of all matching results. Pagination is handled\nautomatically as you iterate over the response\n- `count()` - returns an integer with the count of the matching results\n\n```python\nimport cuenca\nfrom cuenca.types import Status\n\n# find the unique transfer using the idempotency key\nlocal_transfer_id = '078efdc20bab456285437309c4b75673'\ntransfer = cuenca.Transfer.one(idempotency_key=local_transfer_id)\n\n# returns a generator of all succeeded transfers to the specific account\ntransfers = cuenca.Transfer.all(\n account_number='646180157000000004',\n status=Status.succeeded\n)\n\n# the total number of succeeded transfers\ncount = cuenca.Transfer.count(status=Status.succeeded)\n```\n\n## Api Keys\n\n### Create new `ApiKey` and deactivate old\n```python\nimport cuenca\n\n# Create new ApiKey\nnew = cuenca.ApiKey.create()\n\n# Have to use the new key to deactivate the old key\nold_id = cuenca.session.auth[0]\ncuenca.session.configure(new.id, new.secret)\ncuenca.ApiKey.deactivate(old_id, 60) # revoke prior API key in an hour\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Cuenca API Client",
"version": "0.6.1",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "fb2a88e3f1dbedcfcb2c2a9a0cd8e843",
"sha256": "a9f9bd1c10e2571302cdf988730d108b50a83de8194ff6aae6abbda049dc391e"
},
"downloads": -1,
"filename": "cuenca-0.6.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "fb2a88e3f1dbedcfcb2c2a9a0cd8e843",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 25922,
"upload_time": "2021-01-21T21:37:21",
"upload_time_iso_8601": "2021-01-21T21:37:21.026240Z",
"url": "https://files.pythonhosted.org/packages/15/77/46366ad8f08ba709aabee7391f38162c1ab491761e44ef6e4e5658ace799/cuenca-0.6.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "36d94f5acce86af8b2e8dfd316384a3a",
"sha256": "c3b588937b5fcf71128cc0964b83566b8567fe427d2d29b6dd76feed2563481b"
},
"downloads": -1,
"filename": "cuenca-0.6.1.tar.gz",
"has_sig": false,
"md5_digest": "36d94f5acce86af8b2e8dfd316384a3a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 16887,
"upload_time": "2021-01-21T21:37:22",
"upload_time_iso_8601": "2021-01-21T21:37:22.058446Z",
"url": "https://files.pythonhosted.org/packages/5c/51/0e2c209de4c8e9e2b6963885fc8bde3112fc40f53790824c89c8401fdcb8/cuenca-0.6.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2021-01-21 21:37:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": null,
"github_project": "cuenca-mx",
"error": "Could not fetch GitHub repository",
"lcname": "cuenca"
}