Skip to main content

High-performance trajectory splitting and analysis, powered by Rust

Project description

trucktrack

High-performance trajectory splitting, generation, and partitioning, powered by Rust.

A Python package implementing logic similar to movingpandas trajectory splitters (ObservationGapSplitter, StopSplitter) with a Rust backend for speed. Data flows through Polars DataFrames, with the option to process entirely in Rust (parquet in, parquet out) or share DataFrames between Python and Rust zero-copy via pyo3-polars.

In addition to the Rust splitters, trucktrack ships pure-Python subpackages for trace generation, spatial partitioning, map-matching, querying, and visualization.

Install

pip install trucktrack

Optional extras:

pip install trucktrack[valhalla]  # local pyvalhalla routing & map-matching
pip install trucktrack[viz]       # folium-based interactive maps

From source

# Requires Python 3.11+ and Rust stable
git clone https://github.com/twedl/trucktrack.git
cd trucktrack
python3 -m venv .venv && source .venv/bin/activate
pip install "maturin>=1.7,<2.0" polars pytest
maturin develop

Pipelines

Split + partition

Process raw GPS traces into a spatially partitioned hive dataset:

from pathlib import Path
from trucktrack import run_pipeline

run_pipeline(Path("data/raw"), Path("data/partitioned"))

Map-match

Map-match all trips against a local Valhalla instance:

from trucktrack.valhalla.pipeline import run_map_matching

run_map_matching(
    Path("data/partitioned"),
    Path("data/matched"),
    tile_extract="valhalla_tiles.tar",
    # or: config="valhalla.json",
)

Querying

Pull individual trucks or trips without scanning the full dataset. Each function filters by chunk_id (last 3 hex chars of the truck UUID) to read only the relevant files:

import trucktrack as tt

# Raw traces — filters by chunk_id hive partition
df = tt.scan_raw_truck("data/raw", truck_id).collect()

# Partitioned trips — filters by chunk_id in filename
df = tt.scan_partitioned_truck("data/partitioned", truck_id).collect()
df = tt.scan_partitioned_trip("data/partitioned", trip_id).collect()

# Map-matched results
df = tt.scan_matched_truck("data/matched", truck_id).collect()
df = tt.scan_matched_trip("data/matched", trip_id).collect()

ChunkIndex — persistent file-path index

For repeated queries, build an index once and reload it instantly in later sessions:

# First time — one rglob, then save to disk
idx = tt.ChunkIndex.build("data/partitioned")
idx.save()  # writes .chunk_index.json

# Later sessions — instant load, no filesystem scan
idx = tt.ChunkIndex.load("data/partitioned")
df = idx.scan_truck(truck_id).collect()
df = idx.scan_trip(trip_id).collect()

Visualization

One-call helpers to query, plot, and serve an interactive map:

from trucktrack.visualize import inspect_truck, inspect_trip

# All trips for a truck — opens a Flask server
inspect_truck("data/partitioned", truck_id)

# Filter to a date range
from datetime import date
inspect_truck("data/partitioned", truck_id,
              date_range=(date(2025, 1, 1), date(2025, 3, 1)))

# Single trip or multiple trips
inspect_trip("data/partitioned", trip_id)
inspect_trip("data/partitioned", [trip_id_1, trip_id_2])

# Use a ChunkIndex for fast lookups on large datasets
idx = tt.ChunkIndex.load("data/partitioned")
inspect_truck("data/partitioned", truck_id, index=idx)

# Raw traces or matched results
inspect_truck("data/raw", truck_id, stage="raw")
inspect_trip("data/matched", trip_id, stage="matched")

# Get the map object without serving (e.g. for Jupyter display)
m = inspect_trip("data/partitioned", trip_id, serve=False)

# Forward kwargs to plot_trace
inspect_trip("data/partitioned", trip_id, color_by="speed")

For more control, use the lower-level plot_trace, plot_trace_layers, save_map, and serve_map functions directly from trucktrack.visualize.

Dev workflow

Task Command
Build maturin develop
Tests pytest tests/ -v
Lint Python ruff check python/ tests/
Format Python ruff format python/ tests/
Lint Rust cargo clippy --all-targets --all-features -- -D warnings
Format Rust cargo fmt --all
Type-check mypy python/trucktrack
Build wheel maturin build --release

Project details


Download files

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

Source Distribution

trucktrack-0.1.6.tar.gz (147.3 kB view details)

Uploaded Source

Built Distributions

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

trucktrack-0.1.6-cp311-abi3-win_amd64.whl (14.2 MB view details)

Uploaded CPython 3.11+Windows x86-64

trucktrack-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.6 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

trucktrack-0.1.6-cp311-abi3-macosx_11_0_arm64.whl (14.1 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file trucktrack-0.1.6.tar.gz.

File metadata

  • Download URL: trucktrack-0.1.6.tar.gz
  • Upload date:
  • Size: 147.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trucktrack-0.1.6.tar.gz
Algorithm Hash digest
SHA256 a96a0386cca5e4379f2bafc56afdf4acc1f5d91053cdbe7d0d1a9a851eae0f9e
MD5 45ad071b3530ffc7ce6731181d3b0267
BLAKE2b-256 75832822082060141db6e8dffb31045e2f56422e1274756f96f56a78f4db64a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for trucktrack-0.1.6.tar.gz:

Publisher: publish.yml on twedl/trucktrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trucktrack-0.1.6-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: trucktrack-0.1.6-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 14.2 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trucktrack-0.1.6-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2265d2dabd324c7475970c57c3c4bac49e4ece667e5ddbaf7593f857de780bd0
MD5 fa4e556bf8104d88318105e6d6850372
BLAKE2b-256 9abecb0fdc560c1493a83b1768183ff39fdd53a2f66306384fbf5627219e1bb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for trucktrack-0.1.6-cp311-abi3-win_amd64.whl:

Publisher: publish.yml on twedl/trucktrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trucktrack-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for trucktrack-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dc81e38bc7025cca826940d9220f836273db43dca595588277c9263d2e91863f
MD5 67bfa54f214e801db4c3fcf60df3b18a
BLAKE2b-256 540fce02efe6f0d3334e3be227cf0f72e8e4a818d1a34664ea04cbadcc3cc854

See more details on using hashes here.

Provenance

The following attestation bundles were made for trucktrack-0.1.6-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on twedl/trucktrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trucktrack-0.1.6-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for trucktrack-0.1.6-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa8063ccdb0dcba4143d2f63d53c0676eeb986e313b4ef4d4187d0bf0f532962
MD5 8acdb64085c1f544ef98f522f024f13c
BLAKE2b-256 381bcfeca2841e22ef4601d4c11a7a582e97efa46b19ec85a0a28d3c1c7e0d69

See more details on using hashes here.

Provenance

The following attestation bundles were made for trucktrack-0.1.6-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: publish.yml on twedl/trucktrack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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