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.4-cp313-cp313-manylinux_2_35_x86_64.whl (519.5 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

spatio-0.2.4-cp312-cp312-manylinux_2_35_x86_64.whl (519.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

spatio-0.2.4-cp311-cp311-manylinux_2_35_x86_64.whl (519.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

spatio-0.2.4-cp310-cp310-manylinux_2_35_x86_64.whl (522.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

spatio-0.2.4-cp39-cp39-manylinux_2_35_x86_64.whl (526.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.35+ x86-64

File details

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

File metadata

File hashes

Hashes for spatio-0.2.4-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 9ff602a684bf554813121938415dcf352af2e530141e2706ac53ddc724e64599
MD5 d0a910075ace9a5d0eb8fb5270827aeb
BLAKE2b-256 783158312e946024507ceab725a9a7baed05c285eb40763cc7db7874d231e5fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.4-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 3bcb3a60b5cef274c04f9ede30c61f0172e1e0c94ce1bb8e31f7bdfeac6a1b14
MD5 17b86b3a062507d82686e76117f39285
BLAKE2b-256 c96ed4db115422bf602d5db8a09e961192b835b315fd2c2ccc3586f87528aec0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.4-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d1f5d7691b2502f805b9b0b3f38eaf36f511e1724e0954960069dbbcb5a08806
MD5 fade9631e331ad60823b9fc1dc177fbc
BLAKE2b-256 cec7a87bd086077cdba2030c771ed35edbdc174ac7122b0ad2a8f034cf6058c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.4-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 fd48dd7d16de441ea903a4a1477d85dc37839039ee3f22ff4ad1ec332063700f
MD5 45575914f712510ca6bca6a6eff72b7f
BLAKE2b-256 9acb7887b44ffc330a48db27836a9e1daacfae99d1e6149904b7a05e83d02c32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.4-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1a00f7cf074c884f97ee85ca9dfe44cefb6a7b87d4faff650b0d5698b7b0f951
MD5 ee7bea9d10f7074cddffe9e033b51175
BLAKE2b-256 49e455c8f986aa83607020ec6ce13025f867cc10a596b1ac0e7deb29e28ba2e8

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