python-vk-bot 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,222 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ *.lcov
51
+ .hypothesis/
52
+ .pytest_cache/
53
+ cover/
54
+
55
+ # Translations
56
+ *.mo
57
+ *.pot
58
+
59
+ # Django stuff:
60
+ *.log
61
+ local_settings.py
62
+ db.sqlite3
63
+ db.sqlite3-journal
64
+
65
+ # Flask stuff:
66
+ instance/
67
+ .webassets-cache
68
+
69
+ # Scrapy stuff:
70
+ .scrapy
71
+
72
+ # Sphinx documentation
73
+ docs/_build/
74
+
75
+ # PyBuilder
76
+ .pybuilder/
77
+ target/
78
+
79
+ # Jupyter Notebook
80
+ .ipynb_checkpoints
81
+
82
+ # IPython
83
+ profile_default/
84
+ ipython_config.py
85
+
86
+ # pyenv
87
+ # For a library or package, you might want to ignore these files since the code is
88
+ # intended to run in multiple environments; otherwise, check them in:
89
+ # .python-version
90
+
91
+ # pipenv
92
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
94
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
95
+ # install all needed dependencies.
96
+ # Pipfile.lock
97
+
98
+ # uv
99
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
100
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
101
+ # commonly ignored for libraries.
102
+ # uv.lock
103
+
104
+ # poetry
105
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
106
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
107
+ # commonly ignored for libraries.
108
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
109
+ # poetry.lock
110
+ # poetry.toml
111
+
112
+ # pdm
113
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
114
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
115
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
116
+ # pdm.lock
117
+ # pdm.toml
118
+ .pdm-python
119
+ .pdm-build/
120
+
121
+ # pixi
122
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
123
+ # pixi.lock
124
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
125
+ # in the .venv directory. It is recommended not to include this directory in version control.
126
+ .pixi/*
127
+ !.pixi/config.toml
128
+
129
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
130
+ __pypackages__/
131
+
132
+ # Celery stuff
133
+ celerybeat-schedule*
134
+ celerybeat.pid
135
+
136
+ # Redis
137
+ *.rdb
138
+ *.aof
139
+ *.pid
140
+
141
+ # RabbitMQ
142
+ mnesia/
143
+ rabbitmq/
144
+ rabbitmq-data/
145
+
146
+ # ActiveMQ
147
+ activemq-data/
148
+
149
+ # SageMath parsed files
150
+ *.sage.py
151
+
152
+ # Environments
153
+ .env
154
+ .envrc
155
+ .venv
156
+ env/
157
+ venv/
158
+ ENV/
159
+ env.bak/
160
+ venv.bak/
161
+
162
+ # Spyder project settings
163
+ .spyderproject
164
+ .spyproject
165
+
166
+ # Rope project settings
167
+ .ropeproject
168
+
169
+ # mkdocs/Zensical documentation
170
+ /site
171
+
172
+ # mypy
173
+ .mypy_cache/
174
+ .dmypy.json
175
+ dmypy.json
176
+
177
+ # Pyre type checker
178
+ .pyre/
179
+
180
+ # pytype static type analyzer
181
+ .pytype/
182
+
183
+ # Cython debug symbols
184
+ cython_debug/
185
+
186
+ # PyCharm
187
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
188
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
189
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
190
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
191
+ # .idea/
192
+
193
+ # Abstra
194
+ # Abstra is an AI-powered process automation framework.
195
+ # Ignore directories containing user credentials, local state, and settings.
196
+ # Learn more at https://abstra.io/docs
197
+ .abstra/
198
+
199
+ # Visual Studio Code
200
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
201
+ # can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
202
+ # and can be added to the global gitignore or merged into this file. However, if you prefer, you
203
+ # could uncomment the following to ignore the entire vscode folder
204
+ # .vscode/
205
+ # Temporary file for partial code execution
206
+ tempCodeRunnerFile.py
207
+
208
+ # Ruff stuff:
209
+ .ruff_cache/
210
+
211
+ # PyPI configuration file
212
+ .pypirc
213
+
214
+ # Marimo
215
+ marimo/_static/
216
+ marimo/_lsp/
217
+ __marimo__/
218
+
219
+ # Streamlit
220
+ .streamlit/secrets.toml
221
+
222
+ .agent-work/
@@ -0,0 +1,32 @@
1
+ # Changelog
2
+
3
+ All notable changes will be documented here, following Keep a Changelog.
4
+
5
+ ## 0.1.0 - 2026-10-31
6
+
7
+ ### Added
8
+
9
+ - Internal vk-api-upgrade Agent Skill for maintainers to audit VK API compatibility and
10
+ implement approved upgrades.
11
+ - Bundled telegram-to-vk Agent Skill and migration reference in Python distributions,
12
+ discoverable with `uvx library-skills` after package installation.
13
+ - Agent Skills documentation covering installation, AI agent setup, usage and approval rules.
14
+ - Public BotSettings based on pydantic-settings, with VK_* environment variables, explicit
15
+ dotenv loading and subclass extensions; Long Poll and Callback examples use settings.
16
+ - Async Bot and Application with explicit lifecycle, ordered handlers, composable filters,
17
+ scoped context data and error callbacks.
18
+ - Pydantic v2 message/event models preserving unmodeled VK fields and raw event objects.
19
+ - Callback authentication, confirmation and an optional ASGI receiver with resource limits.
20
+ - Bounded in-memory suppression of successfully processed duplicate events.
21
+ - Python 3.14 package baseline and VK API 5.199 support, verified against official
22
+ documentation on 2026-10-31.
23
+ - Reusable HTTPX AsyncClient sessions with explicit ownership and timeouts.
24
+ - Asynchronous Long Poll with iterative session recovery.
25
+ - Messaging methods with nonzero int32 random_id generation, editing by message ID or cmid,
26
+ and forwarding from the source conversation.
27
+
28
+ ### Security
29
+
30
+ - Callback group/secret checks occur before event dispatch.
31
+ - Credentials and payloads are excluded from library error logs; HTTPX request log query
32
+ strings are redacted to protect Long Poll keys.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aleksei Fomenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,237 @@
1
+ Metadata-Version: 2.5
2
+ Name: python-vk-bot
3
+ Version: 0.1.0
4
+ Summary: An asynchronous framework for VK community bots.
5
+ Author-email: Aleksei Fomenko <fomenko_ai@proton.me>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Keywords: asyncio,bot,vk
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3.14
12
+ Classifier: Typing :: Typed
13
+ Requires-Python: >=3.14
14
+ Requires-Dist: httpx<1,>=0.28
15
+ Requires-Dist: pydantic-settings<3,>=2.12
16
+ Requires-Dist: pydantic<3,>=2.12
17
+ Provides-Extra: callback
18
+ Requires-Dist: starlette<1,>=0.49; extra == 'callback'
19
+ Requires-Dist: uvicorn<1,>=0.38; extra == 'callback'
20
+ Description-Content-Type: text/markdown
21
+
22
+ <p align="center">
23
+ <img src="logo.png" alt="python-vk-bot logo" width="720">
24
+ </p>
25
+
26
+ # python-vk-bot
27
+
28
+ An asynchronous framework for VK community bots, inspired by python-telegram-bot.
29
+ Development targets **Python 3.14** and VK API **5.199**. The regression suite runs without
30
+ network access; see [verification results](docs/development/verification.md).
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ uv add python-vk-bot
36
+ ```
37
+
38
+ ### Install from this checkout
39
+
40
+ ```bash
41
+ uv sync --locked
42
+ ```
43
+
44
+ For the optional Callback HTTP receiver:
45
+
46
+ ```bash
47
+ uv sync --locked --extra callback
48
+ ```
49
+
50
+ ## Long Poll bot
51
+
52
+ Enable Bots Long Poll and the `message_new` event in the community settings. Configure
53
+ its event version to match the supported API schema. Supply a community token with the
54
+ required permissions through the environment; messaging is subject to VK's conversation
55
+ and permission rules.
56
+
57
+ ```python
58
+ import asyncio
59
+
60
+ from python_vk_bot import Application, Bot, BotSettings, Context, MessageHandler, Update, filters
61
+
62
+
63
+ async def echo(update: Update, context: Context) -> None:
64
+ message = update.message
65
+ if message is not None:
66
+ await context.bot.send_message(message.peer_id, message.text)
67
+
68
+
69
+ async def main() -> None:
70
+ settings = BotSettings()
71
+ bot = Bot(settings.token, api_version=settings.api_version, timeout=settings.timeout)
72
+ app = Application(bot, settings.group_id)
73
+ app.add_handler(MessageHandler(echo, predicate=filters.TEXT))
74
+ await app.run_polling(wait=settings.polling_wait)
75
+
76
+
77
+ asyncio.run(main())
78
+ ```
79
+
80
+ With `VK_TOKEN` and `VK_GROUP_ID` already set, run the included example:
81
+
82
+ ```bash
83
+ uv run python examples/echo.py
84
+ ```
85
+
86
+ `run_polling()` is awaitable. Cancellation closes owned resources. Handlers run
87
+ sequentially, with the first match in each numeric group. `Context` exposes `bot`,
88
+ `user_data`, `peer_data` and `bot_data`. Use `MessageEventHandler` for button events,
89
+ `filters.LOCATION` for messages containing geo, and `CommandHandler` for `/command` tokens.
90
+
91
+ ## Settings
92
+
93
+ Import `BotSettings` from `python_vk_bot` or `python_vk_bot.settings`. It uses
94
+ `pydantic-settings` to load and validate configuration when you create an instance.
95
+ Importing the module does not read configuration or require credentials.
96
+
97
+ | Field | Environment variable | Default |
98
+ | --- | --- | --- |
99
+ | `token` | `VK_TOKEN` | Required, nonempty `SecretStr` |
100
+ | `group_id` | `VK_GROUP_ID` | Required, positive integer |
101
+ | `api_version` | `VK_API_VERSION` | `"5.199"` |
102
+ | `timeout` | `VK_TIMEOUT` | `40.0` seconds, positive and finite |
103
+ | `polling_wait` | `VK_POLLING_WAIT` | `25` seconds, between 1 and 90 |
104
+
105
+ Use environment variables directly:
106
+
107
+ ```python
108
+ from python_vk_bot import BotSettings
109
+
110
+ settings = BotSettings() # Read VK_* variables; no automatic .env loading.
111
+ ```
112
+
113
+ Alternatively, opt into a dotenv file and override a value for this instance:
114
+
115
+ ```python
116
+ from pathlib import Path
117
+
118
+ from python_vk_bot import BotSettings
119
+
120
+ settings = BotSettings(_env_file=Path(".env"), timeout=15.0)
121
+ ```
122
+
123
+ Explicit constructor values take precedence over environment variables, which take
124
+ precedence over dotenv values and field defaults. Unrelated dotenv entries are ignored,
125
+ so a project may share its `.env` with other components. Unknown constructor fields are
126
+ also ignored; use `extra="forbid"` in a subclass if you prefer strict configuration.
127
+ Settings only contain configuration: pass their values to `Bot`, `Application` and
128
+ `run_polling` explicitly as shown above. Keep real tokens and `.env` out of Git.
129
+
130
+ Extend the class with your project's fields:
131
+
132
+ ```python
133
+ from pathlib import Path
134
+
135
+ from pydantic import Field
136
+
137
+ from python_vk_bot import BotSettings
138
+
139
+
140
+ class ProjectSettings(BotSettings):
141
+ admin_ids: list[int] = Field(default_factory=list)
142
+ debug: bool = False
143
+
144
+
145
+ settings = ProjectSettings(_env_file=Path(".env"))
146
+ ```
147
+
148
+ These fields read `VK_ADMIN_IDS` (a JSON array such as `[123, 456]`) and `VK_DEBUG`
149
+ (for example, `true`). Override `model_config` with `SettingsConfigDict(env_prefix="MYBOT_")`
150
+ to use another prefix. A field with `Field(validation_alias="DATABASE_URL")` instead reads
151
+ that exact variable name, without the prefix. Token values remain `SecretStr` and can be
152
+ passed directly to `Bot`.
153
+
154
+ ## Bot without polling
155
+
156
+ ```python
157
+ async with Bot(token) as bot:
158
+ user = await bot.get_user_info(user_id)
159
+ ```
160
+
161
+ An injected `httpx.AsyncClient` remains caller-owned. Methods cover sending, editing,
162
+ forwarding, fetching a message/user, answering message events, and obtaining Long Poll
163
+ connection data. `Bot.request(method, parameters)` exposes raw JSON results for additional
164
+ VK methods; nested request parameters must be JSON encoded explicitly.
165
+
166
+ Messages use `peer_id`; `Message` exposes both `id` and `conversation_message_id`.
167
+ `send_message` returns an integer message ID and accepts an optional nonzero int32
168
+ `random_id`. Sends are never retried automatically. `edit_message` accepts exactly one
169
+ message identifier and maps `conversation_message_id` to VK's `cmid` parameter.
170
+
171
+ ## Callback API
172
+
173
+ The [Callback example](examples/callback.py) extends the same base settings with its
174
+ required secrets. For example, to construct a receiver from the environment:
175
+
176
+ ```python
177
+ from pydantic import Field, SecretStr
178
+
179
+ from python_vk_bot import Application, Bot, BotSettings, Callback
180
+
181
+
182
+ class CallbackSettings(BotSettings):
183
+ callback_secret: SecretStr = Field(min_length=1, repr=False)
184
+ callback_confirmation: SecretStr = Field(min_length=1, repr=False)
185
+
186
+
187
+ settings = CallbackSettings()
188
+ bot = Bot(settings.token, api_version=settings.api_version, timeout=settings.timeout)
189
+ application = Application(bot, settings.group_id)
190
+ # Register your handlers before starting the ASGI application.
191
+ callback = Callback(
192
+ application,
193
+ secret=settings.callback_secret,
194
+ confirmation_code=settings.callback_confirmation,
195
+ )
196
+ asgi_app = callback.create_app()
197
+ ```
198
+
199
+ Set `VK_TOKEN`, `VK_GROUP_ID`, `VK_CALLBACK_SECRET`, and `VK_CALLBACK_CONFIRMATION`, then:
200
+
201
+ ```bash
202
+ uv run --extra callback uvicorn examples.callback:create_app --factory
203
+ ```
204
+
205
+ Expose `/callback` through your HTTPS deployment and configure the same secret in VK.
206
+ ASGI lifespan manages startup/shutdown. `Callback.handle()` is also available for other
207
+ HTTP frameworks, provided the caller manages Application's async lifecycle.
208
+
209
+ Confirmation returns the configured confirmation code. Ordinary events return `ok` only
210
+ after successful processing. A bounded in-memory cache skips successful duplicates.
211
+ Partial handler failures, restarts and multiple workers can repeat side effects; this
212
+ is not a durable queue or an exactly-once processing guarantee. See the architecture
213
+ for delivery limitations and resource limits.
214
+
215
+ ## Agent Skills
216
+
217
+ The bundled **telegram-to-vk** Agent Skill helps AI coding agents migrate
218
+ `python-telegram-bot` applications to VK using `python-vk-bot`.
219
+
220
+ After installing a package version containing the skill, run from your bot project's root:
221
+
222
+ ```bash
223
+ uvx library-skills
224
+ ```
225
+
226
+ Select `telegram-to-vk` and the `.agents/skills` target for a compatible AI coding agent.
227
+ The skill adds no runtime dependencies and does not change the framework's behavior.
228
+ See [Agent Skills](docs/agent-skills.md) for package installation, installing from a local
229
+ checkout, and usage examples.
230
+
231
+ ## Documentation
232
+
233
+ - [Architecture and lifecycle](docs/architecture/project-architecture.md)
234
+ - [python-telegram-bot design mapping](docs/architecture/python-telegram-bot-compatibility.md)
235
+ - [VK API support](docs/development/api-compatibility.md)
236
+ - [Contributing and verification](CONTRIBUTING.md)
237
+ - [Changelog](CHANGELOG.md)