Automated download of XD Segment data from RITIS or INRIX API, for daily or real time processing.
Project description
RITIS INRIX API
A Python package for automated retrieval of traffic data from RITIS and INRIX APIs for INRIX XD Segments.
Installation
pip install ritis-inrix-api
Core Functionality
This package provides tools to:
- Download Historical Data: Retrieve historical XD segment data from the RITIS API for specific date ranges or on a daily schedule.
- Fetch Real-Time Data: Get current traffic speeds from the INRIX API.
- Scrape Segment Geometries: Identify and retrieve XD segment geometries based on a list of latitude/longitude coordinates.
Examples
Here are some examples of how to use the package.
RITIS API: Download Historical Data
You can download data for a specific date range or set up a recurring daily download.
Download data for a single period
import os
from ritis_inrix_api import RITIS_Downloader
segments = [1236893704, 1236860943]
updater = RITIS_Downloader(
api_key=os.environ.get('RITIS_API_KEY'),
segments=segments, # can be list of IDs or path to a .txt file
columns=['speed', 'travel_time_seconds'], # Specify desired columns
start_time='06:00:00', #default is '00:00:00
end_time='06:15:00', #default is '23:59:00'
bin_size=5, #Enter 1, 5, 10, 15(default), or 60
units='seconds', #'seconds' or 'minutes'
#download_path='Data', #where to save data
)
# Returns a pandas DataFrame (unless download_path is specified)
df = updater.single_download('2025-09-01', '2025-09-02', 'test')
Sample Output
| xd_id | measurement_tstamp | speed | travel_time_seconds | |
|---|---|---|---|---|
| 0 | 1236860943 | 2025-09-01 06:00:00 | 25 | 11.95 |
| 1 | 1236860943 | 2025-09-01 06:05:00 | 25 | 11.95 |
| 2 | 1236860943 | 2025-09-01 06:10:00 | 25 | 11.95 |
Set up automated daily downloads
This will download data from the last run date through yesterday one day at a time and save it as Parquet files at the specified download path. This option is intended to run daily via a scheduler like cron or Windows Task Scheduler.
import os
from ritis_inrix_api import RITIS_Downloader
updater = RITIS_Downloader(
api_key=os.environ.get('RITIS_API_KEY'),
download_path='Data', # Data will be saved in this directory
segments='sample_XD_segments.txt', # Path to a file with segment IDs
last_run_path='last_run.txt' # Path for text file containing last run datetime
)
updater.daily_download()
INRIX API: Fetch Real-Time Speeds
import os
from ritis_inrix_api import INRIX_Downloader
inrix_downloader = INRIX_Downloader(
app_id=os.environ.get('INRIX_APP_ID'),
hash_token=os.environ.get('INRIX_HASH_TOKEN'),
segments_path='sample_XD_segments.txt'
)
# Returns a pandas DataFrame
speed_data = inrix_downloader.get_speed_data()
Sample Output
| code | type | speed | average | |
|---|---|---|---|---|
| 0 | 1236893704 | XDS | 53 | 52 |
| 1 | 1236860943 | XDS | 21 | 19 |
Geometry Scraper: Find Segments and Geometries
This tool finds XD segment geometries within a specified radius of given latitude/longitude points.
How to get the authentication cookie
The Geometry Scraper requires a valid browser cookie from a logged-in RITIS session to authenticate its requests. Open network tab in dev tools look for a request that has a cookie, copy and paste the cookie when prompted in the console.
Example Usage
from ritis_inrix_api import GeometryScraper
# A list of (latitude, longitude) tuples
locations = [
(42.34072155027376, -122.89930147132378),
(44.3029045246138, -120.842181329508),
# ... more locations
]
# The scraper will prompt you to paste the cookie into the console
scraper = GeometryScraper()
geometry_data = scraper.process_locations(locations, buffer_size=50) # buffer size in yards
# Save the new segment IDs to a file
segments = list(geometry_data['segID'])
with open('Map_Data/XD_Segments.txt', 'w') as f:
f.write(','.join(map(str, segments)))
Sample Output
The script will print progress messages as it runs:
Processing 1002 locations in batches of 500
Processing batch 1
Processing batch 2
Processing batch 3
Combining all batches into a single DataFrame
There were 5008 segments found for the provided signals.
The final geometry_data DataFrame will look like this:
| zip | country | segID | bearing | county | ... | coordinates | |
|---|---|---|---|---|---|---|---|
| 0 | 97051 | USA | 1237027426 | E | COLUMBIA | ... | [[-122.8316, 45.84865], [-122.83134, 45.84852], ...] |
| 1 | 97756 | USA | 1237004066 | S | DESCHUTES | ... | [[-121.19391, 44.24292], [-121.1941, 44.2427], ...] |
| 2 | 97527 | USA | 125164532 | E | JOSEPHINE | ... | [[-123.32078, 42.42779], [-123.32054, 42.42772], ...] |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ritis_inrix_api-1.0.0.tar.gz.
File metadata
- Download URL: ritis_inrix_api-1.0.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6a5617b48af1f035763d422300a34caf8bcdcfaa272c6239013a02bb625fd1b
|
|
| MD5 |
cd3f724f0a21afbd108cf41643c7122d
|
|
| BLAKE2b-256 |
d225b5d9401d7d3d3ab95fb040c61a1fa2ab4621abb05cf867ff42d6d2158eb2
|
Provenance
The following attestation bundles were made for ritis_inrix_api-1.0.0.tar.gz:
Publisher:
pr-tests.yml on ShawnStrasser/RITIS_INRIX_API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ritis_inrix_api-1.0.0.tar.gz -
Subject digest:
b6a5617b48af1f035763d422300a34caf8bcdcfaa272c6239013a02bb625fd1b - Sigstore transparency entry: 496716934
- Sigstore integration time:
-
Permalink:
ShawnStrasser/RITIS_INRIX_API@3c09fd41d37d14e805bee0d8029868f5910426d6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ShawnStrasser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pr-tests.yml@3c09fd41d37d14e805bee0d8029868f5910426d6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file ritis_inrix_api-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ritis_inrix_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3880123d16aca2f454f7c9c98b19b02884562e09cb8840bc90ec1cb4f7e441b
|
|
| MD5 |
108fead2c1b79e25dd27d4c16141e02c
|
|
| BLAKE2b-256 |
2aae346a5997e6a78fb44252a4ec65e1a7c97f1cf303a0ea907fb3318f7ceb0e
|
Provenance
The following attestation bundles were made for ritis_inrix_api-1.0.0-py3-none-any.whl:
Publisher:
pr-tests.yml on ShawnStrasser/RITIS_INRIX_API
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ritis_inrix_api-1.0.0-py3-none-any.whl -
Subject digest:
c3880123d16aca2f454f7c9c98b19b02884562e09cb8840bc90ec1cb4f7e441b - Sigstore transparency entry: 496716969
- Sigstore integration time:
-
Permalink:
ShawnStrasser/RITIS_INRIX_API@3c09fd41d37d14e805bee0d8029868f5910426d6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ShawnStrasser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pr-tests.yml@3c09fd41d37d14e805bee0d8029868f5910426d6 -
Trigger Event:
push
-
Statement type: