Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now API python wrapper for asyncio

Project description 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

How to use driver with custom http session object:

Solve next problem:

>>> connector = aiohttp.TCPConnector(verify_ssl=False)
>>> session = aiohttp.ClientSession(connector=connector)
>>> driver = HttpDriver(loop=loop, session=session)

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.


It is useful when a bot has a large message flow

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

Supports both variants like API object

Long Poll

UserLongPoll - for User Long Poll API. See

BotsLongPoll - for Bots Long Poll API. See

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 authorization (if needed), reconnect and etc.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
aiovk-2.2.1.tar.gz (11.4 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page