survos / geonames-bundle
Symfony bundle for fetching packaged GeoNames authority databases.
Package info
github.com/survos/geonames-bundle
Type:symfony-bundle
pkg:composer/survos/geonames-bundle
Fund package maintenance!
Requires
- php: ^8.5
- survos/fetch-bundle: ^2.5
- survos/jsonl-bundle: ^2.5
- symfony/config: ^8.1
- symfony/console: ^8.1
- symfony/dependency-injection: ^8.1
- symfony/dotenv: ^8.1
- symfony/filesystem: ^8.1
- symfony/http-client: ^8.1
- symfony/http-kernel: ^8.1
- zenstruck/bytes: ^1.1
Requires (Dev)
- phpunit/phpunit: ^13.0
- symfony/framework-bundle: ^8.1
- symfony/phpunit-bridge: ^8.1
Suggests
- ext-pdo_duckdb: ^2.0: read and build .duckdb files, much faster than SQLite for lookups
- survos/duckdb-bundle: Read .duckdb files directly from S3 (s3:// duckdb_uri)
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 2.45.80
- 2.45.76
- 2.45.74
- 2.45.73
- 2.41.9
- 2.33.0
- 2.19.1
- 2.18.11
- 2.15.11
- 2.15.8
- 2.15.2
- 2.10.19
- 2.10.18
- 2.10.17
- 2.10.16
- 2.10.15
- 2.10.14
- 2.10.13
- 2.10.12
- 2.10.11
- 2.10.10
- 2.10.9
- 2.10.8
- 2.10.7
- 2.10.6
- 2.10.5
- 2.10.4
- 2.10.3
- 2.10.2
- 2.10.1
- 2.10.0
- 2.9.4
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.4
- 2.8.3
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.23
- 2.7.22
- 2.7.21
- 2.7.20
- 2.7.19
- 2.7.18
- 2.7.17
- 2.7.16
- 2.7.15
- 2.7.14
- 2.7.13
- 2.7.12
- 2.7.11
- 2.7.10
- 2.7.9
- 2.7.8
- 2.7.7
- 2.7.6
- 2.7.5
- 2.7.4
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.0
- 2.5.8
- 2.5.7
- 2.5.6
- 2.5.5
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.0.220
- 2.0.219
- 2.0.218
- 2.0.217
- 2.0.216
- 2.0.215
- 2.0.214
- 2.0.213
- 2.0.212
- 2.0.211
- 2.0.210
- 2.0.209
- 2.0.208
- 2.0.207
- 2.0.206
- 2.0.205
- 2.0.204
- 2.0.203
- 2.0.202
- 2.0.201
- 2.0.200
- 2.0.199
- 2.0.198
- 2.0.197
- 2.0.196
This package is auto-updated.
Last update: 2026-11-20 17:30:40 UTC
README
survos/geonames-bundle is the GeoNames authority-list bundle for packaged SQLite place databases.
The runtime model is intentionally small:
- fetch a published authority database
- store it locally
- query it through a service such as
GeoService
Runtime Databases
Published databases:
geo.sqlitecontainscountry,admin1,admin2, and alias lookups for every country GeoNames covers<countryCode>.sqlite(e.g.us.sqlite,hu.sqlite) contains that country's cities (citytable), name-lookup aliases (aliastable), and locale-specific alternate names (alt_nametable — see below)
GeoNames provides the canonical ids, so the shared runtime base is geo.sqlite, with country-specific city databases layered on top.
Scope: what this bundle is not
GeoNames covers countries, administrative regions, and populated places (cities/towns) — it is not comprehensive for individual schools, stores, churches, or other points of interest, and this bundle doesn't try to make it one. For that layer, two companion bundles:
survos/place-map-bundle— a curated point/polygon library, one Nominatim query at a time.survos/poi-bundle— bulk/automated matching of a literal name (e.g. from a facet tag) against OSM features within a city this bundle already resolved.
See survos/mono#28 for how the split was decided.
Locale-specific alternate names (alt_name)
Each <countryCode>.sqlite also carries an alt_name table (geoname_id, iso_language,
alternate_name, is_preferred, is_short, is_colloquial, is_historic) sourced from GeoNames'
per-country alternatenames/<CC>.zip export — the real language-tagged data (German "Wien" vs.
French "Vienne" vs. English "Vienna" for the same geonameId), not the untagged alternatenames
convenience column already on city rows. Query it through:
$names = $this->geoService->alternateNames(3054643, 'HU'); // Budapest // ['de' => ['Budapest', 'Ofen-Pest'], 'ru' => ['Будапешт'], 'sk' => ['Budapešť'], ...]
Cities only for now — country/admin1/admin2 alt names in geo.sqlite aren't wired up yet (see
PLAN.md). Background: survos/mono#26.
DuckDB backend
DuckDB is the primary format. When ext-pdo_duckdb is loaded, GeoService reads <name>.duckdb files
instead of <name>.sqlite. Lookup order per database (geo, us, ...):
<data_dir>/<name>.duckdb: a local file, read-only. This is also the cache directory.<duckdb_uri>/<name>.duckdb: the source of truth. With anhttps://URI (the Hugging Face dataset), the file is downloaded intodata_diron first use and read locally from then on. Reading a remote file in place costs several round trips per lookup (Hugging Face took 0.3 to 0.75 s per range request), and every web request would pay that again. Setduckdb_cache: falseto read it in place anyway. Ans3://bucket/prefixURI is always read in place (needssurvos/duckdb-bundle).<data_dir>/<name>.sqlite(the legacy format, for apps without the extension, and the fallback if the download fails)
A cached file is never refreshed automatically: run bin/console survos:geo --force (or delete the file) to
fetch a new version. survos:geo fills the same directory, so deploys can warm the cache before the first request.
Concurrent workers download under a file lock (<name>.duckdb.lock).
survos_geonames: # a public Hugging Face dataset: no credentials, read with HTTP range requests (needs DuckDB's httpfs) duckdb_uri: 'https://huggingface.co/datasets/museado/geonames-duckdb/resolve/main' # or S3 (also needs survos/duckdb-bundle): # duckdb_uri: 's3://my-bucket/geonames-data' # duckdb_s3: { endpoint: 'https://s3.eu-central-1.amazonaws.com', region: eu-central-1, access_key: '%env(S3_KEY)%', secret_key: '%env(S3_SECRET)%' }
Install httpfs for the engine and the runtime user when you provision the host
(INSTALL httpfs); the bundle only runs LOAD httpfs.
How the files are built
admin.php build-duckdb reads the worldwide GeoNames dump files (allCountries.zip, alternateNamesV2.zip, and
the small countryInfo.txt, admin1CodesASCII.txt, admin2Codes.txt: about 630 MB in five downloads) with
DuckDB's own CSV reader. It loads the populated places (feature class P) and the language-tagged names once,
then slices one <cc>.duckdb per country from them, so a full rebuild takes about a minute once the files are
on disk. The tables are typed:
INTEGER ids, DOUBLE coordinates, BOOLEAN flags, a DATE modification date, VARCHAR[] for the
comma-separated columns (languages, neighbors) and ENUMs for feature_code and
alias.target_table. There are no keys or indexes, because the files are read-only. Rows are sorted by
the lookup column so DuckDB can skip most of the file. Table and column names match the SQLite files, except that city has no alternate_names column: every entry is already in alias (lowercased) or alt_name (language-tagged), and the list cost 21% of the file.
cd admin php admin.php download # the five worldwide files php admin.php build-duckdb # geo.duckdb + every country; --country=hu limits the slices written
publish.sh runs both and uploads the result to its own dataset, museado/geonames-duckdb
(HF_DUCKDB_REPO), so that apps can read the files over HTTP. The SQLite files are legacy and built only with
LEGACY_SQLITE=1, from per-country archives (download --per-country).
Differences from the SQLite files: aliases are lowercased with Unicode rules (SQLite: ASCII only), and
GeoService lowercases search terms to match the backend it queries.
Measurements
On us (193,759 cities): 75.5 MB as SQLite, 17.1 MB as DuckDB, and lookups take 13 ms instead of 141 ms
(lower(name) = ... cannot use the SQLite indexes, so SQLite scans the table). Building hu from the raw
files takes 0.1 s. Reads over HTTP from a local server took 210 ms for the first lookup (two attaches) and
6 ms after that; reads from S3 or Hugging Face add one network round trip per range request and are not
measured yet.
We require DuckDB 2.0 or later and assume later versions read 2.0 files; if one does not, rebuild the files
with build-duckdb. Composer cannot check this: ext-pdo_duckdb reports the extension's own version (1.0.0),
not the engine's. Check the engine with php --ri pdo_duckdb ("DuckDB Library Version") or
SELECT version(); survos:geo warns when it is older than 2.0.
Build Workflow
Build-time tooling is separate from the public bundle command, so the published bundle itself stays
light — admin/ has its own dev dependencies (composer install inside bu/geonames-bundle) and
never ships to consumer apps.
Admin console (admin/admin.php, a standalone Symfony Console app):
cd admin php admin.php download # the worldwide dumps for build-duckdb (about 630 MB) php admin.php build-duckdb # geo.duckdb + one <cc>.duckdb per country php admin.php download --per-country --country=hu # legacy: one archive pair per country, for the SQLite build php admin.php build --force --country=hu # legacy: rebuild geo.sqlite + hu.sqlite from the per-country archives php admin.php metadata # regenerate README.md/datasets.jsonl only, no rebuild
With --per-country, download fetches, per requested country, both <CC>.zip (cities) and alternatenames/<CC>.zip
(locale-specific alternate names — see above) alongside the shared countryInfo.txt,
admin1CodesASCII.txt, admin2Codes.txt, timeZones.txt, hierarchy.zip. build --force parses
those files directly into SQLite with prepared statements — no ORM — and refreshes the dataset-card
README.md/datasets.jsonl in the output directory.
One-shot: download + build + publish
admin/publish.sh runs the full pipeline — download, build, and hf upload to the
museado/geonames-duckdb Hugging Face dataset (also museado/geonames-data with LEGACY_SQLITE=1) — for a
country or every country:
cd admin ./publish.sh # every country GeoNames covers ./publish.sh us,hu,ch # just these countries SKIP_UPLOAD=1 ./publish.sh hu # download + build only, skip the Hugging Face upload
Requires the hf CLI
(pip install -U huggingface_hub[cli]) logged in with write access to the dataset repo
(hf auth login) unless SKIP_UPLOAD=1.
Publishing To Hugging Face
Each Hugging Face dataset directory contains a README.md dataset card, datasets.jsonl, geo.sqlite,
and one <countryCode>.sqlite per built country. survos:geo (the runtime bundle command, below)
fetches those published files rather than rebuilding them locally.
Installing The Bundle
composer req survos/geonames-bundle
Fetching The Authority
The public Symfony command:
bin/console survos:geo # fetch geo.duckdb bin/console survos:geo --country=us,hu # + one or more per-country city databases bin/console survos:geo --all # every published per-country database bin/console survos:geo --format=sqlite # the legacy SQLite files (default when ext-pdo_duckdb is missing)
fetches the published databases straight from the museado/geonames-duckdb (DuckDB) or
museado/geonames-data (SQLite) Hugging Face dataset into GeoService::sqliteDir() — no auth needed, it's a public repo.
Fetch strategy (cache/retry/resume)
survos:geo uses two different survos/fetch-bundle services for two different jobs — don't
reach for the wrong one if extending this command:
- Listing published files (
--all, the HF Hub tree API call) goes throughPersistentFetcherInterface— small JSON, cached forever (untilforget()/force_fetch) in a SQLite pool atvar/data/fetch_cache.db. Retried up to 5 times with full-jitter exponential backoff (200ms base, 10s cap) on transport errors/429/5xx. - Downloading the
.sqlitefiles themselves (up to ~3.4 GB total) goes throughChunkDownloader, notPersistentFetcher—PersistentFetcherbuffers the whole response into the cache pool, which is fine for JSON and wrong for gigabytes.ChunkDownloaderstreams straight to disk (constant memory), resumes via HTTPRangeif a transfer drops partway (<file>.sqlite.part), and retries transient failures independently of the listing cache.--forcepassesoverwrite: truethrough to it.
Before 2026-08-08 download() was a hand-rolled stream-to-disk loop with no resume — a
dropped 3 GB transfer restarted from byte 0.
Using The Bundle
The runtime API will stay lookup-oriented.
Example:
$geoId = $this->geoService->find('Oslo');
We will refine the query methods and return values later. For now, the design center is local lookup against fetched authority data.
See PLAN.md for the CSV layout and next migration steps.
Configuration
data_dir is the directory that holds the databases (<name>.duckdb, or the legacy <name>.sqlite) and the
downloads cached by GeoService. It defaults to APP_SHARED_DIRECTORY/geonames-data, else var/geonames-data.
sqlite_dir and GeoService::sqliteDir() still work and are deprecated since 2.45.76.