Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ jobs:
- name: Assemble Pages site (landing + PEP 503 index)
run: python3 scripts/build_pages.py

- name: Publish consumer AGENTS.md + llms.txt
run: |
set -euo pipefail
mkdir -p _site/agents
cp docs/agents/AGENTS.md _site/agents/AGENTS.md
cat > _site/llms.txt <<'EOF'
# CockroachDB Python Library

Consumer guide for coding agents working in an app that depends on the
`cockroachdb` packages (which helpers to use, what not to hand-roll):
https://cockroachlabs.github.io/cockroachdb-python-library/agents/AGENTS.md

The same guide ships inside the installed base package at `cockroachdb/AGENTS.md`.
For CockroachDB database fundamentals, see https://docs.cockroachlabs.com/llms.txt
EOF

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A production-grade Python library for [CockroachDB](https://www.cockroachlabs.com/) that provides automatic transaction retry handling, multi-region support, follower reads, CDC webhook handlers, vector search, and RAG pipelines. Part of the CockroachDB language-specific library family alongside the [Java Spring Boot Starter](https://github.com/cockroachlabs/cockroachdb-java-library), [.NET Library](https://github.com/cockroachlabs/cockroachdb-dotnet-library), and [Go Library](https://github.com/cockroachlabs/cockroachdb-go-library).

> **Using an AI coding agent?** A consumer guide for agents working in your app ships inside the installed package at `cockroachdb/AGENTS.md` (source: [`docs/agents/AGENTS.md`](docs/agents/AGENTS.md)) — it tells the agent which helpers to use and what not to hand-roll.
> **Using an AI coding agent?** A consumer guide for agents working in your app lives in **two places**: inside the installed package at `cockroachdb/AGENTS.md` (shipped in the wheel) and on the Pages site at [`/agents/AGENTS.md`](https://cockroachlabs.github.io/cockroachdb-python-library/agents/AGENTS.md) (source: [`docs/agents/AGENTS.md`](docs/agents/AGENTS.md)) — it tells the agent which helpers to use and what not to hand-roll.

## Architecture

Expand Down
47 changes: 47 additions & 0 deletions docs/agents/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,50 @@ Everything is `CockroachDBConfig` (Pydantic), overridable via `CRDB_`-prefixed e

Use `cockroachdb-testing`: `CockroachDBFixture` (Testcontainers-backed real CockroachDB) and
`RetrySimulator` (injects `40001` failures to prove retry works). Don't mock the driver.

## Learn CockroachDB fundamentals

The library handles the Python side; these CockroachDB docs explain the database underneath. The
links below go to the Markdown version of each page, which is easier for an agent to read; drop the
`.md` for the HTML page. Every docs page has one, and <https://docs.cockroachlabs.com/llms.txt>
indexes the whole documentation site.

**Start here**

- [Developer Basics](https://docs.cockroachlabs.com/docs/stable/developer-basics.md): what's different about building on CockroachDB.
- [PostgreSQL Compatibility](https://docs.cockroachlabs.com/docs/stable/postgresql-compatibility.md): CockroachDB speaks the PostgreSQL wire protocol (use a PostgreSQL driver — `psycopg`, `asyncpg`, or SQLAlchemy), with some differences.
- [Connection Pooling](https://docs.cockroachlabs.com/docs/stable/connection-pooling.md): sizing a client-side pool.
- [Common Errors and Solutions](https://docs.cockroachlabs.com/docs/stable/common-errors.md)

**Transactions and contention**

- [Transactions](https://docs.cockroachlabs.com/docs/stable/transactions.md): SERIALIZABLE by default, and why clients see retry errors.
- [Transaction Retry Error Reference](https://docs.cockroachlabs.com/docs/stable/transaction-retry-error-reference.md): what each `40001` (`RETRY_SERIALIZABLE`, `RETRY_WRITE_TOO_OLD`, ...) means and how to make it rarer. The library retries them; this tells you why they happen.
- [Reduce transaction contention](https://docs.cockroachlabs.com/docs/stable/performance-best-practices-overview.md#reduce-transaction-contention): the checklist. Keep transactions small, limit the rows they touch, use `SELECT ... FOR UPDATE` for read-then-write, `UPSERT` whole rows, use historical reads where staleness is fine.
- [Understand Hotspots](https://docs.cockroachlabs.com/docs/stable/understand-hotspots.md): ranges that take far more traffic than others, and how to spread it.
- [Performance Tuning Recipes](https://docs.cockroachlabs.com/docs/stable/performance-recipes.md): symptoms and fixes, contention included.
- [Monitor and Analyze Transaction Contention](https://docs.cockroachlabs.com/docs/stable/monitor-and-analyze-transaction-contention.md)
- [`SELECT FOR UPDATE`](https://docs.cockroachlabs.com/docs/stable/select-for-update.md)
- [Read Committed Transactions](https://docs.cockroachlabs.com/docs/stable/read-committed.md): an alternative isolation level, with trade-offs. Don't switch to it just to avoid retries — at READ COMMITTED `40001` never surfaces and the library's retry silently no-ops.

**Schema design**

- [Database Schemas](https://docs.cockroachlabs.com/docs/stable/schema-design-overview.md): how to design and change schemas, including why to change them with a migration tool rather than through the ORM.
- [Unique ID best practices](https://docs.cockroachlabs.com/docs/stable/performance-best-practices-overview.md#unique-id-best-practices): prefer `UUID` keys (`gen_random_uuid()`) over sequences or auto-increment, which create hotspots.
- [`UUID`](https://docs.cockroachlabs.com/docs/stable/uuid.md) and [Hash-sharded Indexes](https://docs.cockroachlabs.com/docs/stable/hash-sharded-indexes.md), for when an index must be on a sequential column.
- [Online Schema Changes](https://docs.cockroachlabs.com/docs/stable/online-schema-changes.md): schema changes run in the background; what that means for migrations.

**Multi-region**

- [Multi-Region Capabilities Overview](https://docs.cockroachlabs.com/docs/stable/multiregion-overview.md)
- [Table Localities](https://docs.cockroachlabs.com/docs/stable/table-localities.md): `REGIONAL BY TABLE`, `REGIONAL BY ROW` and `GLOBAL`, which `@regional_by_row` and `@global_table` map to.
- [How to Choose a Multi-Region Configuration](https://docs.cockroachlabs.com/docs/stable/choosing-a-multi-region-configuration.md)
- [Follower Reads](https://docs.cockroachlabs.com/docs/stable/follower-reads.md) and [`AS OF SYSTEM TIME`](https://docs.cockroachlabs.com/docs/stable/as-of-system-time.md), behind `@follower_read`.

**Change data capture**

- [`CREATE CHANGEFEED`](https://docs.cockroachlabs.com/docs/stable/create-changefeed.md) and [Changefeed Sinks](https://docs.cockroachlabs.com/docs/stable/changefeed-sinks.md) (the webhook sink is what `@changefeed_handler` receives).

**Vector search**

- [`VECTOR`](https://docs.cockroachlabs.com/docs/stable/vector.md) and [Vector Indexes](https://docs.cockroachlabs.com/docs/stable/vector-indexes.md)
4 changes: 2 additions & 2 deletions examples/ideas-board/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ source .venv/bin/activate
pip install -r requirements.txt
```

`requirements.txt` pins the **published** `cockroachdb==0.1.3` (plus
`requirements.txt` pins the **published** `cockroachdb==0.1.4` (plus
`cockroachdb-testing==0.1.1`) and carries the `--extra-index-url` line for the
feed. A single-package install looks like:

```bash
pip install 'cockroachdb==0.1.3' \
pip install 'cockroachdb==0.1.4' \
--extra-index-url https://cockroachlabs.github.io/cockroachdb-python-library/simple/
```

Expand Down
2 changes: 1 addition & 1 deletion examples/ideas-board/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# anonymous PEP 503 feed, NOT public PyPI.
--extra-index-url https://cockroachlabs.github.io/cockroachdb-python-library/simple/

cockroachdb==0.1.3
cockroachdb==0.1.4
cockroachdb-core==0.3.0 # metrics (RetryEngine) + follower-read/region context
cockroachdb-sqlalchemy==0.3.0 # multi-region schema check (verify_multiregion_schema + ORM mixins); pulls sqlalchemy>=2.0
cockroachdb-cdc==0.2.0 # changefeed handlers + webhook payload parsing
Expand Down
2 changes: 1 addition & 1 deletion packages/cockroachdb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "cockroachdb"
version = "0.1.3"
version = "0.1.4"
description = "CockroachDB Python Library — base decorators, types, and configuration"
readme = "README.md"
requires-python = ">=3.11"
Expand Down
12 changes: 6 additions & 6 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading