cbr-client


Namecbr-client JSON
Version 0.3.4 PyPI version JSON
download
home_pagehttps://github.com/mrslow/cbr-client
SummaryTool for easy working with https://portal5.cbr.ru API
upload_time2023-01-31 18:31:30
maintainer
docs_urlNone
authorAnton Shchetikhin
requires_python>=3.7
licenseMIT
keywords cbr rest api client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cbr-client
![PyPI - License](https://img.shields.io/pypi/l/cbr-client)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cbr-client)

Клиент для работы с api ЦБ РФ

Описание АПИ - https://cbr.ru/lk_uio/guide/rest_api/

## Установка
```bash
pip install cbr-client
```

## Зависимости
* [httpx](https://github.com/encode/httpx)
* [pydantic](https://github.com/samuelcolvin/pydantic)


## Использование
```python
# необходимо запускать python -m asyncio
from cbr_client import Client

conn_params = dict(
    url='https://portal5test.cbr.ru',
    login='test',
    password='test',
    user_agent='test app'
)

client = Client(**conn_params)
# или через контекстный менеджер
# async with Client(**conn_params) as client:
#     ...

files = [
        ('report.zip.enc', b'encrypted report content'),
        ('report.zip.1.sig', b'operator signature'),
        ('report.zip.2.sig', b'client signature')
    ]

# отправка отчета на портал ЦБ
# создание сообщения
msg = await client.create_message(files, '1-ПИ')
# загрузка файлов
for f in msg.files:
    await client.upload(f)
# или опциональная загрузка чанками
for f in msg.files:
    await client.upload(f, chunked=True, chunk_size=2**16)
# финализация (закрытие сессии)
await client.finalize_message(msg)

# получение квитанций
receipts =await client.get_receipts(msg_id=msg.oid)
for rcpt in receipts:
    # получение файла из хранилища
    for f in rcpt.files:
        # сохраняется в f.content
        await client.download(f)

# получение сообщений по типу формы
messages = await client.get_messages(form='1-ПИ')
# или по статусу
messages = await client.get_messages(status='draft')
# или по типу сообщения (inbox/outbox)
messages = await client.get_messages(msg_type='outbox')
# паджинация, по умолчанию возвращается первая страница
messages = await client.get_messages(status='draft', page=4)
# или комбинировать параметры как требуется 

# получение файлов сообщения
messages = await client.get_messages()
for msg in messages:
    # получение файла из хранилища
    for f in msg.files:
        # сохраняется в f.content
        await client.download(f)

# получение списка возможных задач
tasks = await client.get_tasks()

# получение списка справочников с данными
dictionaries = await client.get_dictionaries()

# получение данных из определенного справочника
d = await client.get_dictionary(oid='dictionary_id')

# получение данных профиля
profile = await client.get_profile()

# получение доступной квоты использования хранилища
quota = await client.get_profile_quota()

# удаление сообщения 
await client.delete_message(msg_id='message_id')

# в конце работы не забываем закрывать соединение
await client.close()
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/mrslow/cbr-client",
    "name": "cbr-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "cbr rest api client",
    "author": "Anton Shchetikhin",
    "author_email": "animal2k@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9f/7c/1309ad69181c6be2a215614d780f3f103d633f91d5180ae3086736053424/cbr-client-0.3.4.tar.gz",
    "platform": null,
    "description": "# cbr-client\n![PyPI - License](https://img.shields.io/pypi/l/cbr-client)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cbr-client)\n\n\u041a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 api \u0426\u0411 \u0420\u0424\n\n\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0410\u041f\u0418 - https://cbr.ru/lk_uio/guide/rest_api/\n\n## \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430\n```bash\npip install cbr-client\n```\n\n## \u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438\n* [httpx](https://github.com/encode/httpx)\n* [pydantic](https://github.com/samuelcolvin/pydantic)\n\n\n## \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\n```python\n# \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c python -m asyncio\nfrom cbr_client import Client\n\nconn_params = dict(\n    url='https://portal5test.cbr.ru',\n    login='test',\n    password='test',\n    user_agent='test app'\n)\n\nclient = Client(**conn_params)\n# \u0438\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0439 \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\n# async with Client(**conn_params) as client:\n#     ...\n\nfiles = [\n        ('report.zip.enc', b'encrypted report content'),\n        ('report.zip.1.sig', b'operator signature'),\n        ('report.zip.2.sig', b'client signature')\n    ]\n\n# \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0430 \u043e\u0442\u0447\u0435\u0442\u0430 \u043d\u0430 \u043f\u043e\u0440\u0442\u0430\u043b \u0426\u0411\n# \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\nmsg = await client.create_message(files, '1-\u041f\u0418')\n# \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\nfor f in msg.files:\n    await client.upload(f)\n# \u0438\u043b\u0438 \u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0447\u0430\u043d\u043a\u0430\u043c\u0438\nfor f in msg.files:\n    await client.upload(f, chunked=True, chunk_size=2**16)\n# \u0444\u0438\u043d\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f (\u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0435\u0441\u0441\u0438\u0438)\nawait client.finalize_message(msg)\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043a\u0432\u0438\u0442\u0430\u043d\u0446\u0438\u0439\nreceipts =await client.get_receipts(msg_id=msg.oid)\nfor rcpt in receipts:\n    # \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\n    for f in rcpt.files:\n        # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 f.content\n        await client.download(f)\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u043f\u043e \u0442\u0438\u043f\u0443 \u0444\u043e\u0440\u043c\u044b\nmessages = await client.get_messages(form='1-\u041f\u0418')\n# \u0438\u043b\u0438 \u043f\u043e \u0441\u0442\u0430\u0442\u0443\u0441\u0443\nmessages = await client.get_messages(status='draft')\n# \u0438\u043b\u0438 \u043f\u043e \u0442\u0438\u043f\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f (inbox/outbox)\nmessages = await client.get_messages(msg_type='outbox')\n# \u043f\u0430\u0434\u0436\u0438\u043d\u0430\u0446\u0438\u044f, \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430\nmessages = await client.get_messages(status='draft', page=4)\n# \u0438\u043b\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u0430\u043a \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f\nmessages = await client.get_messages()\nfor msg in messages:\n    # \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438\u0437 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\n    for f in msg.files:\n        # \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 f.content\n        await client.download(f)\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\ntasks = await client.get_tasks()\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0430 \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438\ndictionaries = await client.get_dictionaries()\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u0438\u043a\u0430\nd = await client.get_dictionary(oid='dictionary_id')\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u043e\u0444\u0438\u043b\u044f\nprofile = await client.get_profile()\n\n# \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u043e\u0439 \u043a\u0432\u043e\u0442\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430\nquota = await client.get_profile_quota()\n\n# \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \nawait client.delete_message(msg_id='message_id')\n\n# \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435\nawait client.close()\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Tool for easy working with https://portal5.cbr.ru API",
    "version": "0.3.4",
    "split_keywords": [
        "cbr",
        "rest",
        "api",
        "client"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76369cd341e331dedf0d1ce1729b1c9fdbf7cb2e1fe64496521a95b6bb912642",
                "md5": "6a6c622cbfe1a8686bd7e61312cc964f",
                "sha256": "da4ae0a7f85bca3a84535c074a9d3fe2d9f8777815e7b89101bbeccc9ad76af5"
            },
            "downloads": -1,
            "filename": "cbr_client-0.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a6c622cbfe1a8686bd7e61312cc964f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7266,
            "upload_time": "2023-01-31T18:31:29",
            "upload_time_iso_8601": "2023-01-31T18:31:29.187123Z",
            "url": "https://files.pythonhosted.org/packages/76/36/9cd341e331dedf0d1ce1729b1c9fdbf7cb2e1fe64496521a95b6bb912642/cbr_client-0.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f7c1309ad69181c6be2a215614d780f3f103d633f91d5180ae3086736053424",
                "md5": "afa16b6a3f405d97f3ea730df985d2c4",
                "sha256": "61d3c3cce844fd401be9141cac609ba5043679a8847aa33afca7c53b307f5669"
            },
            "downloads": -1,
            "filename": "cbr-client-0.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "afa16b6a3f405d97f3ea730df985d2c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7475,
            "upload_time": "2023-01-31T18:31:30",
            "upload_time_iso_8601": "2023-01-31T18:31:30.700848Z",
            "url": "https://files.pythonhosted.org/packages/9f/7c/1309ad69181c6be2a215614d780f3f103d633f91d5180ae3086736053424/cbr-client-0.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-31 18:31:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "mrslow",
    "github_project": "cbr-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "cbr-client"
}
        
Elapsed time: 0.09901s