Skip to main content

Blazingly fast spatio-temporal database library

Project description

Spatio for Python

High-performance spatial database for Python, powered by Rust.

PyPI Python 3.9+ License: MIT

What is it?

Spatio is an embedded database optimized for tracking moving objects. It uses a specialized Hot/Cold State architecture to provide real-time spatial queries and historical trajectory tracking with minimal overhead.

Quick Start

import spatio

# Open an in-memory database
db = spatio.Spatio.memory()

# Track a moving object
pos = spatio.Point(-74.006, 40.712, altitude=10.0)
db.upsert("drones", "drone_1", pos, {"status": "active"})

# Find objects within 500 meters
nearby = db.query_radius("drones", pos, radius=500, limit=10)
for object_id, point, metadata, distance in nearby:
    print(f"Found {object_id} at {distance:.1f}m")

core API

Spatio (Local Database)

import spatio

# Creation
db = spatio.Spatio.memory()
db = spatio.Spatio.open("data.db")

# Tracking
db.upsert(namespace, object_id, point, metadata=None)
db.get(namespace, object_id)  # Returns CurrentLocation or None
db.delete(namespace, object_id)

# Proximity Queries
# Returns list of (object_id, point, metadata, distance)
db.query_radius(namespace, center_point, radius, limit=100)
db.query_near(namespace, object_id, radius, limit=100)

# K-Nearest Neighbors
db.knn(namespace, center_point, k)
db.knn_near_object(namespace, object_id, k)

# Volume Queries
db.query_bbox(namespace, min_x, min_y, max_x, max_y, limit=100)
db.query_within_cylinder(namespace, center_point, min_z, max_z, radius, limit=100)
db.query_within_bbox_3d(namespace, min_x, min_y, min_z, max_x, max_y, max_z, limit=100)

# Relative Queries
db.query_bbox_near_object(namespace, object_id, width, height, limit=100)
db.query_cylinder_near_object(namespace, object_id, min_z, max_z, radius, limit=100)

# Trajectories
db.insert_trajectory(namespace, object_id, list_of_temporal_points)
db.query_trajectory(namespace, object_id, start_ts, end_ts, limit=100)

Data Types

Point

spatio.Point(lon, lat, altitude=0.0)

  • point.lon, point.lat, point.alt
  • point.distance_to(other_point) -> distance in meters (Haversine)

TemporalPoint

spatio.TemporalPoint(point, timestamp)

  • Used for bulk trajectory ingestion.

Performance Tips

  1. Namespaces: Use namespaces to logically separate different types of objects (e.g., "delivery_trucks", "warehouses").
  2. Object Queries: Use query_near or knn_near_object whenever possible, as they avoid re-passing coordinates and leverage the internal Hot State index directly.

License

MIT - see LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

spatio-0.2.5-cp313-cp313-manylinux_2_35_x86_64.whl (508.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

spatio-0.2.5-cp312-cp312-manylinux_2_35_x86_64.whl (508.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

spatio-0.2.5-cp311-cp311-manylinux_2_35_x86_64.whl (507.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

spatio-0.2.5-cp310-cp310-manylinux_2_35_x86_64.whl (510.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

spatio-0.2.5-cp39-cp39-manylinux_2_35_x86_64.whl (514.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.35+ x86-64

File details

Details for the file spatio-0.2.5-cp313-cp313-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for spatio-0.2.5-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 6dc0d34b82a553e4963c63c977304b6ed1c5ade73d7d0222219a15aed9936284
MD5 f33f07852cf28cb6e4aaddcb61a007af
BLAKE2b-256 5ff7cecaf8e3f39d2cf837b145697d5ab8642b175894e7b23c67d7ce64c55656

See more details on using hashes here.

File details

Details for the file spatio-0.2.5-cp312-cp312-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for spatio-0.2.5-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 17c1266e4444b5c39c3726061586b3c89080de68e7c3ef27ba23e05e7f6f0149
MD5 400db27f15cfd696c7de186b6aa9c4f8
BLAKE2b-256 bc4b9b1b0f3e892088e87e2cc55c1c8909724f5a9b01c3765980cbc323c701fe

See more details on using hashes here.

File details

Details for the file spatio-0.2.5-cp311-cp311-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for spatio-0.2.5-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 836daada4ce0639d0c9dd7cc3564143b081ac2fad6d39cbed6c11455bd2f7c54
MD5 c2b27340d29c71da7223781644bca14a
BLAKE2b-256 5bb4b946de492a703b35cde5f6a53863866028ee51ff5b484ccb7144ac7a7a02

See more details on using hashes here.

File details

Details for the file spatio-0.2.5-cp310-cp310-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for spatio-0.2.5-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 556aa0e215cee57b6454811c76f7c5c0e24f1b41f78a4cd9d11fb1a01610cec9
MD5 bbaca394a60f6e759ade50f90c5fc95b
BLAKE2b-256 76aba21ecb9f142f944e03fa088e7b8f55592d88182029aa91dcfe5b5ec223d9

See more details on using hashes here.

File details

Details for the file spatio-0.2.5-cp39-cp39-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for spatio-0.2.5-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 2dc1b40dea31d82873df39b72cd9bd9eff035b0847d1eb34f1e76b0416d859d8
MD5 5f41a98ef67be9898a0d8dceda45202d
BLAKE2b-256 f65345cc66f79d29fd7e1e25dfaf5d56c9587103212dfb7fbed99266063e387f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page