Reference Data — Catalog & API Design

In plain English

We have 16 free datasets that describe the world — countries, currencies, languages, airports, cities, shipping ports, map shapes, and a lookup from internet address to location — plus a postal-code layer: a single lookup from a postal code to its place, administrative divisions, and coordinates, covering ~248 countries. Today we hand all of these out as separate spreadsheets, and anyone who wants to combine them (say, "what currency is used at this airport?" or "what region is postal code AD100 in?") has to open several files and match rows by hand — tedious, and often broken because the files spell the same country differently. The insight is that these files aren't really separate: they're one connected web of information, linked mostly by a country's code. So instead of selling spreadsheets, we do the messy matching once and offer a single, clean way to ask questions — four simple ones: look up a thing (resolve), translate a mystery code (crosswalk), find where a clue points — an internet address or a postal code — (locate), and search by name. The core reference data stays free; the postal layer is partly free and partly premium (69 of the 248 are gated — how we charge for those is a separate, still-open decision, not settled here). What we sell is the convenience, reliability, and freshness of not having to stitch it together yourself. This document lays out what data we have (Part 1) and the shape of that API (Part 2).


This document has two parts:

  1. The data — how the datasets connect: the shared keys that stitch them into one graph.
  2. The REST API — the proposed menu of endpoints layered on top of that data.

The one big idea: these datasets look separate but they're really one graph. A handful of shared keys (mostly the country code, plus geonameid for places) stitch them together. The API's job is to do that stitching once, for everyone. The postal-code layer slots onto the same spine — every row carries its ISO 3166 country code, so it attaches to the country graph as cleanly as anything in the bundle. (Internally it's sourced country-by-country, but that's an implementation detail callers never see: to them it's one postal-code capability.)


Part 1 — The Data

How it all connects (read this first)

Two "spines" hold everything together:

  • Country code (ISO 3166) — the main spine. Almost every file references a country. The same country appears as FR, FRA, 250, and half a dozen other code systems. country-codes is the master translation table that maps all of them to each other.
  • geonameid — a stable numeric id (from GeoNames.org), but ⚠️ it appears at two different hierarchy levels that do NOT share values. country-codes.Geoname ID and geoip2.geoname_id are country-level ids (249/249 match — a real join). world-cities.geonameid is city-level and shares zero ids with the country pair, so it links to the country graph only by name text — not by id. population-city has no geonameid at all and joins by (country name, city name) text, so it's the weakest-linked file in the bundle.

How to read the map below: a solid arrow is a clean id join (a real foreign key — always works); a dotted arrow is a weak name/text join that silently drops rows. Each boxed group is a cluster whose members don't share ids with the rest of the graph across the box boundary — that's the "two separate geonameid spines" problem made visual.

(The airport-codes ⇄ un-locode link by IATA is deliberately absent — measured at 0.6% fill, it's effectively no join. The orphan lists connect to nothing by design.)

The tricky bit: some files join cleanly by code (airport → country), but others join by name — e.g. world-cities says country = "Åland Islands" as text, not AX. Names are messy ("Åland Islands" vs "ÅLAND ISLANDS"), so normalising those weak links is the real work the API hides.


Quick reference: the join keys

To connect…Use this keyNotes
Any country file → any otherISO 3166 codecountry-codes translates between systems
Country → currencyISO 4217 currency code (EUR/978)✅ clean; country-codes already carries the currency inline too
Country → languagesIETF tag → language-codese.g. fr-FR → fr
Country → its shapeISO alpha-3geo-countries
Country → subdivisionsISO 3166-2⚠️ partial — airport & un-locode use different levels (FR regions vs departments); only 89% align
geo-IP ↔ countrycountry-level geonameid✅ clean: geoip2 ⇄ country-codes, 249/249
City ↔ country⚠️ name text onlyworld-cities' city geonameid does NOT match geoip2/country-codes ids
City → populationcountry name + city name⚠️ weakest link — population-city has no geonameid
Airport ↔ portshared IATA code⚠️ unreliable — un-locode's IATA field is filled only 0.6% of the time
IP → countryCIDR range matchgeoip2-ipv4
Postal code → countryISO 3166 alpha-2 (country_code)✅ clean — every postal row carries it
Postal code → subdivisionadmin_code1/2/3⚠️ GeoNames admin codes; ISO 3166-2 for some countries, FIPS/internal for others — same two-camps curation
Postal code → cityplace_name (+ lat/lon)⚠️ name/geo only; no geonameid in the GeoNames zip export
container-types, dac codes(none)standalone lists

Join reliability — where the bundle is solid vs. taped together

Not all joins are equal. Some are real foreign keys (match on a shared id, always works); others are text matches that silently drop rows. This is the honest map — and the weak joins are exactly the toil a paid API exists to absorb. All numbers below were measured against the actual files.

Solid — ID-based joins (the backbone)

JoinKeyEvidence
Any country code ⇄ any otherISO 3166 codes in country-codes249 rows, 0 blank geonameids; every code system present
Country → currencyISO 4217 code (EUR/978)clean; only 4 blanks (countries with genuinely no currency)
geo-IP ⇄ countrycountry-level geonameidgeoip2-ipv4 (252 ids) ⇄ country-codes (249) — 249/249 match; geoip2 here is country-only
Country ← airport / UN-LOCODEISO alpha-2 (iso_country, Country)the country link is clean for both
Country ← postal-codesISO alpha-2 (country_code)every postal row carries its alpha-2 — clean by construction (~248 countries covered)

Weak — name/text joins (ranked by how much they bite)

1. world-cities ↔ population-city — the weakest link. No shared id at all; the only bridge is (country name, city name) text. Measured: only 58% of population-city city pairs find an exact match in world-cities — 42% miss, even after lowercasing. Two causes: city names are UPPERCASE in population-city (MARIEHAMN) vs mixed-case in world-cities; and ~21 country names diverge because population-city uses UN long-form (Bolivia (Plurinational State of), United Kingdom of Great Britain and Northern Ireland, China, Hong Kong SAR, Republic of Korea, Reunion…). Net: population cannot be reliably attached to a geonameid without a curation/fuzzy-match layer.

2. Country → languages — locale strings, not codes. country-codes.Languages holds IETF locale tags (fa-AF, ar-eg, fr-FR, sv-AX), not clean 639 codes. Measured over 726 tags: 48% match language-codes.csv as-is; 81% after stripping the -REGION suffix; the rest (dialect codes like frp) never resolve. So expand=languages is a parse-and-normalize step, not a lookup.

3. world-cities city geonameid is isolated — and airport / UN-LOCODE carry no geonameid at all. world-cities.geonameid is city-level and shares 0 ids with the country-level geonameid in geoip2/country-codes (measured: world-cities ∩ country-codes = 0). So a city can only be tied to its country by the free-text country field, not by id. Airport→city is only municipality (free text); UN-LOCODE→city is only Name + coordinates. "Which city is this airport/port in?" is a name/geo guess, not an id join.

4. Subdivisions live in two incompatible "camps" of the ISO 3166-2 hierarchy. All three subdivision-bearing files use valid ISO 3166-2 codes, but at different administrative levels, so string joins silently fail:

FileFrance encodingLevel
un-locode subdivision-codesFR-01, FR-02…departments
geo-ne-admin1FR-01, FR-02…departments
airport-codes iso_regionFR-ARA, FR-OCC…regions

Measured code-level overlap: geo-ne ∩ un-locode = 86% (same camp), but geo-ne ∩ airport = 55% — airport-codes is the outlier. Row-level, airport iso_region matches un-locode in 89.2% of rows (inflated by the US, where both use states), but the gap is systematic (France, UK, Italy, China, Spain) plus 13 countries (Hong Kong, Macao, Réunion, Kosovo…) absent from un-locode's list entirely. Reconciling the two levels is real curation work, not a config fix.

Bright spot — geo-ne-admin1 is the strongest subdivision anchor. Its iso_3166_2 is 100% filled (4,596 rows) and it carries gn_id (geonameid, 97% filled) plus code_hasc, fips, wikidataid. So it can serve as the subdivision crosswalk between the two camps and is the one file that links subdivisions into the geonameid places spine — worth making the canonical subdivision source.

5. Airport ⇄ port (shared IATA) — effectively no join. The doc originally proposed linking airport-codes to un-locode by IATA code. Measured against the files: un-locode's IATA column is filled in only 0.6% of 116,213 rows (3.8% even among airport-flagged rows), and just 383 rows carry an IATA that matches a real airport. The tempting fallback — treat the 3-letter Location code as an IATA — looks like a 61.8% hit but is a mirage: random 3-letter codes collide with some real IATA ~51% of the time by chance, so 61.8% is barely above noise, and FRPAR (Paris the metro trade point) is not the airport CDG. Treat this join as non-existent; don't expose expand=airport on /locodes.

6. Postal codes join up cleanly but down weakly. The postal layer's country link is the strongest in the bundle — every row carries an ISO 3166 alpha-2 country_code (it's sourced per country under the hood, but that never surfaces to a caller). But its two sub-country links inherit — don't escape — the same problems as the rest of the graph. admin_code1/2/3 are GeoNames admin codes: for some countries they are the ISO 3166-2 code (Andorra's admin_code1="02" = AD-02 Canillo), but for others they're FIPS-derived or GeoNames-internal, so the same two-camps reconciliation as airport.iso_region vs un-locode applies before admin_code1 can be trusted as a subdivision key. And the GeoNames zip export the producer reads carries no geonameid, so a postal row ties to a city only by place_name + lat/lon — the same name/geo guess as world-cities, never an id join. Net: expand=subdivision and expand=city on postal codes are best-effort with documented coverage; expand=country is exact. The reverse direction is where postal codes add something the current bundle lacks: postal_code (+ country) → place, and lat/lon → nearest postal code — the first "below country, from a code people actually hold" path in the graph.

Structural warts (not joins, but they bite ingestion)

  • population-city is two tables in one CSV — the real data plus a 246-row footnote block appended at the bottom (where "Country or Area" holds a footnote number 1–246). A naive read yields garbage rows. It's also gender-split (Male/Female), multi-year, and multi-Record Type, so it needs aggregation, not a straight read.

Orphans (no join by design — not a defect)

iso-container-codes, dac-and-crs-code-lists are flat code lists; continent-codes is tiny. Correct to expose as flat endpoints with no expand into the country graph.

Product implication: resolve and crosswalk (ID-clean) are the reliable headline. Population and language should be best-effort expands with documented coverage — either invest curation to lift the 58% city-match rate, or scope the docs to be honest about it. Åland Islands is the poster child: is_independent="Part of FI", empty IOC, sv-AX locale, and MARIEHAMN joinable only by uppercased name.


Part 2 — The REST API

A small, cached REST API that does the stitching above so callers never touch raw files. Four question-shapes: resolve (look up a thing), crosswalk (translate a mystery code), locate (a clue → a place: an IP or a postal code), search (a typed name → a pick-list) — plus bulk file downloads and meta endpoints.

Conventions

Base URL:   https://api.datahub.io/reference/v1
Auth:       header  Authorization: Key <your-key>
Format:     JSON default · ?format=csv|parquet on list/snapshot endpoints
Expand:     ?expand=a,b  embeds related entities (comma-separated, dotted paths ok)
Paging:     ?limit= &cursor=   on any list
Versioning: ?version=2024-06 (pin) · default = latest · every response carries an ETag

1. resolve — look up one thing by id

GET /countries                      list all ~250 countries
GET /countries/{id}                 id = any code system: FR, FRA, 250 → same country
      ?expand=currency,languages,continent,capital,subdivisions,geometry

GET /countries/{id}/subdivisions    ISO 3166-2 regions of a country
GET /countries/{id}/cities          cities whose (name-normalised) country = id — see /cities
GET /countries/{id}/postal-codes    the country's postal-code file — see /postal-codes
GET /countries/{id}/geometry        the border polygon (from geo-countries; 236/258 shapes
                                    carry an ISO code — 22 small territories are code-less)

GET /subdivisions/{id}              e.g. FR-IDF (Île-de-France)
      ?expand=country,geometry               geometry from geo-ne-admin1 / NUTS

GET /currencies                     ISO 4217 — dedup to current (source has 449 rows / 307 codes;
GET /currencies/{id}                the extras are withdrawn currencies w/ WithdrawalDate)
      ?expand=countries               EUR / 978 → Euro (minor_unit: 2, note JPY = 0)

GET /languages                      ISO 639 / IETF
GET /languages/{id}                 fr / fra / "French"

GET /continents                     the 7
GET /continents/{id}/countries      everything in Europe

GET /airports                       filterable: ?country=FR&type=large_airport
GET /airports/{id}                  primary key = ident; IATA covers only 10.6% of rows,
      ?expand=country,country.currency,subdivision   ICAO 11.8% — so CDG/LFPG resolve, most don't

GET /cities                         filterable: ?country=FR&q=par&subdivision=Île-de-France
GET /cities/{geonameid}             2988507 = Paris (from world-cities: name, subcountry, country)
      ?expand=country,population              ⚠️ EXPANDS ARE BEST-EFFORT, NOT ID JOINS:
                                              • the /cities LIST itself is clean (world-cities alone:
                                                34,128 rows, geonameid 100% filled) — reliable
                                              • expand=country resolves by NAME text → country-codes,
                                                not by id (city geonameid shares 0 ids w/ country graph)
                                              • expand=population is name-matched to population-city,
                                                ~58% coverage, documented per-city
GET /places/{geonameid}             alias of /cities/{geonameid} — the geonameid-first spelling
                                    for callers who already hold a GeoNames id

GET /locodes/{id}                   UN/LOCODE, e.g. FRPAR (Paris as a trade point)
      ?expand=country,subdivision             (no airport expand — IATA link is ~0.6% populated)

GET /postal-codes                   one endpoint, all countries: ?country=AD&q=canillo
                                    (country is required — postal codes aren't globally unique,
                                    so AD100 must be scoped to a country to resolve)
GET /postal-codes/{country}/{code}  e.g. AD/AD100 → Canillo, parish Canillo, 42.58,1.67
      ?expand=country,subdivision,city         • expand=country resolves by country_code → EXACT
                                              • expand=subdivision maps admin_code1/2/3 → best-effort
                                                (GeoNames codes; two-camps caveat)
                                              • expand=city is name/geo-matched (no geonameid) → best-effort
                                    ⚠️ some countries are PREMIUM/gated — free countries return
                                       full data; gated ones return a sample + purchase link until the
                                       pricing/entitlement model is decided (see Part 1; deferred)

GET /container-types                 flat orphan list (ISO 6346)
GET /container-types/{id}            22G1 → Standard Dry, 20ft

GET /aid/agencies                    DAC/CRS orphan lists — one sub-resource per file
GET /aid/channels                    (agencies, channel-codes, aid-types, flow-types…)
GET /aid/{list}/{code}

The orphan lists (container-types, aid/*) live at the top level with no fake expand into the country graph — they genuinely don't connect.

2. crosswalk — mystery code in, everything out

GET /resolve?code=ALD               "ALD is a FIFA code → Åland Islands", returns ALL codes
      ?type=country                  optional hint if a value collides
{ "you_gave": {"value":"ALD","system":"FIFA"},
  "resolved": {"type":"country","id":"AX"},
  "all_codes": {"alpha2":"AX","alpha3":"ALA","numeric":"248","fifa":"ALD","ioc":null} }

3. locate — a location clue → a place

GET /locate?ip=1.178.90.5           → chain: Europe → France   (from geoip2-ipv4)
      ⚠️ IP resolves to COUNTRY only — this is the country-level GeoLite2 file (252 country
         geoname_ids, no city/subdivision columns); it cannot return a city.
GET /locate?lat=48.85&lon=2.35      → point-in-polygon: which country/subdivision contains it
      ?level=country|subdivision     lat/lon is a path below country level
GET /locate?postal_code=AD100&country=AD
      → chain: Andorra → parish Canillo → Canillo (from the postal-codes layer)
      country is required (postal codes are not globally unique); returns place + admin
      divisions + coordinates. Gated for the 69 premium countries (see /postal-codes).

Returns big→small, and resolves partially (code + name only) if the place isn't fully in the graph, instead of erroring.

4. search — typed name → pick-list

GET /search?q=paris                 across all types: 2 cities + CDG airport, each typed
      ?type=city,airport             restrict the types
      ?country=FR                    filter
{ "count": 3, "results": [
  {"type":"place","id":"2988507","label":"Paris","meta":"Île-de-France, France"},
  {"type":"place","id":"4717560","label":"Paris","meta":"Texas, United States"},
  {"type":"airport","id":"CDG","label":"Charles de Gaulle Intl","meta":"Paris (CDG)"} ]}

5. Bulk / sync — the "give me the whole file" crowd (Power BI, curl, ADF)

GET /snapshots                              list downloadable datasets + versions
GET /snapshots/{dataset}                    whole file: ?format=csv|json|parquet
      e.g. /snapshots/country-codes.parquet
      e.g. /snapshots/postal-codes?country=ad  postal codes download per country (they're
                                              scoped by country anyway — grab just what you need)
      → strong ETag; a full download counts as ONE call
      → premium countries are gated here too: sample vs full bundle,
        entitlement TBD (see Part 1; deferred)

GET /snapshots/{dataset}/versions           version history for pinning
GET /changes?since=2024-06-01               diffs across datasets — the "freshness" product
      ?dataset=un-locode                    scope to one

6. Meta — plumbing

GET /                                self-describing index of all endpoints
GET /health                          status (backs the SLA / status-page promise)
GET /datasets                        catalogue: each source, its license, update cadence
GET /usage                           your key's calls this period (for the dashboard)

The shape at a glance

  • Nouns (/countries, /cities, /airports, /currencies, /postal-codes…) → the resolve layer, richness via ?expand= (city & postal sub-country expands are best-effort, not id joins)
  • Verbs (/resolve, /locate, /search) → the "I don't have a clean id" cases (/locate now takes an IP or a postal code)
  • Files (/snapshots, /changes) → the bulk/sync money-maker
  • Meta (/, /health, /datasets, /usage) → what makes it a product, not just data