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 neighbours, polygon containment
- 3D support: Altitude-aware indexing and 3D spatial queries (sphere, cylinder)
- Trajectories: Insert and query movement paths over time
- Distance metrics: Haversine, Geodesic, Rhumb line, and Euclidean calculations
- Persistence: Choose between snapshots (default) or append-only file (AOF)
- Namespaces: Logical separation of datasets within a single database instance
- Lightweight: No SQL parser, no external dependencies, no setup required
- Cross-language: Native Python bindings via PyO3
- Edge-optimised: Runs entirely in-process with low memory and zero network latency
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 (not supported - use WSL2, Docker, or a Linux VM)
See PLATFORMS.md for details.
API Overview
Real-time Tracking:
db.update_location?;
db.update_location_at?;
Object-Based Queries (Primary - Most Common):
// Find objects near another object
db.query_near_object?;
db.query_bbox_near_object?;
db.query_cylinder_near_object?;
db.query_bbox_3d_near_object?;
db.knn_near_object?;
Coordinate-Based Queries (When You Have Explicit Coordinates):
db.query_current_within_radius?;
db.query_current_within_bbox?;
db.query_within_cylinder?;
db.query_within_bbox_3d?;
db.knn_3d?;
Trajectories:
db.insert_trajectory?;
db.query_trajectory?;
Utility:
db.stats;
db.close?;
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