Skip to content

Add raw output format to the API#17

Open
roed-math wants to merge 2 commits into
mainfrom
ai/t17-api-raw-format
Open

Add raw output format to the API#17
roed-math wants to merge 2 commits into
mainfrom
ai/t17-api-raw-format

Conversation

@roed-math

Copy link
Copy Markdown
Owner

This adds _format=raw to the API (alongside html/json/yaml), returning only the contents of the columns requested via _fields — one record per line, with no ids or metadata wrapper, as requested by Bill Allombert for consumption from PARI/GP scripts. Values are JSON-encoded and multiple fields are joined by _delim, so a single-field response consists of valid GP expressions that readvec can read directly (verified in gp); requesting raw output without _fields gives a 400 error. The format is documented on the API index page, table pages link to it whenever _fields is present, and test_api.py gains exact-output tests including the error case. Addresses LMFDB#1010.

🤖 Generated with Claude Code

roed314 and others added 2 commits July 19, 2026 01:45
_format=raw returns just the contents of the columns requested via
_fields, one record per line with no ids or metadata wrapper, so that
scripts (in particular PARI/GP, the original request) can consume query
results directly.  Values are JSON-encoded, making each single-field
line a valid GP expression readable with readvec; multiple fields are
joined by _delim.  Requesting raw without _fields gives a 400 error.
Documented on the API index page and linked from table pages when
_fields is present.

Verified with a new test_api_raw in lmfdb/api/test_api.py (all 7 API
tests pass against devmirror) and by reading saved raw responses back
into sage --gp with readvec/readstr.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…DB#1010)

The raw format previously joined individually-JSON-encoded fields with the
query delimiter, producing lines like `[0,-1,1,-10,-20],11` where commas
appear both inside and between fields: not valid JSON, not a single GP
expression, and unparseable when a string value contains the delimiter.

Multiple fields are now emitted as one JSON array per line (JSON Lines), so
every record is self-delimiting and round-trips through json.loads even when a
value contains the delimiter. Single-field output is unchanged (one JSON value
per line), preserving the PARI/GP readvec round-trip; the docs now scope the
GP-compatibility claim to the single-field case. Tests add json.loads
round-trips and a delimiter-in-value case; the single-field GP round-trip was
re-verified in sage --gp.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@roed-math

Copy link
Copy Markdown
Owner Author

Addressed the external review's P2 finding (multi-field raw records not parseable): commit fa953ee makes multi-field raw output emit one JSON array per line (JSON Lines), so each record is self-delimiting regardless of delimiters inside values; single-field output is unchanged. _delim now only splits the _fields/_sort inputs, never joins output. The API docs bullet specifies the format exactly and scopes the PARI/GP readvec claim to the single-field case (re-verified in sage --gp). Tests now round-trip records via json.loads, including a delimiter-inside-value case.

Stayed within this PR's hunks — no overlap with #18/#22/#40 regions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants