cuenca


Namecuenca JSON
Version 2.1.10 PyPI version JSON
download
home_pagehttps://github.com/cuenca-mx/cuenca-python
SummaryCuenca API Client
upload_time2025-09-04 23:38:13
maintainerNone
docs_urlNone
authorCuenca
requires_python>=3.9
licenseNone
keywords
VCS
bugtrack_url
requirements requests cuenca-validations pydantic-extra-types
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cuenca – Python client library

[![test](https://github.com/cuenca-mx/cuenca-python/workflows/test/badge.svg)](https://github.com/cuenca-mx/cuenca-python/actions?query=workflow%3Atest)
[![codecov](https://codecov.io/gh/cuenca-mx/cuenca-python/branch/main/graph/badge.svg)](https://codecov.io/gh/cuenca-mx/cuenca-python)
[![PyPI](https://img.shields.io/pypi/v/cuenca.svg)](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)
```
## Balance

### Current balance
```python
import cuenca

# balance is the amount in cents
balance = cuenca.get_balance()

```


## 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
```

## Login


Create a new password
```python
cuenca.UserCredential.create(password='1234567890')
```

To update your password
```python
cuenca.UserCredential.update(password='1234567890')
```

To reset password
```python
cuenca.UserCredential.update(password=None)
```

Login in and out
```python
cuenca.UserLogin.create(password='1234567890')
...  # authenticated operation
cuenca.UserLogin.logout()
```

Create login token for biometrics
```python
# 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
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/cuenca-mx/cuenca-python",
    "name": "cuenca",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Cuenca",
    "author_email": "dev@cuenca.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/82/109495dd5551e3cdcbdc36dcc744f8207db7bb912ed9e1cfba0b3741a999/cuenca-2.1.10.tar.gz",
    "platform": null,
    "description": "# Cuenca \u2013 Python client library\n\n[![test](https://github.com/cuenca-mx/cuenca-python/workflows/test/badge.svg)](https://github.com/cuenca-mx/cuenca-python/actions?query=workflow%3Atest)\n[![codecov](https://codecov.io/gh/cuenca-mx/cuenca-python/branch/main/graph/badge.svg)](https://codecov.io/gh/cuenca-mx/cuenca-python)\n[![PyPI](https://img.shields.io/pypi/v/cuenca.svg)](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## Balance\n\n### Current balance\n```python\nimport cuenca\n\n# balance is the amount in cents\nbalance = cuenca.get_balance()\n\n```\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## Login\n\n\nCreate a new password\n```python\ncuenca.UserCredential.create(password='1234567890')\n```\n\nTo update your password\n```python\ncuenca.UserCredential.update(password='1234567890')\n```\n\nTo reset password\n```python\ncuenca.UserCredential.update(password=None)\n```\n\nLogin in and out\n```python\ncuenca.UserLogin.create(password='1234567890')\n...  # authenticated operation\ncuenca.UserLogin.logout()\n```\n\nCreate login token for biometrics\n```python\n# Must be logged in\ncuenca.UserLogin.create(password='1234567890')\ntoken = cuenca.LoginToken.create()\ncuenca.UserLogin.logout()\n\n# Then you can use the token which lasts for 7 days\ncuenca.configure(login_token=token)\n...  # authenticated operation\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Cuenca API Client",
    "version": "2.1.10",
    "project_urls": {
        "Homepage": "https://github.com/cuenca-mx/cuenca-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3ff0924eb0f8446b8e37d42923b82248393bcf91b286c68ba5ee20319793e683",
                "md5": "55a03de0ad57c5b8434cb5128d97515f",
                "sha256": "9d8f383294028ffb7b15d744857f2051ea0b95579b34ac1af09e27141eaf996d"
            },
            "downloads": -1,
            "filename": "cuenca-2.1.10-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "55a03de0ad57c5b8434cb5128d97515f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 69635,
            "upload_time": "2025-09-04T23:38:11",
            "upload_time_iso_8601": "2025-09-04T23:38:11.725008Z",
            "url": "https://files.pythonhosted.org/packages/3f/f0/924eb0f8446b8e37d42923b82248393bcf91b286c68ba5ee20319793e683/cuenca-2.1.10-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6f82109495dd5551e3cdcbdc36dcc744f8207db7bb912ed9e1cfba0b3741a999",
                "md5": "f8c763482a125e2016c907849ff08f8d",
                "sha256": "a6890f265432ac55f9757d0a2b8b2c0dd3dd1ef554b80ad1fa4777489aa6d8a1"
            },
            "downloads": -1,
            "filename": "cuenca-2.1.10.tar.gz",
            "has_sig": false,
            "md5_digest": "f8c763482a125e2016c907849ff08f8d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 38433,
            "upload_time": "2025-09-04T23:38:13",
            "upload_time_iso_8601": "2025-09-04T23:38:13.443055Z",
            "url": "https://files.pythonhosted.org/packages/6f/82/109495dd5551e3cdcbdc36dcc744f8207db7bb912ed9e1cfba0b3741a999/cuenca-2.1.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-04 23:38:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "cuenca-mx",
    "github_project": "cuenca-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.32.3"
                ]
            ]
        },
        {
            "name": "cuenca-validations",
            "specs": [
                [
                    "==",
                    "2.1.16"
                ]
            ]
        },
        {
            "name": "pydantic-extra-types",
            "specs": [
                [
                    "==",
                    "2.10.2"
                ]
            ]
        }
    ],
    "lcname": "cuenca"
}
        
Elapsed time: 3.74241s