Skip to content

Commit 3fb7752

Browse files
CLAUDE.md
1 parent 7c20e75 commit 3fb7752

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CLAUDE.md

CLAUDE.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## What This Is
2+
3+
Python wrapper around Telegram's TDLib C library. Provides a synchronous API over TDLib's async backend using ctypes, threads, and a promise-like `AsyncResult` pattern.
4+
5+
## Commands
6+
7+
```bash
8+
# Run full test suite + linting + type checks
9+
tox
10+
11+
# Run tests for a specific Python version
12+
tox -e py312
13+
14+
# Run a single test
15+
tox -e py312 -- -k test_send_message
16+
17+
# Lint
18+
tox -e ruff
19+
20+
# Format check
21+
tox -e ruff-format
22+
23+
# Auto-fix lint/format
24+
ruff check --fix && ruff format
25+
26+
# Type check (strict mode)
27+
tox -e mypy
28+
29+
# Build Docker image
30+
make docker/build
31+
32+
# Build PyPI package
33+
make build-pypi
34+
```
35+
36+
## Architecture
37+
38+
**TDJson** (`telegram/tdjson.py`) — ctypes binding to `libtdjson`. Handles library discovery (system path → bundled precompiled in `telegram/lib/{darwin,linux}/`), creation/destruction of TDLib client instances, and JSON send/receive/execute.
39+
40+
**Telegram** (`telegram/client.py`) — high-level client. Manages login flow via an `AuthorizationState` state machine (NONE → WAIT_TDLIB_PARAMETERS → ... → READY). All API calls return an `AsyncResult`; a background `_listen_to_td` thread receives TDLib responses and matches them to pending results by `@extra` request ID.
41+
42+
**AsyncResult** (`telegram/utils.py`) — promise-like wrapper. `wait(timeout, raise_exc)` blocks until TDLib responds. Special-cased for `updateAuthorizationState` (doesn't resolve on bare "ok" responses).
43+
44+
**Worker** (`telegram/worker.py`) — processes message/update handlers in a daemon thread. `add_message_handler()` and `add_update_handler()` register callbacks that the worker dispatches from a queue.

0 commit comments

Comments
 (0)