Technical Reference · Native & SQL

Embedded SDKs Reference (Rust, Python, DuckDB, C ABI & Mobile)

Beyond JavaScript/WASM and the HTTP server, texspace embeds directly inside native applications with zero external daemons.


1. Rust Crates#

A. Serverless Sans-I/O HTTP-Range (texspace-txg)#

Pure Rust (wasm32-unknown-unknown and native, zero C/SQLite dependencies). Supply any synchronous RangeSource (FileRangeSource, MemoryRangeSource, or your own HTTP/S3 client) or drive the Step::NeedRanges loop asynchronously:

rust
use texspace_txg::{
    FileRangeSource, TxgCache, TxgEnrichSpec, TxgNearbyRequest, TxgQueryOptions, TxgTarget,
    run_sync, step_enrich, step_nearby, step_search, step_verify,
};

let source = FileRangeSource::new("data/txg_planet_v2");
let target = TxgTarget::Routed { router_path: "router.txg".into() };
let mut cache = TxgCache::new();

// Forward search (handles typos like "4865 Mision St")
let hit = run_sync(&mut cache, &source, |c| {
    step_search(&target, c, "4865 Mision St, San Francisco, CA 94112", &TxgQueryOptions::default())
})?;

// Mount an in-memory GeoJSON overlay & run relational nearby search
cache.mount_geojson("stores", include_str!("../stores.geojson"))?;
let near = run_sync(&mut cache, &source, |c| {
    step_nearby(&target, c, &TxgNearbyRequest {
        query: Some("warehouses within 2km of 4865 Mission St, San Francisco, CA 94112".into()),
        ..Default::default()
    })
})?;

// Parallel spatial enrichment (reverse + tz.txg + spatial cells + custom TXGL layers)
let enriched = run_sync(&mut cache, &source, |c| {
    step_enrich(&target, c, 37.72047, -122.43765, &TxgEnrichSpec {
        reverse: true,
        timezone: true,
        spatial: true,
        layers: vec!["layers/us_states.txg".into(), "layers/world_countries.txg".into()],
        ..Default::default()
    })
})?;

B. Local Sub-2ms SQLite mmap Engine (texspace-engine)#

rust
use texspace_engine::{QueryOptions, ReverseOptions, TexspaceEngine};

let engine = TexspaceEngine::open("data/global")?;
let res = engine.query("10 Downing Street, London, SW1A 2AA", &QueryOptions::default())?;
let rev = engine.reverse(37.72047, -122.43765, &ReverseOptions::default())?;
let ip  = engine.geoip("8.8.8.8")?;
let tz  = engine.timezone(37.7749, -122.4194, None)?;

2. Python (python/)#

Zero Python runtime dependencies — uses standard-library ctypes against bundled libtexspace_ffi:

python
from texspace import TexspaceEngine

with TexspaceEngine("/path/to/texspace_shards") as geo:
    res = geo.search("2750 Middlefield Rd, Palo Alto, CA 94306", limit=3)
    print(res["results"][0])

    rev = geo.reverse(37.72047, -122.43765, limit=1)
    print(rev["results"][0])

    ip = geo.geoip("8.8.8.8")
    tz = geo.timezone(37.7749, -122.4194)
    print(ip, tz)

3. DuckDB Native SQL Extension (duckdb/)#

Vectorized, Rayon-parallel DuckDB C-API loadable extension (texspace.duckdb_extension, stable C Extension ABI v1.2.0 for DuckDB 1.2–1.5+). Geocodes 2,048-row chunks across all CPU cores with cached mmap handles.

bash
python3 duckdb/build.py
# -> target/release/texspace.duckdb_extension
sql
LOAD 'target/release/texspace.duckdb_extension';

-- Vectorized geocoding returning a native DuckDB STRUCT
SELECT
  id,
  g.label,
  g.lat,
  g.lon,
  g.match_level,
  g.confidence,
  g.unit,
  g.apn
FROM (
  SELECT id, texspace_geocode('data/global', address) AS g
  FROM read_csv('customers.csv')
);

All 6 DuckDB SQL Functions#

SQL FunctionReturnsDescription
texspace_geocode(db_path, text)STRUCT(label, lat, lon, layer, match_level, confidence, housenumber, unit, postcode, apn)Vectorized forward geocoding
texspace_geocode_json(db_path, text)VARCHAR (JSON)Full compact JSON geocoding payload
texspace_reverse(db_path, lat, lon)VARCHAR (JSON)4-tier offline reverse geocoding
texspace_geoip(db_path, ip)VARCHAR (JSON)Offline IPv4/IPv6 + ASN lookup
texspace_timezone(db_path, lat, lon)VARCHAR (JSON)Offline IANA timezone + DST + local time
texspace_version()VARCHARInstalled texspace engine version

See duckdb/README.md for Python DuckDB integration and build options.


4. C ABI (crates/ffi, include/texspace.h)#

libtexspace_ffi builds as both cdylib (.so/.dylib/.dll) and staticlib (.a) with a clean C header (include/texspace.h) for C, C++, Go (cgo), Swift, Kotlin JNI, Ruby, and Elixir bindings — including pure-Rust ruzstd decompression and thread-safe Rayon batch helpers.


5. Offline Mobile SDKs — iOS Swift & Android Kotlin (mobile/)#

51 pre-built offline packs (world_base 31.7 MB zstd + 50 global metros 3.5–57 MB each) hosted at https://shards.texspace.dev/mobile/latest.json, running in ~10 MB dirty RAM (~25 MB RSS) with zero router.db rebuild on device (multi_pack mode).

  • iOS (mobile/ios/): Swift Package / XCFramework wrapping libtexspace_ffi with ensureEngine(forLat:lon:) geo-aware pack download & pure-Rust zstd extraction.
  • Android (mobile/android/): Kotlin + JNI bindings with identical multi-pack & GPS auto-selection APIs.
  • Custom region extraction: bash texspace pull --mobile --near 37.7749,-122.4194 --out data/mobile # Or extract any custom bounding box: texspace pack-mobile metro --from data/global --id custom_area --bbox 37.3,-122.3,37.6,-121.9 -o custom_area.db

See mobile/README.md for the full 51-pack catalog and Xcode/Gradle setup.