vk.com is the largest social network in Russia. This library is significantly improved fork of vk
pip install vk-requests
import vk_requests
api = vk_requests.create_api(app_id=123, login='User', password='Password')
api.users.get(user_ids=1)
[{'first_name': 'Pavel', 'last_name': 'Durov', 'id': 1}]
Just pass scope
and/or api_version
parameters like
api = vk_requests.create_api(..., scope=['offline', 'status'], api_version='5.00')
api.status.set(text='Hello world!')
From your code:
import logging
logging.getLogger('vk-requests').setLevel(logging.DEBUG)
# Returns list of users
api.users.get(users_ids=1)
# Returns list of user's friends with extra fields
api.friends.get(user_id=1, fields=['nickname', 'city'])
# Returns result list from your custom api method
api.execute.YourMethod(**method_params)
Useful for dev purposes. You will be asked about login, password and app_id interactively in console. Useful if CAPTCHA required.
from vk_requests.auth import InteractiveVKSession
api = vk_requests.create_api(..., session_cls=InteractiveVKSession)
Useful for quick connect
Import StoredVKSession and pass active stored token, more help in vk_requests/__init__.py
from vk_requests.auth import StoredVKSession
api = vk_requests.create_api(app_id=123, login='User', password='Password',
stored_token='str_token', session_cls=StoredVKSession)
or if stored token is 100% valid and will not expire during the query:
from vk_requests.auth import StoredVKSession
api = vk_requests.create_api(stored_token='str_token', session_cls=StoredVKSession)
Just pass your phone number during API initialization. In case of security check it will be handled automatically, otherwise console input will be asked
api = vk_requests.create_api(
app_id=123, login='User', password='Password', phone_number='+79111234567')
Tests are mostly cheking integration part, so it requires some vk authentication data.
Before running tests locally define environment variables:
export VK_USER_LOGIN=<login> VK_USER_PASSWORD=<password> VK_APP_ID=<app_id> VK_PHONE_NUMBER=<phone_number>
To run tests:
tox
Warm welcome for suggestions and concerns