Skip to content

vkpymusic.vk_api

This module contains different classes, using for requests to VK API.

Classes:

Name Description
VkApiRequest

A class that represents a request.

VkApiRequestBuilder

A class that builds requests.

VkApiResponse

A class that represents a response.

VkApiException

A class that represents an error.

Constants

BASE_URL: A constant that stores the base URL for VK API. DEFAULT_PARAMS: A constant that stores the default parameters for VK API.

VkApiRequest

A class that represents a request to VK API.

Attributes:

Name Type Description
method str

The HTTP method.

url str

The URL.

headers dict

The headers.

params dict

The parameters.

__init__(method, url, headers=None, params=None)

Initializes a VkApiRequest object.

Parameters:

Name Type Description Default
method str

The HTTP method.

required
url str

The URL.

required
headers dict

The headers. (default None)

None
params dict

The parameters. (default None)

None

VkApiRequestBuilder

A class for building requests to VK API.

build_from_base_request(method, url, params) staticmethod

Builds a request from a base request.

Parameters:

Name Type Description Default
method str

The HTTP method.

required
url str

The URL.

required
params dict

The parameters.

required

build_req_get_profile_info() classmethod

Builds a request to get profile information.

build_req_get_count(userid) classmethod

Builds a request to get the number of user's audio.

Parameters:

Name Type Description Default
userid int

The user ID.

required

build_req_get(userid, count=100, offset=0, playlist_id=None, access_key=None) classmethod

Builds a request to get user's audio.

Parameters:

Name Type Description Default
userid int

The user ID.

required
count int

The number of audio recordings. (default 100)

100
offset int

The offset. (default 0)

0
playlist_id int

The playlist ID. (default None)

None
access_key str

The access key. (default None)

None

Builds a request to search for audio by query.

Parameters:

Name Type Description Default
query str

The query.

required
count int

The number of audio recordings. (default 100)

100
offset int

The offset. (default 0)

0

build_req_get_playlists(userid, count=50, offset=0) classmethod

Builds a request to get user's playlists.

Parameters:

Name Type Description Default
userid int

The user ID.

required
count int

The number of playlists. (default 50)

50
offset int

The offset. (default 0)

0

build_req_search_playlists(text, count=50, offset=0) classmethod

Builds a request to search for playlists by text.

Parameters:

Name Type Description Default
text str

The text.

required
count int

The number of playlists. (default 50)

50
offset int

The offset. (default 0)

0

build_req_search_albums(text, count=50, offset=0) classmethod

Builds a request to search for albums by text.

Parameters:

Name Type Description Default
text str

The text.

required
count int

The number of albums. (default 50)

50
offset int

The offset. (default 0)

0

Builds a request to get popular audio.

Parameters:

Name Type Description Default
count int

The number of audio recordings. (default 500)

500
offset int

The offset. (default 0)

0

build_req_get_recommendations(user_id=None, song_id=None, count=100, offset=0) classmethod

Builds a request to get audio recommendations.

Parameters:

Name Type Description Default
user_id int

The user ID for which recommendations are being received. (default None)

None
song_id int

The song ID for which recommendations are being received. (default None)

None
count int

The number of audio recordings. (default 100)

100
offset int

The offset. (default 0)

0

VkApiResponse dataclass

A class that represents a response from VK API.

Attributes:

Name Type Description
data Any

The data.

VkApiException

Bases: Exception

A class that represents an exception that occurs when interacting with the VK API.

Attributes:

Name Type Description
error_code int

The error code.

error_msg str

The error message.

details dict

Additional error details.

__init__(error_code, error_msg, details)

Initializes a VkApiException object.

Parameters:

Name Type Description Default
error_code int

The error code.

required
error_msg str

The error message.

required
details dict

Additional error details.

required