forked from codacy-badger/aioqiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
42 lines (36 loc) · 8.93 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
from setuptools import setup
packages = \
['aioqiwi',
'aioqiwi.contrib',
'aioqiwi.core',
'aioqiwi.core.connectors',
'aioqiwi.core.currencies',
'aioqiwi.core.tooling',
'aioqiwi.kassa',
'aioqiwi.kassa.types',
'aioqiwi.terminals',
'aioqiwi.terminals.types',
'aioqiwi.types',
'aioqiwi.wallet',
'aioqiwi.wallet.types']
package_data = \
{'': ['*']}
install_requires = \
['aiohttp>=3.6.2,<4.0.0', 'pydantic>=1.4,<2.0', 'nest-asyncio>=1.3.3']
setup_kwargs = {
'name': 'aioqiwi',
'version': '1.1.5',
'description': 'Convenient and asynchronous qiwi.com api-wrapper library',
'long_description': '===========\n🥝 aioqiwi\n===========\n\n.. image:: https://img.shields.io/badge/Python%203.7-blue.svg\n :target: https://www.python.org/\n :alt: Python-version\n\n**Qiwi payments for humans(for healthy humans)**\n\nSupports most of `qiwi <https://qiwi.com>`_ apis: `qiwi-maps <https://github.com/QIWI-API/qiwi-map>`_, `bills <https://developer.qiwi.com/en/bill-payments/>`_, `wallet <https://developer.qiwi.com/en/qiwi-wallet-personal/>`_\n\n------------\nInstallation\n------------\n\n::\n\n pip install aioqiwi\n\n---------------\n🔸 Dependencies\n---------------\n\n+------------+----------------------------+\n| Library | Description |\n+============+============================+\n| aiohttp | default http server |\n+------------+----------------------------+\n| pydantic | schema validation |\n+------------+----------------------------+\n\n\n**However aioqiwi is highly customizable. Example of switching json modules:**\n\n::\n\n pip install orjson\n\n.. code-block:: python\n\n from aioqiwi import Wallet\n from aioqiwi.core.tooling import json\n\n wallet = Wallet()\n wallet.tools.json_module = json.JSONModule("orjson")\n\n--------------------\n🔹 Dive-in Examples\n--------------------\n\n.. code:: python\n\n import asyncio\n\n from aioqiwi import Wallet\n\n async def qiwi():\n async with Wallet("TOKEN from https://qiwi.com/api") as w:\n w.phone_number = \'+7878787878\' # phone number is not required by default, but some methods need it\n balance = await w.balance()\n print("ACCOUNTS:")\n for acc in balance.accounts:\n print(acc.alias, acc.balance)\n\n asyncio.run(qiwi())\n\n\n--------------------\n📣 Handling updates\n--------------------\n\n**aioqiwi** provides user-friendly web-hooks handler\n\n\n.. code:: python\n\n import asyncio\n from aioqiwi.wallet import WebHook, Wallet\n\n wallet = Wallet("...")\n\n @wallet.hm(lambda event: ...)\n async def payments_handler(hook: WebHook):\n print(f"{hook.payment.account} sent you {event.payment}")\n\n @wallet.hm()\n async def secret_payments_handler(event: WebHook):\n await something(event.payment.commission.amount)\n\n wallet.idle(port=8090)\n\nWhen you do `Wallet::idle`, aioqiwi adds connector closing to `aiohttp.web.Application::on_shutdown` to make sure connector closes, however if you want to avoid this behaviour pass `close_connector_ate=False` to `Wallet::idle`\n\n****************\nHandler manager\n****************\n\nHandler manager `QiwiClient.handler_manager` or `qiwi_client.hm` is responsible for event-handlers registering and filtering/delivering updates to them.\nThere\'re currently two event processing strategies:\n1. `core.handler.EventProcessStrategy.ORDERED` - sequential filter-check. has O(n) amplitude\n2. `core.handler.EventProcessStrategy.MILKSHAKE` - as receives update, will shuffle existing handlers list. has O(n) amplitude\n\n.. note::\n Filters results are not currently cached.\n\n.. note::\n Some users don\'t want mess with web-hooks, for those fellas aioqiwi has `history_polling` [wip] in `aioqiwi.contrib`. Different approach for dealing with payment events.\n Find usage example in `examples/` directory.\n\n---------------------------------------------------\n🔥 Qiwi API p2p transactions(bills)\n---------------------------------------------------\n\n.. code:: python\n\n import asyncio\n from aioqiwi import QiwiKassa\n\n async def test_kassa():\n async with QiwiKassa("SECRET KEY from p2p.qiwi.com or kassa.qiwi.com") as kassa:\n sent_invoice = await kassa.new_bill(14.88, lifetime=44)\n # setting lifetime to 44 ahead today [default is 10] 45 - is max\n print("Url to pay:", sent_invoice.pay_url)\n await kassa.close()\n\n asyncio.run(test_kassa())\n\n\n``sent_invoice.pay_url`` will redirect us to something like:\n\n.. image:: https://imbt.ga/gO8EzaFItB\n\n\n---------------------------\n💳 Handling bill payments\n---------------------------\n\n\n.. code:: python\n\n\n from aioqiwi.kassa import QiwiKassa, Notification\n\n kassa = QiwiKassa(\'PRIVATE_KEY\')\n\n @kassa.hm(lambda bill: bill.bill.amount.currency == \'RUB\')\n async def my_shiny_rubles_handler(bill_update: Notification):\n # do something\n pass\n\n kassa.idle()\n\n\n--------------------\n🗺 QIWI terminals\n--------------------\n\n**aioqiwi** covers qiwi\'s `MAPS\n<https://developer.qiwi.com/ru/qiwi-map>`_ api in aioqiwi.terminals module\n\n---------------\nConnectors\n---------------\n\nQiwiClient.connector is responsible for making http requests. Current available request managers are located in `aioqiwi.core.connectors`\n\nDefault connector is `aioqiwi.core.connectors.asyncio`, but if it\'s no suit for you, you can easily switch to another\n\nExample:\n\n.. code:: python3\n\n from aioqiwi import Wallet\n from aioqiwi.core.connectors.aiohttp import AiohttpConnector\n\n wallet = Wallet("auth")\n # switch with read-to-use connector-like instance implementing\n wallet.connector = AiohttpConnector(timeout, {"user-agent": "opeka/02"})\n # or switch with aioqiwi.core.connectors.abstract.Connector compatible class\n wallet.connector = AiohttpConnector\n\n*******************\nHacking connector\n*******************\n\nYou can easily implement your own http client(connector), subclassing from `aioqiwi.core.connectors.abstract.AbstractConnector`. Take a look at "out of the box" `aiohttp` or `asyncio` sessions for the start.\n\n-----------------------\n👾 Handling errors\n-----------------------\n\n******************\nAPI request error\n******************\n\nConsider we have a `aioqiwi.wallet.Wallet` instance with a named reference `wallet` to it.\nKnown error when we cannot ask server for more than 50 rows in `wallet.history`. To handle that error, we simply:\n\n.. code:: python\n\n from aioqiwi.exceptions import AioqiwiError\n from aioqiwi.errors import ErrorInfo\n\n try:\n await wallet.history(2 ** 6) # pass rows=64, whilst constraint is 0<rows<51\n except AioqiwiError as exc:\n if exc.err: # this feature is experimental\n exc.err: ErrorInfo = exc.err # cast to aioqiwi.Wallet\'s error info\n print(exc.err.error_message)\n\n***************\nTimeoutError\n***************\n\nThis is slight different error and aioqiwi should not be really responsible for it. It\'s usually server-side error\nwhich makes exception that should be raised connector-specific. `asyncio.TimeoutError` is exception that is produced\nby `asyncio` connector. In `aiohttp` or other connectors it may differ.\n\n-----------------------------\n⛏ return policies (types)\n-----------------------------\n\naioqiwi\'s server.BaseWebHookView and requests.Requests support "return policy", it means you can get response/update in the form that suits your needs.\nThere\'re currently 5 return policies.\n\n- NOTHING - returns nothing(note: None is python\'s implicit return), :note: returning nothing does not mean doing nothing, validation is done anyway\n- READ_DATA - raw return once stream is read\n- JSON - raw return once read data was deserialized\n- MODEL - complex return once json deserialized and new model instantiated\n- LIST_OF_MODELS - complex return once json deserialized as an iterable list with new instantiated models of json objects\n\n-------------------\n❓ HOW-TOs\n-------------------\n\nYou can find examples in ``examples/`` directory in github repository. For start examples above should be enough.\n\n\n---------------------------\n🔧 TODOs\n---------------------------\n\n- **Tests/CI/CD**\n- **Implement all qiwi wallet API methods**\n\n-----------------\nWork in progress\n-----------------\n\n- history_polling needs to be tested\n- implement wallet web-hook payment verification\n\n------------------------------------------\n🐦 Community\n------------------------------------------\n\n**My group**\n`✈️ Telegram\n<https://t.me/joinchat/B2cC_hSIAiYXxqKghdguCA>`_\n',
'author': 'Martin Winks',
'author_email': 'cat@snejugal.ru',
'maintainer': None,
'maintainer_email': None,
'url': 'https://github.com/uwinx/aioqiwi',
'packages': packages,
'package_data': package_data,
'install_requires': install_requires,
'python_requires': '>=3.7,<4.0',
}
setup(**setup_kwargs)