Spatio is a high-performance, embedded spatial database designed for applications that need to store and query location-based data efficiently. Built with a simple, SQLite-like architecture, Spatio provides powerful spatial operations optimized for single-threaded embedded use cases.
Features
Embedded-First Design
- Simple Architecture: Single-instance, RefCell-based design for embedded use
- SQLite-like API: Familiar open/close/read/write model
- Minimal Dependencies: No complex thread coordination or global state
- Synchronous by Default: Predictable behavior, background operations opt-in
High Performance
- Fast Key-Value Storage: ~1.6M ops/sec with optimized in-memory operations
- Automatic Spatial Indexing: Geographic points indexed with geohash for efficient queries
- Low Overhead: No unnecessary locking or coordination complexity
- Optional AOF Rewriting: Configurable file compaction with size thresholds
Spatial Operations
- Spatial Queries: Find nearby points, check intersections, and query bounding boxes
- GeoJSON I/O: Native support for GeoJSON import/export
- Distance Calculations: Haversine formula for accurate geographic distances
- Trajectory Tracking: Store and query movement paths over time
Data Management
- TTL Support: Built-in data expiration for temporary data
- Atomic Operations: Batch multiple operations for data consistency
- Persistence: Optional append-only file format with configurable optimization
- Truly Embedded: No external dependencies, no servers, no setup required
Installation
Python
📦 PyPI: https://pypi.org/project/spatio
Rust
Add this to your Cargo.toml:
[]
= "0.1"
📦 Crates.io: https://crates.io/crates/spatio
Language Support
Spatio is available for multiple languages:
- Rust (native): High-performance, zero-cost abstractions
- Python: Easy-to-use bindings via PyO3
Quick Start
Python
# Create an in-memory database
=
# Namespace support for data organization
=
=
# Store data with namespace isolation
# Store geographic points with automatic indexing
=
# GeoJSON support
=
=
# Find nearby points within 100km
=
Rust
use *;
Examples
Run the included examples to see Spatio in action:
Getting Started
Spatial Queries
Trajectory Tracking
Architecture Demo (New!)
Comprehensive Demo
Use Cases
Local Spatial Analytics
- Proximity Search: Efficiently find nearby features or points of interest
- Containment Queries: Check if points or geometries lie within defined areas
- Spatial Relationships: Analyse intersections, distances, and overlaps between geometries
Edge & Embedded Systems
- On-Device Processing: Run spatial queries directly on IoT, drones, or edge devices
- Offline Operation: Perform location analytics without cloud or network access
- Energy Efficiency: Optimised for low memory and CPU usage in constrained environments
Developer & Research Tools
- Python Integration: Use Spatio natively in data analysis or geospatial notebooks
- Simulation Support: Model trajectories and spatial behaviours locally
- Lightweight Backend: Ideal for prototypes, research projects, or local GIS tools
Offline & Mobile Applications
- Local Data Storage: Keep spatial data close to the application
- Fast Query Engine: Sub-millisecond lookups for geometry and location queries
- Self-Contained: No external dependencies or server required
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.find_nearby?;
// Check if points exist in region
let exists = db.contains_point?;
// Count points within distance
let count = db.count_within_distance?;
// 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?;
Performance
Spatio is designed for high performance:
- In-memory operations with microsecond latency
- Automatic spatial indexing using efficient geohash algorithms
- Concurrent access with read-write locks
- Batch operations for high-throughput scenarios
- Optional persistence with append-only file format
Spatial Features
Automatic Indexing
Points are automatically indexed using geohash for efficient spatial queries:
- O(log n) insertion and lookup
- Efficient range queries
- Automatic neighbor finding
Distance Calculations
Built-in haversine distance calculations for accurate geographic distances:
let distance = point1.distance_to; // Returns meters
let nearby = point1.within_distance; // Within 1km
Bounding Box Operations
use BoundingBox;
let bbox = new;
let intersects = bbox.intersects;
Development
Building from Source
Running Tests
Running Benchmarks
Documentation
Architecture
Spatio uses a modern, extensible layered architecture:
Storage Layer
- Backend Abstraction: Trait-based storage with pluggable implementations
- Memory Backend: High-performance in-memory B-trees with prefix operations
- AOF Backend: Append-only file storage with background compaction
- Custom Backends: Extensible design for RocksDB, SQLite, or cloud storage
Namespace Layer
- Data Organization: Isolated data with automatic key prefixing
- Namespace Management: Utilities for parsing and organizing namespaced keys
- Configurable Separators: Flexible namespace delimiter configuration
Indexing Layer
- Spatial Indexing: Automatic geohash-based geographic point indexing
- Configurable Precision: Adjustable spatial resolution (1-12 levels)
- Multi-Level Search: Smart fallback across precision levels
Query Layer
- Optimized Execution: Efficient spatial query processing
- Multiple Query Types: Point-in-radius, bounding box, nearest neighbor
- Background Cleanup: Automatic TTL-based data expiration
API Layer
- Clean Interface: Organized public API with comprehensive prelude
- Feature Flags: Modular compilation for specific use cases
- Serialization: JSON/TOML config support with validation
- Language Bindings: Native Rust API with Python bindings
Status
Spatio is in active development for embedded use cases. Current version: 0.1.0-alpha.10
Core Architecture (New!)
- Storage Backend Abstraction: Pluggable storage with trait-based design
- Namespace Support: Data isolation with automatic key prefixing
- Simplified Configuration: JSON/TOML serializable config with validation
- Feature Flags: Modular compilation (serde, geojson, aof, toml)
- Clean Public API: Organized exports with comprehensive prelude module
Spatial & Data Features
- Enhanced Spatial Operations: Point-in-radius, bounding box, trajectory tracking
- GeoJSON I/O: Native import/export for interoperability
- Automatic Indexing: Geohash-based spatial indexing with configurable precision
- TTL Support: Time-based data expiration with background cleanup
- Thread Safety: Concurrent read/write access with optimized locking
Persistence & Performance
- Enhanced AOF: Background rewriting with configurable size thresholds
- Memory Backend: High-performance in-memory storage with prefix operations
- Atomic Operations: Batch operations for data consistency (Rust API)
- Python Bindings: Complete PyO3-based Python API via
pip install spatio
In Development
- Python Atomic Operations: Batch operations for Python API
- Additional Storage Backends: RocksDB, SQLite integration
- Advanced Spatial Types: Polygons, lines, and complex geometries
- Query Optimization: Enhanced spatial index performance
Performance Characteristics
Based on current benchmarks:
- Key-value operations: ~1.6M ops/sec (600ns per operation)
- Spatial insertions: ~1.9M points/sec (530ns per operation)
- Spatial queries: ~225K queries/sec (4.4μs per operation)
- Memory efficiency: Optimized storage with spatial indexing and background compaction
Production Readiness
- Alpha Status: Enhanced architecture stabilizing, may have breaking changes
- Testing: Comprehensive test suite with 20+ unit tests and integration tests
- Documentation: Complete API documentation with architectural examples
- Extensibility: Plugin architecture ready for custom storage backends
- Language Support: Rust (native) and Python (bindings)
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