Skip to content

Python API: knowtation-api

Generated from the docstrings. The HTTP API itself is described by its OpenAPI document, served at /api/docs.

knowtation_api.app

The FastAPI application.

quiet_health_checks(root_path='')

Keep the container's health checks (every few seconds) out of uvicorn's access log.

Parameters:

Name Type Description Default
root_path str

The proxy prefix, which uvicorn includes in the logged path.

''

log_llm_calls()

Show a line per LLM call, and the provider libraries' retries, in the API log.

create_app(settings=None)

Build the API: migrate, seed the built-ins, ensure the admin, repair interrupted runs.

Raises:

Type Description
RuntimeError

No users exist and the settings name no admin, or people's own LLM keys are stored but KNOWTATION_SECRET_KEY is missing or malformed.

knowtation_api.settings

Settings from KNOWTATION_* environment variables, for example KNOWTATION_DATABASE_URL.

Settings

Bases: BaseSettings

Settings from KNOWTATION_* environment variables.

private_hosts property

The allowlisted host names as a tuple.

max_bytes property

The upload limit in bytes.

knowtation_api.db

Database tables (SQLAlchemy 2) and migrations (Alembic).

Base

Bases: DeclarativeBase

Base class of the database tables.

UserRow

Bases: Base

A person who signs in: their password hash, admin flag, status and API token hash.

SessionRow

Bases: Base

A signed-in browser session; the cookie holds the id, the table only its hash.

MemberRow

Bases: Base

A co-owner or reviewer of a dataset (the owner is datasets.owner_id).

RequestRow

Bases: Base

An invitation to review or co-own a dataset, or an ownership transfer, until answered.

DatasetRow

Bases: Base

A dataset: its source, its profile when read, and the proposals made while reading.

RunRow

Bases: Base

An identification run: what was asked for, its status and its reproducibility record.

TrialRow

Bases: Base

A trial: what rule sets, a policy and an LLM would produce; kept a day, never a version.

DictionaryVersionRow

Bases: Base

An immutable dictionary version: its content, its proposals and a review's changes.

RuleSetRow

Bases: _Versioned, Base

A stored rule-set version (immutable).

PolicyRow

Bases: _Versioned, Base

A stored confidence-policy version (immutable).

migrate(database_url)

Bring the database schema up to date.

grant_app_role(owner_url, app_url)

Create (or update the password of) the app's role and let it only read and write rows.

Run as the database owner after migrating. The role gets SELECT, INSERT, UPDATE and DELETE on the tables, now and for tables added later; it can't create, alter, drop or truncate anything.

fail_interrupted_runs(session)

Mark runs and trials left pending or running by a stopped server as failed.

Returns how many runs; trials are short-lived and not counted.

knowtation_api.registry

Rule sets and confidence policies stored as immutable versions.

VersionConflict

Bases: Exception

A version that already exists with different content.

NotYours

Bases: PermissionError

A name owned by someone else, or built in.

MissingRuleSet

Bases: LookupError

A requested rule set (name and optional version) isn't stored.

visible(row, user)

Whether the user may see and use this stored version (built-ins and public ones: all).

claim(session, row_type, name, user)

Allow user to store a version under name: new names, or names they own.

The admin may add versions to anyone's name. A name with any built-in version is built in: nobody adds versions to it, not even the admin.

Raises:

Type Description
NotYours

The name belongs to someone else or is built in.

store_rule_set(session, rs, owner_id=None)

Store a rule-set version; returns the row and whether it is new.

store_policy(session, p, owner_id=None)

Store a confidence-policy version; returns the row and whether it is new.

get_rule_set(session, name='core', version=None, user=None)

A stored rule set the user may see: the given version, or the latest with this name.

latest_rule_sets(session, user=None)

The latest version of every built-in, public or own rule set, oldest name first.

These are the candidates for automatic selection: other people's private rule sets never are, not even for the admin.

rule_sets_for_run(session, request, dataset, user=None)

The rule sets a run request asks for, as user (None: built-in and public ones only).

The explicit list, the single older-style rule set, or else the latest core plus every built-in, public or own pack whose applies_when holds.

get_policy(session, name='default', version=None, user=None)

A stored policy the user may see: the given version, or the latest with this name.

seed_builtins(session)

Store the built-in core rules, rule packs and policies (each version once).

builtin_keys()

(name, version, content hash) of every built-in rule set, pack and policy.

knowtation_api.services

Operations shared by routes: storing datasets, executing runs, reading versions.

store_profiled(session, profiled, *, name, source, owner_id, dataset_id=None)

Store a profiled dataset, owned by owner_id, with its proposals and warnings.

execute_source(sessions, settings, cs, dataset_id, url, name)

Download and read a URL source in the background, keeping its files with the dataset.

Files from an earlier attempt are replaced. The URL (which may be signed) lives only in memory here; nothing stores its credentials.

execute_reread(sessions, settings, cs, dataset_id, name)

Read a dataset's stored files again in the background (after a failure or new files).

latest_version_number(session, dataset_id)

The number of the dataset's latest dictionary version, or None.

summary(session, row, user)

A dataset for lists, with its owner and the user's access to it.

detail(session, row, user)

A dataset with its profile and warnings.

proposals_out(content, proposals, policy)

Proposals with provenance, whether each was chosen, and the policy's band.

profiled_of(row)

A stored dataset as profiled when it was read: description, proposals, warnings.

run_policy(session, run_id)

The policy a run used, for its bands; the default policy if there's no run record.

The run already used the policy, so this reads it whoever owns it: bands are display only.

dictionary_out(session, row)

A stored dictionary version with its proposals, chosen values and the run policy's bands.

resolve_llm(name, settings)

The model a run asks for: None (rules only), the default, the test model or a name.

execute_run(sessions, settings, run_id)

Run identification for a stored run request and store a new dictionary version.