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.
Quick Start
Python
=
# Store a point (longitude, latitude)
=
# Find nearby points
=
Rust
[]
= "0.1"
use *;
Features
Spatial queries: Radius search, bounding box, K-nearest-neighbors, polygon containment 3D support: Full altitude-aware indexing and queries Trajectories: Track movement over time Distance metrics: Haversine, Geodesic, Rhumb, Euclidean TTL: Auto-expire old data Persistence: Snapshots (default) or append-only file (AOF) Namespaces: Logical data separation in one database
Coordinate Order
Important: Spatio uses (longitude, latitude) order everywhere - same as GeoJSON and most GIS tools.
// Correct: lon, lat
let point = new; // NYC
This matches the mathematical (x, y) convention and makes GeoJSON interop trivial.
Examples
2D Spatial
// Insert points
db.insert_point?;
// Find nearby (within 1km)
let nearby = db.query_within_radius?;
// Bounding box query
let in_box = db.find_within_bounds?;
// K-nearest neighbors
let nearest = db.knn?;
3D Spatial
use Point3d;
// Track drones with altitude
let drone = new;
db.insert_point_3d?;
// 3D sphere query
let nearby = db.query_within_sphere_3d?;
// Cylindrical query (altitude range + radius)
let in_cylinder = db.query_within_cylinder_3d?;
Trajectories
use TemporalPoint;
let path = vec!;
db.insert_trajectory?;
// Query movement history
let history = db.query_trajectory?;
TTL (Time-To-Live)
use SetOptions;
// Data expires in 1 hour
let opts = with_ttl;
db.insert?;
// Expired items return None
let value = db.get?; // None if expired
// Clean up expired items manually
let removed = db.cleanup_expired?;
Important: TTL is lazy - expired items stick around in memory until you call cleanup_expired() or they get overwritten. For long-running apps, clean up periodically or you'll leak memory.
Persistence
Snapshots (default): Point-in-time saves, good for edge devices
let config = default.with_snapshot_auto_ops;
let db = new
.snapshot_path
.config
.build?;
// Auto-saves every 1000 operations
AOF (optional): Write-ahead log, good for zero data loss
let db = new
.aof_path
.build?;
// Requires --features aof
Platforms
Supported:
- Linux (x86_64, aarch64)
- macOS (x86_64, arm64)
Not supported:
- Windows (use WSL2 or Docker)
See PLATFORMS.md for details.
API Overview
Key-Value:
db.insert?;
db.get?;
db.delete?;
Spatial:
db.insert_point?;
db.query_within_radius?;
db.count_within_radius?;
db.contains_point?;
db.find_within_bounds?;
db.knn?;
db.query_within_polygon?;
db.distance_between?;
3D Spatial:
db.insert_point_3d?;
db.query_within_sphere_3d?;
db.query_within_cylinder_3d?;
db.query_within_bbox_3d?;
db.knn_3d?;
Trajectories:
db.insert_trajectory?;
db.query_trajectory?;
Utility:
db.atomic?;
db.cleanup_expired?;
db.count_expired;
db.stats;
Documentation
- Examples: examples/ directory
- Spatial features: SPATIAL_FEATURES.md
- Platform support: PLATFORMS.md
- API docs: docs.rs/spatio
- Python docs: py-spatio/README.md
Status
Current version: 0.1.x (active development)
APIs may change. Check CHANGELOG.md before upgrading.
Contributing
Contributions are welcome! See CONTRIBUTING.md.
License
MIT - see LICENSE