|
| 1 | +# AGENTS.md — YDB Python SDK |
| 2 | + |
| 3 | +Official Python client for [YDB](https://ydb.tech/) — a fault-tolerant distributed SQL DBMS. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Project Structure |
| 8 | + |
| 9 | +| Path | Purpose | |
| 10 | +|------|---------| |
| 11 | +| `ydb/` | Synchronous client — canonical implementation | |
| 12 | +| `ydb/aio/` | Async client — mirrors `ydb/` API exactly | |
| 13 | +| `ydb/_grpc/v3/` … `v6/` | **Auto-generated protobuf stubs — never edit** | |
| 14 | +| `ydb/*_test.py` | Unit tests (fast, no Docker required) | |
| 15 | +| `tests/` | Integration tests (require Docker, auto-started by pytest) | |
| 16 | +| `examples/` | Usage examples | |
| 17 | +| `docs/` | User-facing documentation | |
| 18 | + |
| 19 | +## Development Environment |
| 20 | + |
| 21 | +```sh |
| 22 | +python3 -m venv .venv |
| 23 | +source .venv/bin/activate |
| 24 | +pip install -e . tox |
| 25 | +``` |
| 26 | + |
| 27 | +**Always activate the virtual environment before running any project commands.** |
| 28 | + |
| 29 | +## Code Quality |
| 30 | + |
| 31 | +```sh |
| 32 | +# Auto-fix formatting |
| 33 | +tox -e black-format |
| 34 | + |
| 35 | +# Check formatting |
| 36 | +tox -e black |
| 37 | + |
| 38 | +# Style (flake8) |
| 39 | +tox -e style |
| 40 | + |
| 41 | +# Type checking |
| 42 | +tox -e mypy |
| 43 | +``` |
| 44 | + |
| 45 | +Before submitting a PR, run all checks and unit tests: |
| 46 | +```sh |
| 47 | +tox -e black && tox -e style && tox -e mypy && tox -e py -- ydb -v |
| 48 | +``` |
| 49 | + |
| 50 | +## Testing |
| 51 | + |
| 52 | +```sh |
| 53 | +# Unit tests — fast, no Docker needed |
| 54 | +source .venv/bin/activate && tox -e py -- ydb -v |
| 55 | + |
| 56 | +# Integration tests — Docker started automatically by pytest-docker, do NOT start it manually |
| 57 | +source .venv/bin/activate && tox -e py -- tests -v |
| 58 | + |
| 59 | +# Single test file |
| 60 | +source .venv/bin/activate && tox -e py -- tests/path/to/test_file.py -v |
| 61 | +``` |
| 62 | + |
| 63 | +**Always run the relevant tests after implementing a feature or fix.** |
| 64 | + |
| 65 | +## Key Rules |
| 66 | + |
| 67 | +1. **Backward compatibility** — never break the public API; only extend it. |
| 68 | +2. **Sync/async parity** — every change in `ydb/` must be mirrored in `ydb/aio/`. |
| 69 | +3. **Tests required** — all changes must have tests; add to existing test files, do not create new ones. |
| 70 | +4. **No new dependencies** — the current dependency set is intentionally minimal. |
| 71 | +5. **No excessive comments** — do not comment self-evident code. |
| 72 | +6. **English only** — code, comments, docstrings, commit messages. |
| 73 | +7. **Python 3.8+** — do not use language or stdlib features beyond that baseline. |
| 74 | + |
| 75 | +## Documentation & Examples |
| 76 | + |
| 77 | +- Update `docs/` for any user-facing changes; create new sections if needed. |
| 78 | +- Extend `examples/` when adding new features. |
| 79 | + |
| 80 | +## Auto-generated Files — Do NOT Edit |
| 81 | + |
| 82 | +``` |
| 83 | +ydb/_grpc/v3/ |
| 84 | +ydb/_grpc/v4/ |
| 85 | +ydb/_grpc/v5/ |
| 86 | +ydb/_grpc/v6/ |
| 87 | +``` |
| 88 | + |
| 89 | +To regenerate protobuf stubs: see `Makefile` and `generate-protobuf.Dockerfile`. |
| 90 | + |
| 91 | +--- |
| 92 | + |
| 93 | +## Topic Chaos Testing (SLO) |
| 94 | + |
| 95 | +Run this only for changes that affect topic reader/writer reconnection logic. |
| 96 | + |
| 97 | +**1. Start YDB with chaos** (kills a DB node every ~20 seconds): |
| 98 | +```sh |
| 99 | +docker compose -f tests/slo/playground/configs/compose.yaml up -d |
| 100 | +``` |
| 101 | + |
| 102 | +**2. Wait until YDB is healthy:** |
| 103 | +```sh |
| 104 | +docker ps --format "table {{.Names}}\t{{.Status}}" | grep ydb |
| 105 | +``` |
| 106 | + |
| 107 | +**3. Create a test topic** (from `tests/slo/` directory): |
| 108 | +```sh |
| 109 | +source .venv/bin/activate |
| 110 | +python ./src topic-create grpc://localhost:2135 /Root/testdb \ |
| 111 | + --path /Root/testdb/slo_topic --debug |
| 112 | +``` |
| 113 | + |
| 114 | +**4. Test writer** (60 sec): |
| 115 | +```sh |
| 116 | +python ./src topic-run grpc://localhost:2135 /Root/testdb \ |
| 117 | + --path /Root/testdb/slo_topic --otlp-endpoint "" \ |
| 118 | + --read-threads 0 --write-rps 1 --time 60 --debug |
| 119 | +``` |
| 120 | + |
| 121 | +**5. Test reader** (60 sec): |
| 122 | +```sh |
| 123 | +python ./src topic-run grpc://localhost:2135 /Root/testdb \ |
| 124 | + --path /Root/testdb/slo_topic --otlp-endpoint "" \ |
| 125 | + --read-rps 1 --write-threads 0 --time 60 --debug |
| 126 | +``` |
| 127 | + |
| 128 | +**6. Tear down:** |
| 129 | +```sh |
| 130 | +docker compose -f tests/slo/playground/configs/compose.yaml down |
| 131 | +``` |
| 132 | + |
| 133 | +**Success criteria:** writer and reader reconnect automatically during node restarts with no fatal errors. |
0 commit comments