Skip to main content

Test Data Service

A working prototype of the above. Data is stored as JSON files on disk (one file per namespace), exposed through a REST API and a web interface, with optional role-based access control.

Install & run

# from PyPI (once published)
pip install test-data-service

# start the server (API + web UI) on http://127.0.0.1:8000
tds serve                       # or: python -m testdataservice serve
# open http://127.0.0.1:8000 in a browser

From source, for development:

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/tds serve

Packaging/release details (build, twine, GitHub Actions publish-on-release) are in CONTRIBUTING.md.

Configure with a YAML file

Drop a tds.yml (or tds.yaml) in your project root and just run tds serve — no flags needed. Environment variables override the file.

# tds.yml
data_dir: ./data        # where namespace files + .auth live
auth: true              # turn on accounts / access control
host: 127.0.0.1
port: 8000

Data model

Three levels: namespace → table → row.

  • A namespace is the unit of access control.
  • A namespace holds any number of tables.
  • A table holds rows, and each row is a record with an arbitrary set of fields. Field values can be any JSON (string, number, boolean, array, object, null).
  • A table can also have designed columns — a persisted column list you set up front (the "schema"), which shows even before any rows exist. The effective columns of a table are its designed columns plus any extra fields that appear in its rows, so the layout stays dynamic.

REST API

Method Path Permission Description
GET /api/health — Health + auth status
GET /api/whoami — Caller's access summary
GET /api/namespaces any key List accessible namespaces
POST /api/namespaces admin Create a namespace
DELETE /api/{ns} write ns Delete a namespace
GET /api/{ns} read ns List tables
POST /api/{ns} write ns Create a table ({"name": …})
GET /api/{ns}/{table} read ns Get a table's designed columns
PUT /api/{ns}/{table} write ns Design columns ({"columns":[…]})
DELETE /api/{ns}/{table} write ns Delete a table
GET /api/{ns}/{table}/rows read ns List rows (filter with ?col=value)
POST /api/{ns}/{table}/rows write ns Create a row (body = its fields)
GET /api/{ns}/{table}/rows/{id} read ns Get one row
PUT /api/{ns}/{table}/rows/{id} write ns Replace a row's fields
DELETE /api/{ns}/{table}/rows/{id} write ns Delete a row

In the web UI, open a table and use the Columns designer to add/remove columns; they persist and appear in the grid and the add-row form even with no rows yet.

curl -X POST localhost:8000/api/namespaces -H 'Content-Type: application/json' -d '{"name":"demo"}'
curl -X POST localhost:8000/api/demo       -H 'Content-Type: application/json' -d '{"name":"users"}'

# a row IS its fields — any shape you like
curl -X POST localhost:8000/api/demo/users/rows \
  -H 'Content-Type: application/json' \
  -d '{"name":"alice","age":30,"active":true}'
# -> {"id":"<row-id>","updated_at":"...","fields":{...}}

curl localhost:8000/api/demo/users/rows
# -> {"columns":["name","age","active", ...], "rows":[{"id":..., "fields":{...}}, ...]}

# filter by column conditions — each query param is a column=value test,
# and multiple are AND-ed together:
curl "localhost:8000/api/demo/users/rows?status=ok&ean=123"

Filter values are matched leniently: ean=123 matches a numeric 123 or the string "123", active=true matches the boolean. The web UI has a matching filter box on each table (type status=ok&ean=123).

(The names namespaces, health, whoami, keys, accounts, login, logout, password, and me are reserved and can't be used as namespaces.)

The API is self-documenting via OpenAPI:

  • /docs — Swagger UI (also linked as API docs in the web interface header)
  • /redoc — ReDoc
  • /openapi.json — raw OpenAPI schema

When auth is enabled, each operation in Swagger exposes an X-API-Key header field you can fill in to try requests.

CSV import / export (web UI only, per table)

Each table in the web UI has Download CSV / Import CSV buttons. A table maps naturally to CSV: the header row is the column names, each line is a row. These are built on the rows API (no dedicated CSV endpoints). On import, each cell is parsed leniently — 30 → number, true → boolean, [1,2] → array, anything else → string.

name,age,active
alice,30,true
bob,25,false

Access control (accounts + API keys)

Off by default. Turn it on with auth: true in tds.yml, --auth, or TDS_AUTH_ENABLED=1. There are two credential types, and you can use both:

  • User accounts — username + password. Humans log into the web UI (session cookie). Passwords are hashed with scrypt (a slow, salted KDF); the plaintext is never stored.
  • API keys — long random tokens for scripts/CI. Only a SHA-256 hash is stored; the token is shown once, at creation.

Access is scoped to each namespace. A role of admin means full CRUD on that namespace; reader means read-only. A global admin manages everything.

First run

On first start with auth on, a default admin account is created: username admin, password admin — and the web UI requires you to set a new password before anything else.

What the admin does (from the web UI)

  1. Create namespaces (the admin-only form in the sidebar).
  2. Create user accounts scoped to namespaces — e.g. alice with projects=admin (full CRUD on projects). Users then log in and create/read/update/delete data in their namespaces, from the web UI and the API.

Using the API as a user

Each signed-in user can mint a personal API key (web UI → My API keys, or POST /api/me/keys) that inherits their namespace permissions:

# the token is returned once; then use it as a header
curl -X POST localhost:8000/api/projects/people/rows \
  -H "X-API-Key: $TOKEN" -H "Content-Type: application/json" \
  -d '{"name":"alice","role":"qa"}'

Auth & admin endpoints (summary)

Method Path Who Purpose
POST /api/login anyone Log in (sets session cookie)
POST /api/logout anyone Clear session
POST /api/password user Change your own password
POST /api/namespaces admin Create a namespace
GET/POST/DELETE /api/accounts[/{user}] admin Manage user accounts
GET/POST/DELETE /api/me/keys[/{id}] user Manage your own API keys
GET/POST/PUT/DELETE /api/keys[/{id}] admin Manage standalone (machine) keys

Standalone machine-to-machine keys (not tied to an account) are still managed by an admin at /api/keys. For bootstrapping you may seed keys via TDS_API_KEYS or an admin token via TDS_ADMIN_KEY (both hashed in memory, never written to disk).

Configuration

Settings come from tds.yml/tds.yaml in the project root, overridden by environment variables:

YAML key Env var Default Purpose
data_dir TDS_DATA_DIR ./tds-data Data + .auth/ live here
storage TDS_STORAGE sqlite Storage backend: sqlite or file
db_path TDS_DB_PATH <data_dir>/tds.db SQLite DB path (sqlite backend)
auth TDS_AUTH_ENABLED false Turn access control on/off
host — 127.0.0.1 Bind host
port — 8000 Bind port
secret TDS_SECRET (generated) Signs web-UI session cookies
admin_key TDS_ADMIN_KEY (empty) Bootstrap machine admin token
api_keys TDS_API_KEYS (empty) Seed machine keys + grants
— TDS_KEY_PEPPER (empty) Optional pepper for API-key hashing

Storage backend

Data is kept in SQLite by default — a single tds.db file the app creates in data_dir on first start (no setup, no server). Rows store their dynamic fields in a JSON column, so the schema is fixed while the data stays free-form. Set storage: file to use one JSON file per namespace instead (human-readable and dependency-free, but it rewrites a whole file per change and isn't safe across processes). Either way, point data_dir at a persistent volume.

Credentials always live under <data_dir>/.auth/ (accounts.json, keys.json, secret) — hashed/secret material, never plaintext.

Tests

.venv/bin/python -m pytest

Metadata

Release files for test-data-service 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for test-data-service 0.3.0
File Size Uploaded Provenance Actions
test_data_service-0.3.0.tar.gz 39.7 kB Without provenance Details for test_data_service-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for test-data-service 0.3.0
File Interpreter ABI Platform Actions
test_data_service-0.3.0-py3-none-any.whl Python 3 none any Details for test_data_service-0.3.0-py3-none-any.whl

Total release size: 80.6 kB

Release files / test_data_service-0.3.0.tar.gz

Download URL test_data_service-0.3.0.tar.gz
Size 39.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e15b2650cbcb3c0e14fc52e6501741181859d8ab059e54221bd1acaf263547f7
BLAKE2b-256 checksum
How to use checksums
bd342246b82e2f5ef8ad9f2803ff08b4ef6494c5b59082167a5371db85591655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / test_data_service-0.3.0-py3-none-any.whl

Download URL test_data_service-0.3.0-py3-none-any.whl
Size 40.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
09842da639439c54ea106547110dd6ddea359e0d6a778adc928b8c2bbd5b1086
BLAKE2b-256 checksum
How to use checksums
27b1d2d184bec1e7dc0e8dcf5c52aa46a6ccd6e51fb876195b9f6cb6efa49e7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Security for test-data-service 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page