Spatio is a compact and efficient embedded spatio-temporal database written in Rust. It’s designed for real-time 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
- Spatio-Temporal Queries — Nearby search, bounding box, distance, containment, and time slicing
- Trajectory Support — Store and query movement over time
- 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 Duration;
C ABI
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
let point = new;
// Insert point with automatic spatial indexing
db.insert_point?;
// 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?;
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)
Acknowledgments
- Built with the Rust ecosystem's excellent geospatial libraries
- Inspired by modern embedded databases and spatial indexing research
- Thanks to the Rust community for feedback and contributions