{"id":15107974,"url":"https://github.com/alexanderlarin/aiovk","last_synced_at":"2025-04-09T12:06:55.869Z","repository":{"id":44933169,"uuid":"62889917","full_name":"alexanderlarin/aiovk","owner":"alexanderlarin","description":"vk.com API python wrapper for asyncio","archived":false,"fork":false,"pushed_at":"2023-04-10T12:11:48.000Z","size":154,"stargazers_count":96,"open_issues_count":1,"forks_count":28,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-02T11:06:46.132Z","etag":null,"topics":["asyncio","hacktoberfest","python-3","vk","wrapper"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexanderlarin.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-08T13:17:15.000Z","updated_at":"2025-03-15T14:39:30.000Z","dependencies_parsed_at":"2024-06-20T23:39:33.213Z","dependency_job_id":null,"html_url":"https://github.com/alexanderlarin/aiovk","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderlarin%2Faiovk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderlarin%2Faiovk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderlarin%2Faiovk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexanderlarin%2Faiovk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexanderlarin","download_url":"https://codeload.github.com/alexanderlarin/aiovk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","hacktoberfest","python-3","vk","wrapper"],"created_at":"2024-09-25T21:43:32.215Z","updated_at":"2025-04-09T12:06:55.846Z","avatar_url":"https://github.com/alexanderlarin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"vk.com API python wrapper for asyncio\n=====================================\nfor old version of python you can use https://github.com/dimka665/vk\n\nFeatures\n--------\n* asynchronous\n* support python 3.5+ versions\n* have only one dependency - ``aiohttp 3+``\n* support two-factor authentication\n* support socks proxy with ``aiohttp-socks``\n* support rate limit of requests\n* support Long Poll connection\n\nTODO\n----\n* need refactoring tests for ``AsyncVkExecuteRequestPool``\n\nInstall\n-------\n\n.. code-block:: bash\n\n    pip install aiovk\n\nExamples\n========\nAnnotation\n----------\nIn all the examples below, I will give only the ``{code}``\n\n.. code-block:: python\n\n    async def func():\n        {code}\n\n    loop = asyncio.get_event_loop()\n    loop.run_until_complete(func())\n\n\nAuthorization\n-------------\n**TokenSession** - if you already have token or you use requests which don't require token\n\n.. code-block:: python\n\n    session = TokenSession()\n    session = TokenSession(access_token='asdf123..')\n\n**ImplicitSession** - client authorization in js apps and standalone (desktop and mobile) apps\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID)\n    \u003e\u003e\u003e await session.authorize()\n    \u003e\u003e\u003e session.access_token\n    asdfa2321afsdf12eadasf123...\n\nWith scopes:\n\n.. code-block:: python\n\n    ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 'notify')\n    ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 'notify,friends')\n    ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, ['notify', 'friends'])\n    ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 3)  # notify and friends\n\nAlso you can use ``SimpleImplicitSessionMixin`` for entering confirmation code\nor captcha key\n\n**AuthorizationCodeSession** - authorization for server apps or Open API\n\nSee https://vk.com/dev/authcode_flow_user for getting the CODE\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = AuthorizationCodeSession(APP_ID, APP_SECRET, REDIRECT_URI, CODE)\n    \u003e\u003e\u003e await session.authorize()\n    \u003e\u003e\u003e session.access_token\n    asdfa2321afsdf12eadasf123...\n\nOr:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = AuthorizationCodeSession(APP_ID, APP_SECRET, REDIRECT_URI)\n    \u003e\u003e\u003e await session.authorize(CODE)\n    \u003e\u003e\u003e session.access_token\n    asdfa2321afsdf12eadasf123...\n\n**Authorization using context manager** - you won't need to use session.close() after work\n\n.. code-block:: python\n\n    async with aiovk.TokenSession(access_token=YOUR_VK_TOKEN) as ses:\n        api = API(ses)...\n\nAnd your session will be closed after all done or code fail(similar to simple \"with\" usage)\nWorks with all types of authorization\n\nDrivers\n-------\n**HttpDriver** - default driver for using ``aiohttp``\n\n.. code-block:: python\n\n    \u003e\u003e\u003e driver = HttpDriver()\n    \u003e\u003e\u003e driver = HttpDriver(timeout=10)  # default timeout for all requests\n\n.. code-block:: python\n\n    \u003e\u003e\u003e driver = ProxyDriver(PROXY_ADDRESS, PORT)  # 1234 is port\n    \u003e\u003e\u003e driver = ProxyDriver(PROXY_ADDRESS, PORT, timeout=10)\n    \u003e\u003e\u003e driver = ProxyDriver(PROXY_ADDRESS, PORT, PROXY_LOGIN, PROXY_PASSWORD, timeout=10)\n\nHow to use custom driver with session:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = TokenSession(..., driver=HttpDriver())\n\nHow to use driver with own loop:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e loop = asyncio.get_event_loop()\n    \u003e\u003e\u003e asyncio.set_event_loop(None)\n    \u003e\u003e\u003e session = TokenSession(driver=HttpDriver(loop=loop))  # or ProxyDriver\n\nHow to use driver with custom http session object:\n\nSolve next problem: https://stackoverflow.com/questions/29827642/asynchronous-aiohttp-requests-fails-but-synchronous-requests-succeed\n\n.. code-block:: python\n\n    \u003e\u003e\u003e connector = aiohttp.TCPConnector(verify_ssl=False)\n    \u003e\u003e\u003e session = aiohttp.ClientSession(connector=connector)\n    \u003e\u003e\u003e driver = HttpDriver(loop=loop, session=session)\n\n\n**LimitRateDriverMixin** - mixin class what allow you create new drivers with speed rate limits\n\n.. code-block:: python\n\n    \u003e\u003e\u003e class ExampleDriver(LimitRateDriverMixin, HttpDriver):\n    ...     requests_per_period = 3\n    ...     period = 1  #seconds\n\nVK API\n------\nFirst variant:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = TokenSession()\n    \u003e\u003e\u003e api = API(session)\n    \u003e\u003e\u003e await api.users.get(user_ids=1)\n    [{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]\n\nSecond variant:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = TokenSession()\n    \u003e\u003e\u003e api = API(session)\n    \u003e\u003e\u003e await api('users.get', user_ids=1)\n    [{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]\n\nAlso you can add ``timeout`` argument for each request or define it in the session\n\nSee https://vk.com/dev/methods for detailed API guide.\n\nLazy VK API\n-----------\nIt is useful when a bot has a large message flow\n\n.. code-block:: python\n\n    \u003e\u003e\u003e session = TokenSession()\n    \u003e\u003e\u003e api = LazyAPI(session)\n    \u003e\u003e\u003e message = api.users.get(user_ids=1)\n    \u003e\u003e\u003e await message()\n    [{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]\n\nSupports both variants like API object\n\nUser Long Poll\n--------------\nFor documentation, see: https://vk.com/dev/using_longpoll\n\nUse exist API object\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api = API(session)\n    \u003e\u003e\u003e lp = UserLongPoll(api, mode=2)  # default wait=25\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":1820350345,\"updates\":[...]}\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":1820351011,\"updates\":[...]}\n\nUse Session object\n\n.. code-block:: python\n\n    \u003e\u003e\u003e lp = UserLongPoll(session, mode=2)  # default wait=25\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":1820350345,\"updates\":[...]}\n    \u003e\u003e\u003e await lp.get_pts()  # return pts\n    191231223\n    \u003e\u003e\u003e await lp.get_pts(need_ts=True)  # return pts, ts\n    191231223, 1820350345\n\nYou can iterate over events\n\n.. code-block:: python\n\n    \u003e\u003e\u003e async for event in lp.iter():\n    ...     print(event)\n    {\"type\":..., \"object\": {...}}\n\nNotice that ``wait`` value only for long pool connection.\n\nReal pause could be more ``wait`` time because of need time\nfor authorization (if needed), reconnect and etc.\n\nBots Long Poll\n--------------\nFor documentation, see: https://vk.com/dev/bots_longpoll\n\nUse exist API object\n\n.. code-block:: python\n\n    \u003e\u003e\u003e api = API(session)\n    \u003e\u003e\u003e lp = BotsLongPoll(api, group_id=1)  # default wait=25\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":345,\"updates\":[...]}\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":346,\"updates\":[...]}\n\nUse Session object\n\n.. code-block:: python\n\n    \u003e\u003e\u003e lp = BotsLongPoll(session, group_id=1)  # default wait=25\n    \u003e\u003e\u003e await lp.wait()\n    {\"ts\":78455,\"updates\":[...]}\n    \u003e\u003e\u003e await lp.get_pts()  # return pts\n    191231223\n    \u003e\u003e\u003e await lp.get_pts(need_ts=True)  # return pts, ts\n    191231223, 1820350345\n\nBotsLongPoll supports iterating too\n\n.. code-block:: python\n\n    \u003e\u003e\u003e async for event in lp.iter():\n    ...     print(event)\n    {\"type\":..., \"object\": {...}}\n\nNotice that ``wait`` value only for long pool connection.\n\nReal pause could be more ``wait`` time because of need time\nfor authorization (if needed), reconnect and etc.\n\nAsync execute request pool\n--------------------------\nFor documentation, see: https://vk.com/dev/execute\n\n.. code-block:: python\n\n    from aiovk.pools import AsyncVkExecuteRequestPool\n\n    async with AsyncVkExecuteRequestPool() as pool:\n        response = pool.add_call('users.get', 'YOUR_TOKEN', {'user_ids': 1})\n        response2 = pool.add_call('users.get', 'YOUR_TOKEN', {'user_ids': 2})\n        response3 = pool.add_call('users.get', 'ANOTHER_TOKEN', {'user_ids': 1})\n        response4 = pool.add_call('users.get', 'ANOTHER_TOKEN', {'user_ids': -1})\n\n    \u003e\u003e\u003e print(response.ok)\n    True\n    \u003e\u003e\u003e print(response.result)\n    [{'id': 1, 'first_name': 'Павел', 'last_name': 'Дуров'}]\n    \u003e\u003e\u003e print(response2.result)\n    [{'id': 2, 'first_name': 'Александра', 'last_name': 'Владимирова'}]\n    \u003e\u003e\u003e print(response3.result)\n    [{'id': 1, 'first_name': 'Павел', 'last_name': 'Дуров'}]\n    \u003e\u003e\u003e print(response4.ok)\n    False\n    \u003e\u003e\u003e print(response4.error)\n    {'method': 'users.get', 'error_code': 113, 'error_msg': 'Invalid user id'}\n\nor\n\n.. code-block:: python\n\n    from aiovk.pools import AsyncVkExecuteRequestPool\n\n    pool = AsyncVkExecuteRequestPool()\n    response = pool.add_call('users.get', 'YOUR_TOKEN', {'user_ids': 1})\n    response2 = pool.add_call('users.get', 'YOUR_TOKEN', {'user_ids': 2})\n    response3 = pool.add_call('users.get', 'ANOTHER_TOKEN', {'user_ids': 1})\n    response4 = pool.add_call('users.get', 'ANOTHER_TOKEN', {'user_ids': -1})\n    await pool.execute()\n    ...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderlarin%2Faiovk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexanderlarin%2Faiovk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexanderlarin%2Faiovk/lists"}