Skip to content

feat(dump): download a resource's data dictionary and metadata - #32

Merged
luccasmmg merged 1 commit into
mainfrom
feat/download-dictionary-metadata
Oct 26, 2026
Merged

luccasmmg merged 1 commit into
mainfrom
feat/download-dictionary-metadata

Conversation

@luccasmmg

Copy link
Copy Markdown
Member

Implements datopian/neso-nextgen-shared#42 (CH15: download the data dictionary, plus the dataset/resource metadata requested in the comments).

New endpoints

Both need read on the resource, take ?format=csv|json (default csv) and return the file directly (200, Content-Disposition named like the table dump, e.g. <name>_data_dictionary.csv / <name>_metadata.json). They're small, so they're built in memory. There's no export or redirect.

GET /datastore/api/v2/dump/{resource_id}/dictionary

  • json: the Frictionless Table Schema, exactly as datastore_info returns it.
  • csv: one row per column, with name, type, title, description first and then every other property. Nested values (e.g. constraints) are compact JSON in their cell.

GET /datastore/api/v2/dump/{resource_id}/metadata (AUTH_TYPE=ckan only)

The fields from the issue. The dataset is read via a new CKANClient.package_show rather than the cached datastore_authorize payload.

Field Source
Data group organization.title
Resource last updated metadata_modified, else last_modified (same as the portal shows)
Download URL this service's dump/{resource_id} URL
Total record count engine row count; empty if the resource has no table
Temporal coverage from / to temporal_coverage split on /

CSV is a header row plus one value row, with tags comma-joined. JSON is one object with the same labels as keys.

Other changes

  • _dump_url moved from services/write.py to core/helper.dump_url, so the Download URL matches the url that datastore_create writes to CKAN.
  • Removed a leftover print(response.status_code) in CKANClient._unwrap.
  • Analytics records these downloads as datastore_dump_dictionary / datastore_dump_metadata.
  • API.md / CLAUDE.md updated.

Testing

  • pytest: 568 passed (26 new in tests/test_datastore_dump_documents.py).
  • Manually against the local stack (real CKAN + BigQuery): all four format combinations return 200 with the expected headers and content. An invalid format returns a 400 Validation Error.

Add two file downloads next to the table dump, each `?format=csv|json`:

- `dump/{resource_id}/dictionary` — the resource's Frictionless schema
  (as `datastore_info` returns it). CSV is one row per column, one column
  per field property; nested values are written as JSON in the cell.
- `dump/{resource_id}/metadata` — the resource's and its dataset's
  metadata (datopian/neso-nextgen-shared#42). The dataset is read with a
  new `CKANClient.package_show`; data group is the organization title,
  "last updated" matches the portal (`metadata_modified`, else
  `last_modified`), and the record count comes from the engine. CSV is a
  header row plus one value row. Requires AUTH_TYPE=ckan.

`dump_url` moves to core/helper so the metadata's Download URL matches
the `url` datastore_create writes. Also drops a stray debug print of
every CKAN response status.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 45e2e5a9-1937-4b8f-883d-d9d73b88f422
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@luccasmmg
luccasmmg merged commit 34a7370 into main Oct 26, 2026
2 checks passed
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.

1 participant