Add raw output format to the API#17
Open
roed-math wants to merge 2 commits into
Open
Conversation
_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>
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. Stayed within this PR's hunks — no overlap with #18/#22/#40 regions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds
_format=rawto 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 thatreadveccan read directly (verified in gp); requesting raw output without_fieldsgives a 400 error. The format is documented on the API index page, table pages link to it whenever_fieldsis present, andtest_api.pygains exact-output tests including the error case. Addresses LMFDB#1010.🤖 Generated with Claude Code