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

Uploaded CPython 3.13manylinux: glibc 2.35+ x86-64

spatio-0.2.3-cp312-cp312-manylinux_2_35_x86_64.whl (519.5 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.35+ x86-64

spatio-0.2.3-cp311-cp311-manylinux_2_35_x86_64.whl (519.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.35+ x86-64

spatio-0.2.3-cp310-cp310-manylinux_2_35_x86_64.whl (522.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.35+ x86-64

spatio-0.2.3-cp39-cp39-manylinux_2_35_x86_64.whl (526.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.35+ x86-64

File details

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

File metadata

File hashes

Hashes for spatio-0.2.3-cp313-cp313-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 d181b721fab144d0b6e7966068caed8492c3f19cc69d5580beb7e19a406dc5d4
MD5 fbc2208ec2bcaa10f0129cd2660a4f80
BLAKE2b-256 f899654b9a3eb25d5b6884c35f8ac6d5a502eb7ac36d830aae3f8347d34ad0b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.3-cp312-cp312-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 f1da095a3c32b5909c47bb0c1224dca31704df819700a3410fe5cca9f136aa76
MD5 611fa76ca5e5b0cc18c3641f4e330edf
BLAKE2b-256 5f15bba58c5e9a986fc66d4b2d0186340bdd0eb88684c9bf329d906790172d4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.3-cp311-cp311-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 20d20cfcc8bcc23e8694bb236302b9f6d3d9823cf2bc4aac97ef6be811cf93d0
MD5 e9239494706efcc4ee87a9b035c33ac0
BLAKE2b-256 e9442abb0c3b680ded25e7fafff48856ab47ae89742eb40cde88a3ce1a662e18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.3-cp310-cp310-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 1338ecee91d853312c5aad449026e596337e052578c146139ed008f62a99f4eb
MD5 53875b0acbb42087e498ea4ee5b19f1b
BLAKE2b-256 615eb4ee23a0780d34588ec74626334077ea6e98cefe3edec5264141a4e0ecfb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for spatio-0.2.3-cp39-cp39-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 5ab6e2a503bded4d3d624bd59453132c25684ca8059d758fd370a21c13f552eb
MD5 6e83283ccd8c2d6f273ece5adbfdfd84
BLAKE2b-256 58b479d9eae2348907085f176c21d9eb1945164429d6401cdb1a83d82fb6e499

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