plystore 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.
- plystore-0.1.0/.github/workflows/ci.yml +101 -0
- plystore-0.1.0/.github/workflows/publish.yml +57 -0
- plystore-0.1.0/.gitignore +10 -0
- plystore-0.1.0/.prettierignore +6 -0
- plystore-0.1.0/.prettierrc +4 -0
- plystore-0.1.0/.python-version +1 -0
- plystore-0.1.0/CHANGELOG.md +25 -0
- plystore-0.1.0/LICENSE +21 -0
- plystore-0.1.0/Makefile +72 -0
- plystore-0.1.0/PKG-INFO +153 -0
- plystore-0.1.0/README.md +133 -0
- plystore-0.1.0/docker/compose.yml +23 -0
- plystore-0.1.0/pyproject.toml +72 -0
- plystore-0.1.0/scripts/backup.sh +31 -0
- plystore-0.1.0/scripts/compare.sh +30 -0
- plystore-0.1.0/scripts/demo.py +186 -0
- plystore-0.1.0/scripts/release.py +122 -0
- plystore-0.1.0/scripts/restore.sh +24 -0
- plystore-0.1.0/src/plystore/__init__.py +9 -0
- plystore-0.1.0/src/plystore/check.py +60 -0
- plystore-0.1.0/src/plystore/cli.py +90 -0
- plystore-0.1.0/src/plystore/config.py +58 -0
- plystore-0.1.0/src/plystore/copy.py +126 -0
- plystore-0.1.0/src/plystore/files.py +167 -0
- plystore-0.1.0/src/plystore/formats/__init__.py +14 -0
- plystore-0.1.0/src/plystore/formats/common.py +8 -0
- plystore-0.1.0/src/plystore/formats/plyagents.py +80 -0
- plystore-0.1.0/src/plystore/formats/plybench.py +161 -0
- plystore-0.1.0/src/plystore/formats/plybench_analysis.py +76 -0
- plystore-0.1.0/src/plystore/keys.py +39 -0
- plystore-0.1.0/src/plystore/mapping.py +339 -0
- plystore-0.1.0/src/plystore/memory.py +72 -0
- plystore-0.1.0/src/plystore/postgres/__init__.py +0 -0
- plystore-0.1.0/src/plystore/postgres/admin.py +77 -0
- plystore-0.1.0/src/plystore/postgres/migrations/__init__.py +49 -0
- plystore-0.1.0/src/plystore/postgres/migrations/env.py +22 -0
- plystore-0.1.0/src/plystore/postgres/migrations/script.py.mako +21 -0
- plystore-0.1.0/src/plystore/postgres/migrations/versions/54922dd700f7_the_tables_of_every_format.py +882 -0
- plystore-0.1.0/src/plystore/postgres/migrations/versions/90f393b0252b_learner_states_whole_as_jsonb.py +120 -0
- plystore-0.1.0/src/plystore/postgres/schema.py +89 -0
- plystore-0.1.0/src/plystore/postgres/store.py +292 -0
- plystore-0.1.0/src/plystore/py.typed +0 -0
- plystore-0.1.0/src/plystore/routed.py +103 -0
- plystore-0.1.0/src/plystore/store.py +107 -0
- plystore-0.1.0/tests/conftest.py +39 -0
- plystore-0.1.0/tests/records.py +330 -0
- plystore-0.1.0/tests/test_contract.py +200 -0
- plystore-0.1.0/tests/test_copy.py +57 -0
- plystore-0.1.0/tests/test_files.py +56 -0
- plystore-0.1.0/tests/test_mapping.py +122 -0
- plystore-0.1.0/tests/test_postgres.py +104 -0
- plystore-0.1.0/tests/test_routed.py +84 -0
- plystore-0.1.0/uv.lock +445 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ci-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
|
|
18
|
+
- name: Install uv
|
|
19
|
+
uses: astral-sh/setup-uv@v5
|
|
20
|
+
with:
|
|
21
|
+
enable-cache: true
|
|
22
|
+
|
|
23
|
+
- name: Sync dependencies
|
|
24
|
+
run: uv sync --group dev --python 3.13
|
|
25
|
+
|
|
26
|
+
- name: Ruff lint
|
|
27
|
+
run: uv run ruff check .
|
|
28
|
+
|
|
29
|
+
- name: Ruff format check
|
|
30
|
+
run: uv run ruff format --check .
|
|
31
|
+
|
|
32
|
+
- name: Prettier format check
|
|
33
|
+
run: npx --yes prettier@3.9.6 --check .
|
|
34
|
+
|
|
35
|
+
typecheck:
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
|
|
40
|
+
- name: Install uv
|
|
41
|
+
uses: astral-sh/setup-uv@v5
|
|
42
|
+
with:
|
|
43
|
+
enable-cache: true
|
|
44
|
+
|
|
45
|
+
- name: Sync dependencies
|
|
46
|
+
run: uv sync --group dev --python 3.13
|
|
47
|
+
|
|
48
|
+
- name: Pyright
|
|
49
|
+
run: make typecheck
|
|
50
|
+
|
|
51
|
+
# every test, the Postgres ones on a Postgres of the same major version as the local compose file
|
|
52
|
+
test:
|
|
53
|
+
runs-on: ubuntu-latest
|
|
54
|
+
strategy:
|
|
55
|
+
fail-fast: false
|
|
56
|
+
matrix:
|
|
57
|
+
python-version: ["3.12", "3.13"]
|
|
58
|
+
services:
|
|
59
|
+
postgres:
|
|
60
|
+
image: postgres:16-alpine
|
|
61
|
+
env:
|
|
62
|
+
POSTGRES_USER: plystore
|
|
63
|
+
POSTGRES_PASSWORD: plystore
|
|
64
|
+
ports:
|
|
65
|
+
- 5432:5432
|
|
66
|
+
options: >-
|
|
67
|
+
--health-cmd "pg_isready -U plystore"
|
|
68
|
+
--health-interval 2s
|
|
69
|
+
--health-timeout 2s
|
|
70
|
+
--health-retries 30
|
|
71
|
+
steps:
|
|
72
|
+
- uses: actions/checkout@v4
|
|
73
|
+
|
|
74
|
+
- name: Install uv
|
|
75
|
+
uses: astral-sh/setup-uv@v5
|
|
76
|
+
with:
|
|
77
|
+
enable-cache: true
|
|
78
|
+
|
|
79
|
+
- name: Sync dependencies
|
|
80
|
+
run: uv sync --group dev --python ${{ matrix.python-version }}
|
|
81
|
+
|
|
82
|
+
- name: Run tests
|
|
83
|
+
run: uv run --group dev --python ${{ matrix.python-version }} pytest -q
|
|
84
|
+
env:
|
|
85
|
+
PLYSTORE_TEST_DATABASE_URL: postgresql://plystore:plystore@127.0.0.1:5432/plystore
|
|
86
|
+
|
|
87
|
+
build:
|
|
88
|
+
runs-on: ubuntu-latest
|
|
89
|
+
steps:
|
|
90
|
+
- uses: actions/checkout@v4
|
|
91
|
+
|
|
92
|
+
- name: Install uv
|
|
93
|
+
uses: astral-sh/setup-uv@v5
|
|
94
|
+
with:
|
|
95
|
+
enable-cache: true
|
|
96
|
+
|
|
97
|
+
- name: Build wheel and sdist
|
|
98
|
+
run: uv build
|
|
99
|
+
|
|
100
|
+
- name: Check package metadata
|
|
101
|
+
run: uvx twine check dist/*
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI when a GitHub Release is published (see scripts/release.py).
|
|
4
|
+
# Uses PyPI Trusted Publishing (OIDC) — no API token is stored.
|
|
5
|
+
# One-time setup on PyPI: add a trusted publisher for project "plystore" with
|
|
6
|
+
# owner=radajakub, repository=plystore, workflow=publish.yml, environment=pypi.
|
|
7
|
+
on:
|
|
8
|
+
release:
|
|
9
|
+
types: [published]
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
|
|
17
|
+
- name: Install uv
|
|
18
|
+
uses: astral-sh/setup-uv@v5
|
|
19
|
+
|
|
20
|
+
- name: Verify tag matches the package version
|
|
21
|
+
run: |
|
|
22
|
+
version="$(uv version --short)"
|
|
23
|
+
tag="${GITHUB_REF_NAME#v}"
|
|
24
|
+
if [ "$version" != "$tag" ]; then
|
|
25
|
+
echo "tag $GITHUB_REF_NAME does not match pyproject version $version" >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
|
|
29
|
+
- name: Build wheel and sdist
|
|
30
|
+
run: uv build
|
|
31
|
+
|
|
32
|
+
- name: Check package metadata
|
|
33
|
+
run: uvx twine check dist/*
|
|
34
|
+
|
|
35
|
+
- name: Upload build artifacts
|
|
36
|
+
uses: actions/upload-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
publish:
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
environment:
|
|
45
|
+
name: pypi
|
|
46
|
+
url: https://pypi.org/p/plystore
|
|
47
|
+
permissions:
|
|
48
|
+
id-token: write # required for trusted publishing
|
|
49
|
+
steps:
|
|
50
|
+
- name: Download build artifacts
|
|
51
|
+
uses: actions/download-artifact@v4
|
|
52
|
+
with:
|
|
53
|
+
name: dist
|
|
54
|
+
path: dist/
|
|
55
|
+
|
|
56
|
+
- name: Publish to PyPI
|
|
57
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-11-21
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- `Store`: one interface for records and append-only logs; `MemoryStore`, `FileStore` (plydata's layout and bytes),
|
|
14
|
+
`RoutedStore` (prefixes to backends, `also_read` for data written before a switch); `open_store` from a
|
|
15
|
+
`PLYSTORE_CONFIG` file, files when there is none, other backends through the `plystore.backends` entry points.
|
|
16
|
+
- Formats (`formats/`): the records of plybench, plyagents and plybench_analysis described as typed tables; `mapping`
|
|
17
|
+
splits a record into rows and rebuilds it, anything that does not fit a column kept in `extra`.
|
|
18
|
+
- `PostgresStore` (extra `postgres`): records in typed tables, one schema per repository, history for codebooks and
|
|
19
|
+
experiment files, shared texts, one transaction per write; migrations generated from the formats (Alembic);
|
|
20
|
+
`plystore-admin` (migrate, revision, roles, delete); a local compose file.
|
|
21
|
+
- `plystore-check`: the round trip of every record of a data folder, without a database.
|
|
22
|
+
- `copy` and `scan`, with the commands `plystore-copy` and `plystore-scan`, for importing a data folder; `copy` moves
|
|
23
|
+
records in batches of 200, reads them back, and falls back to one by one for a batch that fails; a log in batches of
|
|
24
|
+
2,000 records (`append_many`, one transaction each).
|
|
25
|
+
- Backup scripts: one dump per schema, restore into a new database, compare every table.
|
plystore-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jakub Rada
|
|
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.
|
plystore-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
.PHONY: lint typecheck format check fix test test-postgres check-data demo up down backup backup-check require-version release release-dry-run
|
|
2
|
+
|
|
3
|
+
# Check lint and formatting
|
|
4
|
+
lint:
|
|
5
|
+
uv run ruff check .
|
|
6
|
+
uv run ruff format --check .
|
|
7
|
+
npx --yes prettier@3.9.6 --check .
|
|
8
|
+
$(MAKE) typecheck
|
|
9
|
+
|
|
10
|
+
typecheck:
|
|
11
|
+
uv run pyright
|
|
12
|
+
|
|
13
|
+
# Alias for lint
|
|
14
|
+
check: lint
|
|
15
|
+
|
|
16
|
+
# Autofix lint issues and reformat
|
|
17
|
+
format:
|
|
18
|
+
uv run ruff check --fix .
|
|
19
|
+
uv run ruff format .
|
|
20
|
+
npx --yes prettier@3.9.6 --write .
|
|
21
|
+
|
|
22
|
+
# Alias for format
|
|
23
|
+
fix: format
|
|
24
|
+
|
|
25
|
+
test:
|
|
26
|
+
uv run --group dev pytest -q
|
|
27
|
+
|
|
28
|
+
LOCAL_DATABASE ?= postgresql://plystore:plystore@127.0.0.1:55432/plystore
|
|
29
|
+
|
|
30
|
+
# The Postgres tests too, on the local compose Postgres (make up first)
|
|
31
|
+
test-postgres:
|
|
32
|
+
PLYSTORE_TEST_DATABASE_URL=$(LOCAL_DATABASE) uv run --group dev pytest -q
|
|
33
|
+
|
|
34
|
+
# The round trip of every record of a data folder through its format, no database: make check-data DATA=../plydata/plybench
|
|
35
|
+
check-data:
|
|
36
|
+
uv run plystore-check $(DATA)
|
|
37
|
+
|
|
38
|
+
# Files and Postgres side by side on one folder of plydata (make up first; scripts/demo.py); DEMO_ARGS=--keep to look around after
|
|
39
|
+
demo:
|
|
40
|
+
PLYSTORE_DATABASE_URL=$(LOCAL_DATABASE) uv run python scripts/demo.py $(DEMO_ARGS)
|
|
41
|
+
|
|
42
|
+
# The local Postgres (docker/compose.yml); down keeps the data volume
|
|
43
|
+
up:
|
|
44
|
+
docker compose -f docker/compose.yml up -d
|
|
45
|
+
|
|
46
|
+
down:
|
|
47
|
+
docker compose -f docker/compose.yml down
|
|
48
|
+
|
|
49
|
+
POSTGRES ?= plystore-postgres-1
|
|
50
|
+
BACKUPS ?= backups
|
|
51
|
+
|
|
52
|
+
# Dump every schema of the local compose Postgres into $(BACKUPS) (scripts/backup.sh; never removes old dumps)
|
|
53
|
+
backup:
|
|
54
|
+
scripts/backup.sh $(POSTGRES) $(BACKUPS)
|
|
55
|
+
|
|
56
|
+
# The restore check: dump the plybench schema, restore it into a new database, compare the two, then drop that copy
|
|
57
|
+
backup-check:
|
|
58
|
+
scripts/backup.sh $(POSTGRES) $(BACKUPS) plybench
|
|
59
|
+
scripts/restore.sh $(POSTGRES) $$(ls -t $(BACKUPS)/plybench-*.dump | head -1) plystore_restore_check
|
|
60
|
+
scripts/compare.sh $(POSTGRES) plybench plystore plystore_restore_check; status=$$?; docker exec $(POSTGRES) dropdb -U plystore plystore_restore_check; exit $$status
|
|
61
|
+
|
|
62
|
+
require-version:
|
|
63
|
+
@test -n "$(VERSION)" || (echo "usage: make $(MAKECMDGOALS) VERSION=0.1.0" >&2; exit 1)
|
|
64
|
+
|
|
65
|
+
# Cut a release: make release VERSION=0.1.0
|
|
66
|
+
# Bumps the version, tags it, and publishes a GitHub Release, which triggers the PyPI upload. The Postgres tests run in CI (on its Postgres).
|
|
67
|
+
release: require-version lint test
|
|
68
|
+
uv run python scripts/release.py $(VERSION)
|
|
69
|
+
|
|
70
|
+
# Print every step of a release without changing anything
|
|
71
|
+
release-dry-run: require-version
|
|
72
|
+
uv run python scripts/release.py $(VERSION) --dry-run
|
plystore-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: plystore
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: One storage interface for the outputs of ply runs: records and logs in memory, in files, or in typed PostgreSQL tables.
|
|
5
|
+
Author-email: Jakub Rada <dev.jakubrada@icloud.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Science/Research
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Python: >=3.12
|
|
15
|
+
Provides-Extra: postgres
|
|
16
|
+
Requires-Dist: alembic>=1.15; extra == 'postgres'
|
|
17
|
+
Requires-Dist: psycopg[binary]>=3.2; extra == 'postgres'
|
|
18
|
+
Requires-Dist: sqlalchemy>=2.0.40; extra == 'postgres'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# plystore
|
|
22
|
+
|
|
23
|
+
One storage interface for what ply runs write: records (JSON documents, or text) and append-only logs. A writer
|
|
24
|
+
(plybench, plyagents, plybench_analysis, plyservice) gets a `Store` and never knows where its data goes; which backend
|
|
25
|
+
holds what is configuration only.
|
|
26
|
+
|
|
27
|
+
- `MemoryStore`: everything in memory, for tests and for runs that leave nothing behind.
|
|
28
|
+
- `FileStore`: each record a file under a root folder, as plydata holds them today (same bytes, same layout).
|
|
29
|
+
- `RoutedStore`: key prefixes routed to backends (`plots/` to files, the rest elsewhere), with `also_read` stores that
|
|
30
|
+
hold what was written before a switch.
|
|
31
|
+
- `PostgresStore` (extra `postgres`): each record in typed tables, one schema per repository.
|
|
32
|
+
|
|
33
|
+
The client (`plystore`) has no dependencies. The PostgreSQL backend comes with `plystore[postgres]` (SQLAlchemy,
|
|
34
|
+
psycopg, Alembic) and is loaded through the `plystore.backends` entry point only when a configuration names it.
|
|
35
|
+
|
|
36
|
+
plybench does not depend on plystore: it keeps its results through its own small store protocol, as files by default.
|
|
37
|
+
With `PLYBENCH_STORE=plystore` it opens this package's configured store instead (`open_store`, through the
|
|
38
|
+
`plybench.stores` entry point); plyagents and plybench_analysis write through plybench's store, so the same variable
|
|
39
|
+
covers them.
|
|
40
|
+
|
|
41
|
+
## Keys
|
|
42
|
+
|
|
43
|
+
A key names a record like a relative path, e.g. `results/benchmarks/ttt_10/a_b/game_1.json`. Its suffix says what it
|
|
44
|
+
holds: `.json` a JSON value, `.jsonl` a log of JSON records (`append`, `read_log`), anything else text. Parts may not
|
|
45
|
+
be empty, start with `.`, or end in `.tmp` or `.lock` (names the backends keep for themselves).
|
|
46
|
+
|
|
47
|
+
## The interface
|
|
48
|
+
|
|
49
|
+
| Call | Does |
|
|
50
|
+
| -------------------------------------- | --------------------------------------------------------------------- |
|
|
51
|
+
| `put(key, value, replace=False)` | write a record; write-once unless `replace` (`DocumentExists`) |
|
|
52
|
+
| `put_many({key: value})` | several new records, all or none |
|
|
53
|
+
| `get(key)` | the record, or `None` |
|
|
54
|
+
| `get_many(keys)` | the records of those keys that exist, in one call |
|
|
55
|
+
| `exists(key)`, `keys(prefix)` | whether it is there; every key under a prefix, by whole parts, sorted |
|
|
56
|
+
| `append(key, record)`, `read_log(key)` | one record at the end of a log; the records in order |
|
|
57
|
+
| `append_many(key, records)` | several records at the end of a log, all or none, in one call |
|
|
58
|
+
| `delete(prefix)` | every record under a non-empty prefix (an admin action) |
|
|
59
|
+
|
|
60
|
+
What PostgreSQL cannot hold (NaN, infinities, the NUL character, lone surrogates) is refused by every backend, so a run
|
|
61
|
+
finds out at once, not after a switch.
|
|
62
|
+
|
|
63
|
+
## Formats: records in typed tables
|
|
64
|
+
|
|
65
|
+
plystore follows the formats of the repositories that write; the repositories know nothing of it. `formats/` describes
|
|
66
|
+
each kind of record (a plybench game, matchup, training run, learner call list and LLM block log; a plyagents learner
|
|
67
|
+
state and update; a plybench_analysis annotation, verdict, decision, judge response and failure, codebook; an experiment
|
|
68
|
+
file) by its key pattern and a tree of nodes:
|
|
69
|
+
|
|
70
|
+
- `Column`: one field into a typed column (`str`, `int`, `float`, `bool`, `json`, lists of `str` or `int`; `shared` for
|
|
71
|
+
long texts that repeat, kept once in `texts`);
|
|
72
|
+
- `Flatten`: the fields of a nested object into columns of the same row (`ending.result` → `end_result`);
|
|
73
|
+
- `Child`: a list of objects, or a dict of objects one or more levels deep, into rows of another table;
|
|
74
|
+
- `Choice`: the first of several shapes that takes the value whole (a memory of texts or a table of values).
|
|
75
|
+
|
|
76
|
+
A value goes into a column only if it has exactly the column's type; anything else (a null, another type, a field no
|
|
77
|
+
node names) stays in the row's `extra` (jsonb). So every record rebuilds to itself, types included, and nothing is
|
|
78
|
+
refused. A record no format matches is kept whole (`unmapped`). Tables are generated from the formats
|
|
79
|
+
(`postgres/schema.py`), and so are the migrations.
|
|
80
|
+
|
|
81
|
+
`plystore-check <data folder>` splits and rebuilds every record of a folder without a database and reports what did not
|
|
82
|
+
rebuild, what no store would take, and which fields have values outside the typed columns. ply's release checks it over
|
|
83
|
+
plydata for plybench, plyagents and plybench_analysis (the `plystore` contracts in plytools).
|
|
84
|
+
|
|
85
|
+
## PostgreSQL
|
|
86
|
+
|
|
87
|
+
One database, one schema per repository that ran the work (`plybench`, `plyagents`, `plybench_analysis`); every schema
|
|
88
|
+
has every table, so one repository's data is dumped or dropped as a whole. Training runs from the plyagents checkout,
|
|
89
|
+
so its plybench records are in the `plyagents` schema.
|
|
90
|
+
|
|
91
|
+
- `records`: one row per key (its format and time); every root row references it `ON DELETE CASCADE`, and every child
|
|
92
|
+
row its parent, so `delete(prefix)` removes everything under the prefix.
|
|
93
|
+
- A format's root table: `key`, `folder` (records link by folder: a game's matchup is the `metadata.json` in its
|
|
94
|
+
folder), `saved`, the columns, `extra`. Formats that keep history (codebooks, experiment files) mark a replaced row
|
|
95
|
+
`replaced` instead of deleting it.
|
|
96
|
+
- A child table: `parent_id`, `position`, `part` (when several nodes share it), its dict key columns.
|
|
97
|
+
- A write is one transaction: a record with all its rows, or a `put_many` with all its records.
|
|
98
|
+
|
|
99
|
+
A writer refuses a schema whose migration is not the one its formats were made for. Administration (`plystore-admin`,
|
|
100
|
+
URL from `--url` or `PLYSTORE_DATABASE_URL`):
|
|
101
|
+
|
|
102
|
+
- `migrate --schema plybench plyagents plybench_analysis`: create and upgrade the schemas;
|
|
103
|
+
- `revision --message "..."`: generate the next migration after a format changed (in a scratch schema, rolled back);
|
|
104
|
+
- `roles --schema ...`: group roles `plystore_<schema>_write` (rows of that schema only) and `plystore_read`; login
|
|
105
|
+
roles are granted them by hand;
|
|
106
|
+
- `delete --schema plybench --prefix results/benchmarks/ttt [--yes]`: list, then delete an experiment.
|
|
107
|
+
|
|
108
|
+
Locally: `make up` starts Postgres on 127.0.0.1:55432 (`docker/compose.yml`); `make down` stops it and keeps the volume.
|
|
109
|
+
|
|
110
|
+
## Configuration
|
|
111
|
+
|
|
112
|
+
`open_store(root)` reads the file `PLYSTORE_CONFIG` names; without one every key is a file under `root`, as today.
|
|
113
|
+
|
|
114
|
+
```toml
|
|
115
|
+
[postgres]
|
|
116
|
+
schema = "plyagents"
|
|
117
|
+
url_env = "PLYSTORE_DATABASE_URL"
|
|
118
|
+
|
|
119
|
+
[[route]]
|
|
120
|
+
prefix = ""
|
|
121
|
+
store = "postgres"
|
|
122
|
+
also_read = ["files"]
|
|
123
|
+
|
|
124
|
+
[[route]]
|
|
125
|
+
prefix = "plots"
|
|
126
|
+
store = "files"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Commands
|
|
130
|
+
|
|
131
|
+
- `plystore-check <data folder>`: read only; the round trip of every record through its format.
|
|
132
|
+
- `plystore-scan <data folder>`: read only; what an import would move (by kind and folder), the files it skips, and
|
|
133
|
+
the records no store would take.
|
|
134
|
+
- `plystore-copy <data folder> <config> --target-root <root>`: copy every record into the configured store and read it
|
|
135
|
+
back; never overwrites; a key with other content there is reported as a conflict; safe to run again.
|
|
136
|
+
|
|
137
|
+
## Releases
|
|
138
|
+
|
|
139
|
+
`make release VERSION=X.Y.Z` (or ply's `make release REPO=plystore VERSION=X.Y.Z`) tags a GitHub Release; its workflow
|
|
140
|
+
publishes to PyPI by trusted publishing (`.github/workflows/publish.yml`). Backups: `scripts/backup.sh` (one dump per
|
|
141
|
+
schema), `scripts/restore.sh` and `scripts/compare.sh`; `make backup-check` dumps, restores into a new database, and
|
|
142
|
+
compares every table.
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
uv sync
|
|
148
|
+
make test # without Postgres: the Postgres tests are skipped
|
|
149
|
+
make up && make test-postgres
|
|
150
|
+
make check-data DATA=../plydata/plybench
|
|
151
|
+
make demo # files and Postgres side by side on one plydata folder (DEMO_ARGS=--keep to look around)
|
|
152
|
+
make lint
|
|
153
|
+
```
|
plystore-0.1.0/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# plystore
|
|
2
|
+
|
|
3
|
+
One storage interface for what ply runs write: records (JSON documents, or text) and append-only logs. A writer
|
|
4
|
+
(plybench, plyagents, plybench_analysis, plyservice) gets a `Store` and never knows where its data goes; which backend
|
|
5
|
+
holds what is configuration only.
|
|
6
|
+
|
|
7
|
+
- `MemoryStore`: everything in memory, for tests and for runs that leave nothing behind.
|
|
8
|
+
- `FileStore`: each record a file under a root folder, as plydata holds them today (same bytes, same layout).
|
|
9
|
+
- `RoutedStore`: key prefixes routed to backends (`plots/` to files, the rest elsewhere), with `also_read` stores that
|
|
10
|
+
hold what was written before a switch.
|
|
11
|
+
- `PostgresStore` (extra `postgres`): each record in typed tables, one schema per repository.
|
|
12
|
+
|
|
13
|
+
The client (`plystore`) has no dependencies. The PostgreSQL backend comes with `plystore[postgres]` (SQLAlchemy,
|
|
14
|
+
psycopg, Alembic) and is loaded through the `plystore.backends` entry point only when a configuration names it.
|
|
15
|
+
|
|
16
|
+
plybench does not depend on plystore: it keeps its results through its own small store protocol, as files by default.
|
|
17
|
+
With `PLYBENCH_STORE=plystore` it opens this package's configured store instead (`open_store`, through the
|
|
18
|
+
`plybench.stores` entry point); plyagents and plybench_analysis write through plybench's store, so the same variable
|
|
19
|
+
covers them.
|
|
20
|
+
|
|
21
|
+
## Keys
|
|
22
|
+
|
|
23
|
+
A key names a record like a relative path, e.g. `results/benchmarks/ttt_10/a_b/game_1.json`. Its suffix says what it
|
|
24
|
+
holds: `.json` a JSON value, `.jsonl` a log of JSON records (`append`, `read_log`), anything else text. Parts may not
|
|
25
|
+
be empty, start with `.`, or end in `.tmp` or `.lock` (names the backends keep for themselves).
|
|
26
|
+
|
|
27
|
+
## The interface
|
|
28
|
+
|
|
29
|
+
| Call | Does |
|
|
30
|
+
| -------------------------------------- | --------------------------------------------------------------------- |
|
|
31
|
+
| `put(key, value, replace=False)` | write a record; write-once unless `replace` (`DocumentExists`) |
|
|
32
|
+
| `put_many({key: value})` | several new records, all or none |
|
|
33
|
+
| `get(key)` | the record, or `None` |
|
|
34
|
+
| `get_many(keys)` | the records of those keys that exist, in one call |
|
|
35
|
+
| `exists(key)`, `keys(prefix)` | whether it is there; every key under a prefix, by whole parts, sorted |
|
|
36
|
+
| `append(key, record)`, `read_log(key)` | one record at the end of a log; the records in order |
|
|
37
|
+
| `append_many(key, records)` | several records at the end of a log, all or none, in one call |
|
|
38
|
+
| `delete(prefix)` | every record under a non-empty prefix (an admin action) |
|
|
39
|
+
|
|
40
|
+
What PostgreSQL cannot hold (NaN, infinities, the NUL character, lone surrogates) is refused by every backend, so a run
|
|
41
|
+
finds out at once, not after a switch.
|
|
42
|
+
|
|
43
|
+
## Formats: records in typed tables
|
|
44
|
+
|
|
45
|
+
plystore follows the formats of the repositories that write; the repositories know nothing of it. `formats/` describes
|
|
46
|
+
each kind of record (a plybench game, matchup, training run, learner call list and LLM block log; a plyagents learner
|
|
47
|
+
state and update; a plybench_analysis annotation, verdict, decision, judge response and failure, codebook; an experiment
|
|
48
|
+
file) by its key pattern and a tree of nodes:
|
|
49
|
+
|
|
50
|
+
- `Column`: one field into a typed column (`str`, `int`, `float`, `bool`, `json`, lists of `str` or `int`; `shared` for
|
|
51
|
+
long texts that repeat, kept once in `texts`);
|
|
52
|
+
- `Flatten`: the fields of a nested object into columns of the same row (`ending.result` → `end_result`);
|
|
53
|
+
- `Child`: a list of objects, or a dict of objects one or more levels deep, into rows of another table;
|
|
54
|
+
- `Choice`: the first of several shapes that takes the value whole (a memory of texts or a table of values).
|
|
55
|
+
|
|
56
|
+
A value goes into a column only if it has exactly the column's type; anything else (a null, another type, a field no
|
|
57
|
+
node names) stays in the row's `extra` (jsonb). So every record rebuilds to itself, types included, and nothing is
|
|
58
|
+
refused. A record no format matches is kept whole (`unmapped`). Tables are generated from the formats
|
|
59
|
+
(`postgres/schema.py`), and so are the migrations.
|
|
60
|
+
|
|
61
|
+
`plystore-check <data folder>` splits and rebuilds every record of a folder without a database and reports what did not
|
|
62
|
+
rebuild, what no store would take, and which fields have values outside the typed columns. ply's release checks it over
|
|
63
|
+
plydata for plybench, plyagents and plybench_analysis (the `plystore` contracts in plytools).
|
|
64
|
+
|
|
65
|
+
## PostgreSQL
|
|
66
|
+
|
|
67
|
+
One database, one schema per repository that ran the work (`plybench`, `plyagents`, `plybench_analysis`); every schema
|
|
68
|
+
has every table, so one repository's data is dumped or dropped as a whole. Training runs from the plyagents checkout,
|
|
69
|
+
so its plybench records are in the `plyagents` schema.
|
|
70
|
+
|
|
71
|
+
- `records`: one row per key (its format and time); every root row references it `ON DELETE CASCADE`, and every child
|
|
72
|
+
row its parent, so `delete(prefix)` removes everything under the prefix.
|
|
73
|
+
- A format's root table: `key`, `folder` (records link by folder: a game's matchup is the `metadata.json` in its
|
|
74
|
+
folder), `saved`, the columns, `extra`. Formats that keep history (codebooks, experiment files) mark a replaced row
|
|
75
|
+
`replaced` instead of deleting it.
|
|
76
|
+
- A child table: `parent_id`, `position`, `part` (when several nodes share it), its dict key columns.
|
|
77
|
+
- A write is one transaction: a record with all its rows, or a `put_many` with all its records.
|
|
78
|
+
|
|
79
|
+
A writer refuses a schema whose migration is not the one its formats were made for. Administration (`plystore-admin`,
|
|
80
|
+
URL from `--url` or `PLYSTORE_DATABASE_URL`):
|
|
81
|
+
|
|
82
|
+
- `migrate --schema plybench plyagents plybench_analysis`: create and upgrade the schemas;
|
|
83
|
+
- `revision --message "..."`: generate the next migration after a format changed (in a scratch schema, rolled back);
|
|
84
|
+
- `roles --schema ...`: group roles `plystore_<schema>_write` (rows of that schema only) and `plystore_read`; login
|
|
85
|
+
roles are granted them by hand;
|
|
86
|
+
- `delete --schema plybench --prefix results/benchmarks/ttt [--yes]`: list, then delete an experiment.
|
|
87
|
+
|
|
88
|
+
Locally: `make up` starts Postgres on 127.0.0.1:55432 (`docker/compose.yml`); `make down` stops it and keeps the volume.
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
`open_store(root)` reads the file `PLYSTORE_CONFIG` names; without one every key is a file under `root`, as today.
|
|
93
|
+
|
|
94
|
+
```toml
|
|
95
|
+
[postgres]
|
|
96
|
+
schema = "plyagents"
|
|
97
|
+
url_env = "PLYSTORE_DATABASE_URL"
|
|
98
|
+
|
|
99
|
+
[[route]]
|
|
100
|
+
prefix = ""
|
|
101
|
+
store = "postgres"
|
|
102
|
+
also_read = ["files"]
|
|
103
|
+
|
|
104
|
+
[[route]]
|
|
105
|
+
prefix = "plots"
|
|
106
|
+
store = "files"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Commands
|
|
110
|
+
|
|
111
|
+
- `plystore-check <data folder>`: read only; the round trip of every record through its format.
|
|
112
|
+
- `plystore-scan <data folder>`: read only; what an import would move (by kind and folder), the files it skips, and
|
|
113
|
+
the records no store would take.
|
|
114
|
+
- `plystore-copy <data folder> <config> --target-root <root>`: copy every record into the configured store and read it
|
|
115
|
+
back; never overwrites; a key with other content there is reported as a conflict; safe to run again.
|
|
116
|
+
|
|
117
|
+
## Releases
|
|
118
|
+
|
|
119
|
+
`make release VERSION=X.Y.Z` (or ply's `make release REPO=plystore VERSION=X.Y.Z`) tags a GitHub Release; its workflow
|
|
120
|
+
publishes to PyPI by trusted publishing (`.github/workflows/publish.yml`). Backups: `scripts/backup.sh` (one dump per
|
|
121
|
+
schema), `scripts/restore.sh` and `scripts/compare.sh`; `make backup-check` dumps, restores into a new database, and
|
|
122
|
+
compares every table.
|
|
123
|
+
|
|
124
|
+
## Development
|
|
125
|
+
|
|
126
|
+
```sh
|
|
127
|
+
uv sync
|
|
128
|
+
make test # without Postgres: the Postgres tests are skipped
|
|
129
|
+
make up && make test-postgres
|
|
130
|
+
make check-data DATA=../plydata/plybench
|
|
131
|
+
make demo # files and Postgres side by side on one plydata folder (DEMO_ARGS=--keep to look around)
|
|
132
|
+
make lint
|
|
133
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# The local trial: Postgres on this machine, reachable from it only (127.0.0.1). The password is a fixed local value, not a secret; kamino gets
|
|
2
|
+
# its own stack with Swarm secrets. `make up` / `make down`; the data stays in the volume. One database (plystore), one schema per repo:
|
|
3
|
+
# PLYSTORE_DATABASE_URL=postgresql://plystore:plystore@127.0.0.1:55432/plystore uv run plystore-admin migrate --schema plybench plyagents plybench_analysis
|
|
4
|
+
name: plystore
|
|
5
|
+
|
|
6
|
+
services:
|
|
7
|
+
postgres:
|
|
8
|
+
image: postgres:16-alpine
|
|
9
|
+
environment:
|
|
10
|
+
POSTGRES_USER: plystore
|
|
11
|
+
POSTGRES_PASSWORD: plystore
|
|
12
|
+
ports:
|
|
13
|
+
- "127.0.0.1:55432:5432"
|
|
14
|
+
volumes:
|
|
15
|
+
- postgres_data:/var/lib/postgresql/data
|
|
16
|
+
healthcheck:
|
|
17
|
+
test: ["CMD", "pg_isready", "-U", "plystore"]
|
|
18
|
+
interval: 2s
|
|
19
|
+
timeout: 2s
|
|
20
|
+
retries: 30
|
|
21
|
+
|
|
22
|
+
volumes:
|
|
23
|
+
postgres_data:
|