VKBottle Types

5.199.99.20 · active · verified Thu Apr 16

vkbottle-types is a companion library to vkbottle, providing machine-generated type hints and Pydantic models for VK API methods and objects. It ensures robust type checking and auto-completion for developers working with the VK API. The current version is 5.199.99.20, with updates frequently released to reflect VK API changes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate and interact with Pydantic models provided by `vkbottle-types`. These models allow for strong type-hinting and validation of VK API objects, which are typically received or sent when using the `vkbottle` library.

import json
from vkbottle_types.objects import UsersUser, MessagesMessage

# Example 1: Instantiating a User type
user_data = {
    "id": 12345,
    "first_name": "Alex",
    "last_name": "Example",
    "is_closed": False,
    "can_access_closed": True
}
user: UsersUser = UsersUser(**user_data)
print(f"User ID: {user.id}, Full Name: {user.first_name} {user.last_name}")
print(f"User JSON: {user.json(indent=2)}")

# Example 2: Demonstrating another type's structure
message_payload_data = {
    "id": 1,
    "peer_id": 2000000001,
    "from_id": 12345,
    "date": 1678886400,
    "text": "Hello, vkbottle-types!",
    "random_id": 0,
    "attachments": [],
    "fwd_messages": [],
    "important": False,
    "is_hidden": False,
    "out": 0,
    "conversation_message_id": 1
}
message_payload: MessagesMessage = MessagesMessage(**message_payload_data)
print(f"Message text: '{message_payload.text}' from user {message_payload.from_id}")

# These types are primarily used for type hinting and data validation
# in vkbottle applications, not for direct API calls.

view raw JSON →