| Crates.io | geodb-wasm |
| lib.rs | geodb-wasm |
| version | 0.1.5 |
| created_at | 2025-11-17 15:52:12.718801+00 |
| updated_at | 2025-12-08 22:49:56.950516+00 |
| description | WebAssembly bindings for geodb-core with simple JS API and embedded dataset |
| homepage | https://github.com/holg/geodb-rs |
| repository | https://github.com/holg/geodb-rs |
| max_upload_size | |
| id | 1937056 |
| size | 8,494,081 |
Author: Holger Trahe | License: MIT (Code) / CC-BY-4.0 (Data)
A high-performance, pure-Rust geographic database with countries, states/regions, cities, aliases, phone codes, currencies, timezones, and multi-platform support including WebAssembly, iOS, macOS, watchOS, and Android.
This repository is a Cargo workspace containing:
geodb-core — main geographic database library (published on crates.io) — docs: https://docs.rs/geodb-coregeodb-cli — command-line interface — docs: https://docs.rs/geodb-cligeodb-wasm — WebAssembly bindings + browser demo — docs: https://docs.rs/geodb-wasmgeodb-py — Python bindings (published on PyPI as "geodb-rs") — https://pypi.org/project/geodb-rs/geodb-ffi — FFI bindings for mobile platforms (iOS, macOS, watchOS, Android)geodb-core provides:
geodb-wasmgeodb-ffi (iOS, macOS, watchOS, Android)The dataset is adapted from https://github.com/dr5hn/countries-states-cities-database (licensed under CC-BY-4.0, attribution required).
Important: Data source and automatic downloading
geodb-core uses the upstream dataset from the dr5hn/countries-states-cities-database repository:
Automatic data download and caching:
- The published crate does NOT include data files (keeps package size under 1MB)
- On first load, the library automatically downloads the dataset from GitHub (~3.7MB)
- After download, a binary cache is generated for fast subsequent loads
- Download and cache generation happen only once per system
- Requires the
builderfeature (enabled by default) and internet connection for first load- Downloaded data and cache stored in
crates/geodb-core/data/directoryIf you update or replace the dataset, ensure it retains the same JSON structure. Please observe the CC-BY-4.0 license and attribution of the upstream project.
[dependencies]
geodb-core = "0.1"
Note: First load will download the dataset from GitHub (~3.7MB) and build the binary cache (requires internet connection). Subsequent loads will be instant using the cached binary.
[dependencies]
geodb-wasm = "0.1"
Add the Swift Package via git URL:
// In Xcode: File → Add Package Dependencies
// URL: https://github.com/holg/geodb-rs
// Or in Package.swift:
dependencies: [
.package(url: "https://github.com/holg/geodb-rs", from: "1.0.0")
]
Then import and use:
import GeodbKit
let engine = try GeoDbEngine()
let stats = engine.stats()
print("Countries: \(stats.countries), States: \(stats.states), Cities: \(stats.cities)")
// Search
let results = engine.smartSearch(query: "Berlin")
for city in results {
print("\(city.name), \(city.state), \(city.country)")
}
// Find nearest cities
let nearest = engine.findNearest(lat: 52.52, lng: 13.405, count: 10)
See the example app in GeoDB-App/android-app/. The app uses UniFFI-generated Kotlin bindings.
import uniffi.geodb_ffi.GeoDbEngine
val engine = GeoDbEngine()
val stats = engine.stats()
println("Countries: ${stats.countries}, States: ${stats.states}, Cities: ${stats.cities}")
// Search
val results = engine.smartSearch("Berlin")
results.forEach { city ->
println("${city.name}, ${city.state}, ${city.country}")
}
// Find nearest cities
val nearest = engine.findNearest(52.52, 13.405, 10u)
use geodb_core::prelude::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = GeoDb::<StandardBackend>::load()?;
if let Some(country) = db.find_country_by_iso2("US") {
println!("Country: {}", country.name());
println!("Capital: {:?}", country.capital());
println!("Phone Code: {}", country.phone_code());
println!("Currency: {}", country.currency());
}
Ok(())
}
Loads from:
geodb-core/data/countries+states+cities.json.gz
Creates automatic cache:
countries+states+cities.json.ALL.bin
let db = GeoDb::<StandardBackend>::load()?;
let db = GeoDb::<StandardBackend>::load_from_path(
"path/to/worlddata.json.gz",
None,
)?;
Cache becomes:
worlddata.json.ALL.bin
let db = GeoDb::<StandardBackend>::load_filtered_by_iso2(&["DE", "US"])?;
Cache:
countries+states+cities.json.DE_US.bin
Cache rules:
<dataset_filename>.<filter>.bin
use geodb_core::prelude::*;
let db = GeoDb::<StandardBackend>::load()?;
for country in db.countries() {
println!("{} ({})", country.name(), country.iso2());
}
if let Some(country) = db.find_country_by_iso2("DE") {
println!("Found {}", country.name());
}
if let Some(fr) = db.find_country_by_iso2("FR") {
println!("Capital: {:?}", fr.capital());
println!("Currency: {}", fr.currency());
println!("Region: {}", fr.region());
}
if let Some(us) = db.find_country_by_iso2("US") {
let states = us.states();
if let Some(ca) = states.iter().find(|s| s.state_code() == "CA") {
for city in ca.cities() {
println!("{}", city.name());
}
}
}
let countries = db.find_countries_by_phone_code("+44");
let results: Vec<_> = db.countries()
.iter()
.flat_map(|country| {
country.states().iter().flat_map(move |state| {
state.cities().iter()
.filter(|c| c.name() == "Springfield")
.map(move |c| (country.name(), state.name(), c.name()))
})
})
.collect();
geodb-wasm)Exports:
search_country_prefixsearch_countries_by_phonesearch_state_substringsearch_city_substringsmart_searchget_statsTo run locally:
cd crates/geodb-wasm
cargo install trunk
trunk serve
Live demos:
geodb-cli)The CLI is finished and available on crates.io. It provides quick access to the database for exploration, scripting, or data checks.
Install:
cargo install geodb-cli
Examples:
geodb-cli --help
geodb-cli stats
geodb-cli find-country US
geodb-cli list-cities --country US --state CA
Docs.rs: https://docs.rs/geodb-cli
geodb-py)geodb_rs - os: ubuntu-latest
target: x86_64
manylinux: auto
- os: ubuntu-latest
target: aarch64
manylinux: auto
- os: macos-13
target: x86_64
manylinux: ""
- os: macos-14
target: aarch64
manylinux: ""
- os: windows-latest
target: x64
manylinux: ""
Quick start:
import geodb_rs
db = geodb_rs.PyGeoDb.load_default() # tries bundled data first
print(db.stats()) # (countries, states, cities)
GeoDB-App)The repository includes native apps for Apple and Android platforms:
| Platform | Status | Link |
|---|---|---|
| iOS | Available | App Store |
| macOS | In Review | Coming soon |
| tvOS | In Review | Coming soon |
| watchOS | Available | Included with iOS app |
| TestFlight | Available | Join Beta |
Located in GeoDB-App/GeoDB/ - a universal Xcode project supporting:
Uses the GeodbKit Swift package via SPM.
Located in GeoDB-App/android-app/ - a Jetpack Compose app featuring:
Pre-built APKs available in releases/android/:
app-arm64-v8a-release.apk (15 MB) - Most modern Android phonesapp-armeabi-v7a-release.apk (14 MB) - Older 32-bit phonesapp-x86_64-release.apk (15 MB) - Emulatorsapp-universal-release.apk (40 MB) - All architecturesgeodb-rs/
├── crates/
│ ├── geodb-core/ # Core Rust library
│ ├── geodb-cli/ # Command-line interface
│ ├── geodb-wasm/ # WebAssembly bindings
│ ├── geodb-py/ # Python bindings
│ └── geodb-ffi/ # FFI bindings (mobile)
├── GeoDB-App/
│ ├── GeoDB/ # Xcode project (macOS/iOS/watchOS)
│ ├── android-app/ # Android Kotlin app
│ ├── spm/ # Swift Package (GeodbKit)
│ │ ├── Package.swift
│ │ ├── GeodbFfi.xcframework/
│ │ └── Sources/
│ └── scripts/ # Build scripts
├── releases/
│ └── android/ # Pre-built APKs
├── Package.swift # Root SPM package (for git URL install)
├── scripts/ # Development scripts
└── README.md
cargo build --workspace
cargo test --workspace
cd GeoDB-App/scripts
./build_spm_package.sh
# Requires cargo-ndk and Android NDK
cargo ndk -t arm64-v8a -t armeabi-v7a -t x86_64 -t x86 \
-o GeoDB-App/android-app/app/src/main/jniLibs \
build --release -p geodb-ffi
cargo fmt
cargo clippy --all-targets -- -D warnings
cargo test --workspace
cargo doc --workspace
cargo sort -cwg
taplo format --check
cargo deny check
MIT License.
This project includes data from:
countries-states-cities-database https://github.com/dr5hn/countries-states-cities-database Licensed under Creative Commons Attribution 4.0 (CC-BY-4.0). Attribution is required if you redistribute or use the dataset.
releases/android/ folderMade with Rust.