HTTP API¶
omnitax serve speaks HTTP, on a Unix socket by default or on TCP with --tcp. All responses are
JSON (the rows endpoints stream NDJSON), and errors are objects {"error": "..."} with a 4xx or
5xx status. The endpoints are the batched primitives of the store protocol (see the
design): a client needs one request per batch, never
one per node. omnitax.connect wraps them.
curl --unix-socket "$XDG_RUNTIME_DIR/omnitax.sock" http://localhost/taxonomies
curl --unix-socket "$XDG_RUNTIME_DIR/omnitax.sock" http://localhost/ncbi/nodes -d '{"ids": ["562"]}'
{taxonomy} in a path is kind:version (gtdb:232; a colon is fine in a URL path) or a bare
kind, which is its newest version. A taxonomy the file does not have is a 404.
| Endpoint | Purpose |
|---|---|
GET / |
service name, version, api_version and the endpoints |
GET /health |
liveness: status, version, uptime |
GET /taxonomies |
the taxonomies served, the server's batch limit and the API version |
POST /{taxonomy}/nodes |
nodes by id |
POST /{taxonomy}/ancestors |
lineages |
POST /{taxonomy}/children |
children |
POST /{taxonomy}/names |
names and synonyms |
POST /{taxonomy}/by_name |
the nodes that many names name exactly |
POST /{taxonomy}/search |
exact, prefix and fuzzy name search |
POST /{taxonomy}/links |
the links of one kind for many bases (genome accessions without version, sequence accessions without region, ids), every version and source |
GET /{taxonomy}/links_under?id= |
the links at and below a node, of every kind, streamed as NDJSON, one [key, node id, source] per line (not capped; --no-export does not refuse it) |
GET /{taxonomy}/meta |
the taxonomy's metadata tables |
GET /{taxonomy}/rank/{rank} |
the nodes of a rank, as NDJSON |
GET /{taxonomy}/subtree?id=ID |
a node and everything below it in pre-order, as NDJSON |
GET /{taxonomy}/rows/{part} |
a whole taxonomy as NDJSON |
Bodies are JSON objects of at most 1 MiB. Ids are strings (an integer is accepted and read as its
string; an id of any length is allowed, a long one just names no node); lists hold at most max_batch (1000) entries. Every request runs in a
thread of its own, never on the event loop, so /health answers while the file is busy.
Taxonomies¶
GET /taxonomies answers {"api_version": 1, "max_batch": 1000, "taxonomies": [entry, ...]}. The API
version is an integer that changes with the wire format; RemoteStore refuses a server whose version is
not its own (strict equality). An entry has id,
label (kind:version), kind, version, built, fuzzy, nodes, names,
aliases, links, provenance ({"omnitax": version that built it, "files": [{"source", "size", "sha256", "verified"}]}: the files of the tree), link_sources ({label: {"kind": "genome", "links": n, "provenance": {"files": [...]}}}, in the order they were built: each source of links with the kind of its keys and the files its links came from; provenance is empty for a source whose files are not recorded), ranks and name_classes ({rank: nodes}, {class: names}, most first). name_from and name_to are the ids of the taxonomy's names in the file, an internal detail.
Records¶
A node travels as [id, parent, rank, name, attrs]: parent is null for a root, attrs an
object (taxonomy specific: for NCBI division, genetic_code, specified_species, ...) or null.
Unknown ids are left out of every answer; an id that was merged or renamed answers with the current
node, under the id you asked for.
| Endpoint | Request | Answer |
|---|---|---|
nodes |
{"ids": [...]} |
{"nodes": {id: record}} |
ancestors |
{"ids": [...], "attrs": true} |
{"lineages": {id: [id, ...root first]}, "nodes": {id: record}}: every node once, since lineages share most of theirs. "attrs": false leaves the records' attrs out (null); clients send it when they only need ids, as for a consensus (about 5 times smaller on NCBI) |
children |
{"ids": [...]} |
{"children": {id: [record]}}; ids without children are left out |
names |
{"ids": [...]} |
{"names": {id: [[name, class], ...]}}; the node's own name first, class "name" |
search |
{"text": "escherichia c", "rank": null, "match": "prefix", "limit": 10, "classes": null, "within": null} |
{"hits": [[id, parent, rank, name, attrs, matched name, name class], ...]}: a record followed by the name that matched and its class; best first, one hit per node. What matches and how it is ranked is in the Python guide; within is the id of a node (the answer is its subtree, itself included; a merged id is followed to the current node; an id that is not a node is a 400), classes is a list of name classes to look in (null or an empty list: all for "exact", all but authority otherwise), limit is 1 to 100 (more is a 400, not cut), text is at most 200 characters (the only string with a limit), empty text gives no hits. A rank or class the taxonomy does not have, and fuzzy search on a taxonomy saved without its index, are a 400. These rules are those of the store the server wraps (SqliteStore.search), so a client gets the same answer or the same error (a ValueError) from a file and from a server |
by_name |
{"texts": ["Homo sapiens", ...]} |
{"hits": {text: [[id, parent, rank, name, attrs, matched name, name class], ...]}}: for each text the nodes it names exactly (any class; compared as in search), each once, best first; texts that name nothing are left out. What search with "match": "exact" finds, for many texts at once |
links |
{"kind": "genome", "bases": ["GCF_000005845"], "attrs": true} ("attrs": false leaves the attributes out) |
{"links": {base: [[key, node id, name or null, source, kind, attrs or null], ...]}}: a base is a key without its version (genome: upper case, no RS_/GB_) or region (seq); the answer lists every stored version or region and source of it, among the sources of that kind; unknown bases are left out. Choosing among them is the client's job (see the design) |
meta answers the tables of the taxonomy (NCBI: divisions, genetic_codes; {} for others).
Export¶
GET /{taxonomy}/rows/nodes, names, aliases or links stream one JSON value per line: node
records, [node, name, class], [old id, new id or null] and [key, node, name or null, source, kind, attrs or null];
GET /{taxonomy}/rank/{rank} the node records of one rank (URL-encode a rank with a space) and
GET /{taxonomy}/subtree?id=ID a node and everything below it, in pre-order: node records with a last element, whether the node is a leaf.
They are what Taxon.descendants and leaves, Taxonomy.subset, prune, apply, stats, write and save need when the taxonomy is remote.
--no-export answers 403 to rows, rank and subtree (not to links_under).
The status of a stream is sent with its first chunk: a file that cannot be read when it starts is a 503 as for any request; if it fails later, the
response just ends (a client that reads to the end of a line-based stream and counts lines will notice nothing, so a client that must not get half an
export should check the count it expects, e.g. nodes in GET /taxonomies).
Errors¶
| Status | When |
|---|---|
400 |
bad input: a body that is not a JSON object, a missing or malformed field, an empty or oversized list, a search the store refuses (limit not from 1 to 100, text over 200 characters, an unknown match, rank, class or within, fuzzy search without an index) |
403 |
rows, rank and subtree with --no-export |
404 |
an unknown path or taxonomy (also one that the file had a moment ago) |
405 |
the wrong method |
413 |
a body over 1 MiB |
500 |
a bug: {"error": "internal server error"}, and the traceback in the server's log |
503 |
the file cannot be read now: it is locked by another connection for more than 20 seconds (a file of omnitax is in WAL mode, which does not happen to a reader), it is missing, it was replaced while the request ran, or it is not an omnitax file of this version, or SQLite reports another error reading it (the message is SQLite's, with the path). The message says which; Retry-After: 5; the Python client retries it (retries=) |
429, 503 |
also what a reverse proxy that limits requests sends; the Python client retries them (retries=, after Retry-After) |
The Python client raises ClientError for every status of 400 or more, with the status in status_code; a 400 is a BadRequest, which is also a
ValueError, and a 404 a NotFound, which is also a KeyError, as a store reading the file raises them.
There is no authentication and no rate limit in the server; see running it publicly.