skip to navigation
skip to content

aiovk 1.2.2 API python wrapper for asyncio

Latest Version: 1.3.1 API python wrapper for asyncio

for old version of python you can use


  • asynchronous
  • support python 3.5+ versions
  • have only one dependency - aiohttp
  • support two-factor authentication
  • support socks proxy with aiosocks
  • support rate limit of requests
  • support Long Poll connection


pip install aiovk



In all the examples below, I will give only the {code}

async def func():

loop = asyncio.get_event_loop()


TokenSession - if you already have token or you use requests which don’t require token

session = TokenSession()
session = TokenSession(access_token='asdf123..')

ImplicitSession - client authorization in js apps and standalone (desktop and mobile) apps

>>> session = ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID)
>>> await session.authorize()
>>> session.access_token

With scopes:

ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 'notify')
ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 'notify,friends')
ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, ['notify', 'friends'])
ImplicitSession(USER_LOGIN, USER_PASSWORD, APP_ID, 3)  # notify and friends

Also you can use SimpleImplicitSessionMixin for entering confirmation code or captcha key

AuthorizationCodeSession - authorization for server apps or Open API

See for getting the CODE

>>> session = AuthorizationCodeSession(APP_ID, APP_SECRET, REDIRECT_URI, CODE)
>>> await session.authorize()
>>> session.access_token


>>> session = AuthorizationCodeSession(APP_ID, APP_SECRET, REDIRECT_URI)
>>> await session.authorize(CODE)
>>> session.access_token

Authorization using context manager - you won’t need to use session.close() after work

async with aiovk.TokenSession(access_token=YOUR_VK_TOKEN) as ses:
    api = API(ses)...

And your session will be closed after all done or code fail(similar to simple “with” usage) Works with all types of authorization


HttpDriver - default driver for using aiohttp

>>> driver = HttpDriver()
>>> driver = HttpDriver(timeout=10)  # default timeout for all requests
>>> driver = Socks5Driver(PROXY_ADDRESS, PORT)  # 1234 is port
>>> driver = Socks5Driver(PROXY_ADDRESS, PORT, timeout=10)
>>> driver = Socks5Driver(PROXY_ADDRESS, PORT, PROXY_LOGIN, PROXY_PASSWORD, timeout=10)

How to use custom driver with session:

>>> session = TokenSession(..., driver=HttpDriver())

How to use driver with own loop:

>>> loop = asyncio.get_event_loop()
>>> asyncio.set_event_loop(None)
>>> session = TokenSession(driver=HttpDriver(loop=loop))  # or Socks5Driver

LimitRateDriverMixin - mixin class what allow you create new drivers with speed rate limits

>>> class ExampleDriver(LimitRateDriverMixin, HttpDriver):
...     requests_per_period = 3
...     period = 1  #seconds


First variant:

>>> session = TokenSession()
>>> api = API(session)
>>> await api.users.get(user_ids=1)
[{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]

Second variant:

>>> session = TokenSession()
>>> api = API(session)
>>> await api('users.get', user_ids=1)
[{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]

Also you can add timeout argument for each request or define it in the session

See for detailed API guide.

Long Poll

Use exist API object

>>> api = API(session)
>>> lp = LongPoll(api, mode=2)  # default wait=25
>>> await lp.wait()
>>> await lp.wait()

Use Session object

>>> lp = LongPoll(session, mode=2)  # default wait=25
>>> await lp.wait()
>>> await lp.get_pts()  # return pts
>>> await lp.get_pts(need_ts=True)  # return pts, ts
191231223, 1820350345

Notice that wait value only for long pool connection.

Real pause could be more wait time because of need time for authorisation (if needed), reconnect and etc.

File Type Py Version Uploaded on Size
aiovk-1.2.2.tar.gz (md5) Source 2017-06-19 8KB