DataHub datapackage
DataHub datapackage
What DataHub reads from a dataset's datapackage.json / datapackage.yaml / datapackage.yml, and how it renders the dataset page from it.
The base is a standard Frictionless Data Package. DataHub adds a few custom properties on top. The spec allows custom properties, and generic Frictionless tools ignore them, so a DataHub datapackage stays a valid data package.
Most datasets need none of this beyond the standard spec: list your resources and the page previews and offers each one for download. Read on if a dataset needs either of these:
- a public sample that stands in for a larger full dataset, or
- a premium (paid or request-only) full version.
Those datasets use the full + sample shape below. It was introduced for the postal-codes datasets (datopian/postal-codes docs/single-source-of-truth.md, on a feature branch until it merges), but it isn't specific to them. Any dataset that needs a sample or a premium version should use it.
Implementation: lib/dataset-shape.ts (shape and primary action), lib/dataset-lookup.ts (server-side premium lookup), components/layouts/datapackage.tsx (the page), and the types in types.ts.
Two shapes
The renderer picks the shape by looking for a resource whose name equals the package name.
| Shape | When | What the page does |
|---|---|---|
| Generic | no resource is named after the package | Previews and offers every resource. The header sums their sizes. The dataset is never premium, even if a resource says premium: true. |
| Full + sample | a resource's name equals the package name | That resource is the full resource. A resource named <name>-sample is the sample. See below. |
Resources are always found by name, never by position, so their order in the file doesn't matter.
The full + sample shape
package name: my-dataset
resources: my-dataset ← full (always)
my-dataset-sample ← sample (premium only)
- Full resource (
name= packagename). It describes the complete data and carries its true stats (bytes,rows,modified). The page header always takes size, row count and last-updated from it. When the dataset is premium it also carries the premium flags, and itspathis a landing page instead of a data file. - Sample resource (
<name>-sample). A small public extract that the page previews and offers as "Download sample". It exists if and only if the full resource is premium.
Don't add other resources in this shape: the page ignores them. Don't give a free dataset a sample either. The page previews and offers the sample whenever there is one, so a free dataset with a sample would hide its full data.
States
A dataset in this shape is in exactly one of four states. The page's primary action is chosen top to bottom: the first matching row wins.
| # | State | How it's declared | Page shows |
|---|---|---|---|
| 1 | No data | top-level data_available: false. Full resource is a header-only file with rows: 0. No sample. | "Coming soon" badge, a "Request this data" card, and the full resource's schema as the columns to come. No preview or downloads. |
| 2 | Free | full resource without premium: true. Its path is the public data file. No sample. | Preview and "Download" of the full resource. |
| 3 | Premium, priced | full resource has premium: true, a valid premium_tier and premium_source_key. A sample resource exists. | Sample preview, "Download sample", and a price card with "Buy full dataset" at the tier's price. |
| 4 | Premium, not priced | full resource has premium: true and neither premium_tier nor premium_source_key. A sample resource exists. | Sample preview, "Download sample", and a "Get full dataset" request card. |
A priced dataset falls back to the "Get full dataset" request card when its price can't be resolved at runtime, for example when the tier's Stripe price env var isn't set. A tier without a source key, a source key without a tier, or an unknown tier also counts as not priced. Nothing reaches checkout half-configured.
On premium datasets the "Explore with AI" button and the /explore route are disabled, because only the sample is public.
Fail-safe
A premium dataset with an invalid shape renders an error message in place of the preview and downloads. It never falls back to showing the data. These count as invalid:
premium: truebut no<name>-sampleresource.premium: trueand the full resource'spathlooks like data: a repo-relative path, or a URL whose last segment has a file extension (.csv,.zip, …). The fullpathof a premium dataset must be a page, typically the dataset's own DataHub URL.
Property reference
Package level
| Property | Type | Meaning |
|---|---|---|
data_available | boolean | Default true. false means we don't have the data yet: state 1 above. Only an explicit false counts. |
premium_description | string | Optional copy for the price card, describing what the full version contains. |
collection | string | Collection name. The page links to /collections/<collection>. |
has_solutions | string[] | Data Solution slugs the dataset belongs to. Each gets a badge in the page header and a row in the data solutions band linking to /solutions/<slug> (see lib/solutions.ts). |
views | object[] | Chart/table views rendered above the data files. |
Premium flags at the package level (is_premium, premium_tier, premium_source_key) are no longer read. They now go on the full resource.
Resource level
| Property | Type | Meaning |
|---|---|---|
rows | integer | Row count of the data this resource describes. Shown in the header (full resource) and the file's info card. Preferred over the in-browser count, which only sees the previewed file. |
modified | string (date) | When the data last changed. Shown as "Updated" in the header (full resource) and on the info card. |
bytes | integer | Standard Frictionless. Size of the data this resource describes. Shown as the header size (full resource). |
premium | boolean | Full resource only. true makes the dataset premium: its path becomes a landing page and a sample resource is required. Only a real true counts. |
premium_tier | "A" "B" "C" | Full resource only, with premium: true. The price tier. Each tier maps to one shared Stripe price via STRIPE_PRICE_TIER_A/B/C (see lib/premium-tiers.ts). |
premium_source_key | string | Full resource only, with premium: true. Key of the full file (usually a zip) in the private premium bucket. Read server-side only, and never turned into a URL in the browser. Set together with premium_tier or not at all. |
sample | string | An optional lighter file to preview instead of path, when the file at path is public but large. The download still uses path. It's not the premium mechanism: for a gated full version, use the full + sample shape. |
When the full resource has no bytes, rows or modified, the header leaves that stat out rather than showing 0 or the sample's value. This is the case for a premium dataset whose full data isn't held in the repo.
Examples
Postal codes use YAML. The &schema / *schema anchor writes the schema once and reuses it on the sample. DataHub's YAML parser expands the anchor, so both resources end up with the same schema. In JSON, repeat the schema instead.
Free
name: postal-codes-ad
title: Postal Codes Dataset for Andorra, AD
resources:
- name: postal-codes-ad
path: https://postal.datahub.io/ad/ad.csv
format: csv
bytes: 599
rows: 7
modified: "2026-10-02"
schema: { fields: [...] }
Premium, priced
name: postal-codes-de
title: Postal Codes Dataset for Germany, DE
resources:
- name: postal-codes-de
path: https://datahub.io/logistics/postal-codes-de # landing page, not data
format: csv
premium: true
premium_tier: C
premium_source_key: de/de.zip # private premium bucket
bytes: 2375854 # stats of the FULL data
rows: 23297
modified: "2026-10-06"
schema: &schema
fields: [...]
- name: postal-codes-de-sample
path: https://postal.datahub.io/de/de.csv # public, ≤100 rows
format: csv
bytes: 13730
rows: 100
modified: "2026-10-06"
schema: *schema
Premium, not priced
Like the priced example, but the full resource has premium: true with no premium_tier and no premium_source_key. It also usually has no stats, so the header omits them.
No data
name: postal-codes-aq
data_available: false
resources:
- name: postal-codes-aq
path: https://postal.datahub.io/aq/aq.csv # header-only
format: csv
rows: 0
schema: { fields: [...] }
Selling a dataset
- Upload the full file. Put the zip in the private premium bucket. Its key becomes
premium_source_key. - Upload the sample. Put it somewhere public, and point the sample resource's
pathat it. - Edit the full resource. Set
premium: true,premium_tier,premium_source_key, and a landing-pagepath. Keep the full data's truebytes/rows/modifiedon it. - Publish.
The Buy button then appears with the tier's price. The flow from there:
- Checkout. It resolves tier, price and source key server-side from the synced datapackage. Nothing the browser sends is trusted.
- Payment. The Stripe webhook re-resolves them and rejects the payment if the price or source key changed in between.
- Delivery. The buyer gets a perpetual re-download link that presigns the source key recorded at purchase. So never delete or move an object in the premium bucket that has already been sold. Upload a new key instead.