Spatio is a compact and efficient embedded spatio-temporal database written in Rust. It's designed for real-time 2D and 3D location data, with low memory usage, optional persistence, and native Python bindings.
No SQL parser, no external dependencies, and requires no setup.
Features
Embedded and Lightweight
- Self-contained — Runs without external services or dependencies
- Minimal API surface — Open, insert, and query
- Low memory footprint — Suitable for IoT, edge, and embedded environments
- Single-Writer Thread Safety — Uses a shared Arc (without lock upgrades) to allow concurrent readers and a single writer
Performance Scope
- Concurrent read access — Multiple readers operate without blocking; writes are serialized under a global lock
- Spatio-temporal queries — Use a geohash + R-tree hybrid to balance lookup precision and performance for moderate datasets
- Configurable persistence — Append-Only File (AOF) with sync policies
- Startup and Shutdown — AOF logs are replayed automatically on startup
Spatio-Temporal Indexing and Querying
- Spatio-Temporal Indexing — R-Tree + geohash hybrid indexing with optional history tracking
- Advanced Spatial Operations — Distance calculations (Haversine, Geodesic, Rhumb, Euclidean), K-nearest-neighbors, polygon queries, convex hull, bounding box operations
- Spatio-Temporal Queries — Nearby search, bounding box, distance, containment, and time slicing
- 3D Spatial Support — Full 3D point indexing with altitude-aware queries (spherical, cylindrical, bounding box)
- Trajectory Support — Store and query movement over time (2D and 3D)
- GeoJSON I/O — Supports import and export of geometries in GeoJSON format
Data Management
- Namespaces — Isolate data logically within the same instance
- TTL Support — Automatically removes expired data
- Temporal Queries — Filter keys by recent activity with optional history tracking
- Atomic Batches — Supports grouped write operations with atomic semantics.
- Custom Configs — JSON/TOML serializable configuration
Language Support
- Rust — Native
- Python — Provides bindings implemented via PyO3 (
pip install spatio) - C / C++ — Provides an extern "C" ABI for interoperability (see C ABI)
Compile-Time Feature Flags
time-index(default) — enables creation-time indexing and per-key history APIs. Disable it for the lightest build:cargo add spatio --no-default-features --features="aof,geojson".
Sync Strategy Configuration
SyncMode::All(default) — callfsync/File::sync_allafter each batch of writes (durable but slower).SyncMode::Data— usefdatasync/File::sync_datawhen your platform supports it (data-only durability).sync_batch_size— number of write operations to batch before a sync whenSyncPolicy::Alwaysis selected (default: 1). Tune viaConfig::with_sync_batch_sizeto reduce syscall frequency.
Installation
Python
📦 PyPI: https://pypi.org/project/spatio
Rust
Add this to your Cargo.toml:
[]
= "0.1"
📦 Crates.io: https://crates.io/crates/spatio
Quick Start
Python usage lives in the dedicated bindings package—see py-spatio/README.md
for up-to-date installation notes and examples.
Rust
use *;
use Point3d;
use Duration;
C ABI
Note: The C ABI is experimental and is not actively developed.
The crate ships with a C-compatible ABI for embedding. Build the shared library once:
# target/release/libspatio.so (Linux)
# target/release/libspatio.dylib (macOS)
# target/release/spatio.dll (Windows)
Link the resulting library and declare the externs you need (or generate them
with bindgen). Minimal usage example:
typedef struct SpatioHandle SpatioHandle;
typedef struct SpatioBuffer;
extern SpatioHandle *;
extern void ;
extern int ;
extern int ;
extern void ;
int
Safety note: Callers must pass valid, null-terminated strings and free any buffers produced by
spatio_getusingspatio_free_buffer. Structured error reporting is under development;spatio_last_error_messagecurrently returnsNULL.
For runnable demos and extended use-case walkthroughs, check
examples/README.md.
API Overview
Core Operations
// Basic key-value operations
db.insert?;
let value = db.get?;
db.delete?;
Spatial Operations
use ;
use polygon;
let point = new;
// Insert point with automatic spatial indexing
db.insert_point?;
// Distance calculations with multiple metrics
let nyc = new;
let la = new;
let dist = db.distance_between?;
println!; // ~3,944 km
// K-nearest-neighbors search
let nearest = db.knn?;
for in nearest
// Polygon queries (using geo crate)
let area = polygon!;
let in_polygon = db.query_within_polygon?;
// Find nearby points
let nearby = db.query_within_radius?;
// Check if points exist in region
let exists = db.contains_point?;
// Count points within distance
let count = db.count_within_radius?;
// Query bounding box
let in_bounds = db.find_within_bounds?;
let intersects = db.intersects_bounds?;
Note: See SPATIAL_FEATURES.md for complete documentation on all spatial operations, including convex hull, polygon area calculations, and more.
3D Spatial Operations
Spatio provides comprehensive 3D spatial indexing for altitude-aware applications like drone tracking, aviation, and multi-floor building navigation:
use ;
let db = memory?;
// Insert 3D points (lon, lat, altitude)
let drone = new; // 100m altitude
db.insert_point_3d?;
// Spherical 3D query (true 3D distance)
let control = new;
let nearby = db.query_within_sphere_3d?;
// Cylindrical query (altitude range + horizontal radius)
let results = db.query_within_cylinder_3d?;
// 3D bounding box query
let bbox = new;
let in_box = db.query_within_bbox_3d?;
// K-nearest neighbors in 3D
let nearest = db.knn_3d?;
// 3D distance calculations
let dist_3d = db.distance_between_3d?;
See examples/3d_spatial_tracking.rs for a complete demonstration.
Logging
Spatio uses the log crate for diagnostics and warnings. To see log output in your application:
// Add to your Cargo.toml:
spatio = "0.1"
env_logger = "0.11" // or any other log implementation
// Initialize logging in your main():
Control log verbosity with the RUST_LOG environment variable:
# See all debug logs
RUST_LOG=debug
# Only warnings and errors
RUST_LOG=warn
# Only Spatio logs
RUST_LOG=spatio=debug
Spatio logs important events such as:
- Database lock errors (poisoned locks)
- AOF replay warnings (invalid coordinates, corrupted entries)
- Performance warnings (large expiration clusters)
- Spatial index warnings (invalid query parameters)
Trajectory Tracking
// Store movement over time
let trajectory = vec!;
db.insert_trajectory?;
// Query trajectory for time range
let path = db.query_trajectory?;
Atomic Operations
db.atomic?;
Time-to-Live (TTL)
// Data expires in 1 hour
let opts = with_ttl;
db.insert?;
Architecture Overview
Spatio is organized in layered modules:
- Storage – Pluggable backends (in-memory by default, AOF for durability) with a common trait surface.
- Indexing – Geohash-based point index with configurable precision and smart fallback during searches.
- Query – Radius, bounding-box, and trajectory primitives that reuse the shared index and TTL cleanup workers.
- API – Ergonomic Rust API plus PyO3 bindings that expose the same core capabilities.
See the docs site for deeper architectural notes.
Project Status
- Current version: 0.1.X
- Active development: APIs may still change.
- Follow releases for migration notes and roadmap updates.
Contributing
Contributions are welcome! Please read our Contributing Guidelines before submitting pull requests.
Development Setup
Links & Resources
Package Repositories
- PyPI: https://pypi.org/project/spatio
- Crates.io: https://crates.io/crates/spatio
Documentation & Source
- GitHub Repository: https://github.com/pkvartsianyi/spatio
- Rust Documentation: https://docs.rs/spatio
- Python Documentation: https://github.com/pkvartsianyi/spatio/tree/main/py-spatio
Community
- Issues & Bug Reports: https://github.com/pkvartsianyi/spatio/issues
- Releases & Changelog: https://github.com/pkvartsianyi/spatio/releases
License
MIT License (LICENSE)
Spatial Features
Spatio provides comprehensive geospatial operations powered by the georust/geo crate:
- 4 Distance Metrics: Haversine (fast spherical), Geodesic (accurate ellipsoidal), Rhumb (constant bearing), Euclidean (planar)
- K-Nearest-Neighbors: Find the K closest points efficiently using spatial index
- Polygon Queries: Point-in-polygon tests, polygon area calculations
- Geometric Operations: Convex hull, bounding boxes, bbox expansion and intersection
- Full geo Integration: All operations leverage battle-tested geo crate implementations
Coordinate Convention:
- Rust:
Point::new(longitude, latitude)- follows geo crate (x, y) convention - Python:
Point(latitude, longitude)- user-friendly order, converted internally
For complete documentation and examples, see:
- SPATIAL_FEATURES.md - Complete API reference
- examples/advanced_spatial.rs - Comprehensive demo
Acknowledgments
- Built with the Rust ecosystem's excellent geospatial libraries (especially georust/geo)
- Inspired by modern embedded databases and spatial indexing research
- Thanks to the Rust community for feedback and contributions