AlphaLoops Freight SDK — Python client for the FMCSA carrier data API
Project description
AlphaLoops Freight SDK
The official Python SDK for the AlphaLoops FMCSA API — access carrier profiles, fleet data, inspections, crash history, contacts, and more.
Installation
pip install alphaloops-freight-sdk
Quick Start
from alphaloops.freight import AlphaLoops
al = AlphaLoops(api_key="ak_...")
# Look up a carrier by DOT number
carrier = al.carriers.get("2247505")
print(carrier.legal_name, carrier.total_trucks)
# Search for carriers by name
results = al.carriers.search("Swift Transportation")
for r in results.results:
print(r.legal_name, r.dot_number, r.confidence)
# Fleet data
trucks = al.fleet.trucks("2247505")
for truck in trucks.results:
print(truck.vin, truck.make, truck.model_year)
Authentication
The SDK resolves your API key in this order:
- Explicit parameter —
AlphaLoops(api_key="ak_...") - Environment variable —
ALPHALOOPS_API_KEY - Config file —
~/.alphaloops
To set up via environment variable:
export ALPHALOOPS_API_KEY=ak_your_key_here
Or create a config file at ~/.alphaloops:
api_key=ak_your_key_here
Get your API key at runalphaloops.com.
Resources
Carriers — al.carriers
# Full carrier profile (200+ fields)
carrier = al.carriers.get("2247505")
# Look up by MC number
carrier = al.carriers.get_by_mc("624748")
# Field projection — only fetch what you need
carrier = al.carriers.get("2247505", fields=["legal_name", "total_trucks", "total_drivers"])
# Fuzzy search with confidence scoring
results = al.carriers.search("JB Hunt", state="AR", limit=5)
# Authority history
history = al.carriers.authority("2247505")
# News and press mentions
news = al.carriers.news("2247505", start_date="2025-01-01")
Fleet — al.fleet
trucks = al.fleet.trucks("2247505", limit=100)
trailers = al.fleet.trailers("2247505", limit=100)
Inspections — al.inspections
inspections = al.inspections.list("2247505")
# Violations for a specific inspection
violations = al.inspections.violations("INS-12345")
Crashes — al.crashes
crashes = al.crashes.list("2247505", severity="FATAL", start_date="2024-01-01")
Contacts — al.contacts
# Find people at a carrier
contacts = al.contacts.search(dot_number="2247505", job_title_levels=["c_suite", "vp"])
# Enrich a contact (1 credit per new lookup, cached results are free)
enriched = al.contacts.enrich("contact_id_here")
print(enriched.email, enriched.phone)
Pagination
All list endpoints support manual pagination:
page1 = al.carriers.search("Swift", page=1, limit=10)
page2 = al.carriers.search("Swift", page=2, limit=10)
Auto-pagination iterators handle paging for you:
for truck in al.fleet.trucks_iter("2247505", limit=200):
print(truck.vin)
for inspection in al.inspections.list_iter("2247505"):
print(inspection.inspection_id)
The APIObject
All SDK methods return an APIObject — a lightweight dict wrapper that gives you attribute-style access to API responses without enforcing a rigid schema. The data you get is exactly what the API returns.
carrier = al.carriers.get("2247505")
# Attribute access
carrier.legal_name # "SWIFT TRANSPORTATION CO OF ARIZONA LLC"
carrier.total_trucks # 18752
# Dict access
carrier["dot_number"] # "2247505"
# Check for fields
"safety_rating" in carrier # True
# Serialize to JSON
import json
json.dumps(carrier.to_dict())
Error Handling
from alphaloops.freight import (
AlphaLoops,
AlphaLoopsAuthError,
AlphaLoopsNotFoundError,
AlphaLoopsRateLimitError,
AlphaLoopsPaymentError,
)
al = AlphaLoops()
try:
carrier = al.carriers.get("0000000")
except AlphaLoopsNotFoundError:
print("Carrier not found")
except AlphaLoopsAuthError:
print("Invalid API key")
except AlphaLoopsRateLimitError:
print("Rate limit exceeded — the SDK auto-retries on 429, so this is rare")
except AlphaLoopsPaymentError:
print("Enrichment credits exhausted")
The SDK automatically retries on transient errors (5xx, timeouts, connection errors) with exponential backoff. Rate limit (429) responses are retried after the Retry-After delay.
Configuration
al = AlphaLoops(
api_key="ak_...", # API key
base_url="https://api.runalphaloops.com", # API base URL
timeout=30, # Request timeout (seconds)
max_retries=3, # Max retry attempts
retry_base_delay=1.0, # Base delay for exponential backoff
)
The base URL can also be set via the ALPHALOOPS_BASE_URL environment variable.
API Documentation
Full API reference and endpoint details: runalphaloops.com/fmcsa-api/docs
License
MIT — see LICENSE for details.
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
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 alphaloops_freight_sdk-0.1.0.tar.gz.
File metadata
- Download URL: alphaloops_freight_sdk-0.1.0.tar.gz
- Upload date:
- Size: 14.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 |
aeba3e7afb378a7ee7d1729ec0166f8e132ac6d0acde8b4738fefda8831f52d5
|
|
| MD5 |
a43df725ba53be5417e3e97f1753f30d
|
|
| BLAKE2b-256 |
936115e7458f8a38be7b26ec543ba7015a58a54a37a2aa5dec9567e89feb6f95
|
Provenance
The following attestation bundles were made for alphaloops_freight_sdk-0.1.0.tar.gz:
Publisher:
publish.yml on RunAlphaLoop/freight-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphaloops_freight_sdk-0.1.0.tar.gz -
Subject digest:
aeba3e7afb378a7ee7d1729ec0166f8e132ac6d0acde8b4738fefda8831f52d5 - Sigstore transparency entry: 1071376766
- Sigstore integration time:
-
Permalink:
RunAlphaLoop/freight-sdk@f7444e0ac2e9f66acd9a9cb31d161653d27c0e11 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/RunAlphaLoop
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7444e0ac2e9f66acd9a9cb31d161653d27c0e11 -
Trigger Event:
release
-
Statement type:
File details
Details for the file alphaloops_freight_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alphaloops_freight_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 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 |
b91fbd49d90e9fdd3008f8cf8eb6704c7318edb8ac2a0d868674b8ff6ae7c0c3
|
|
| MD5 |
76cb23e65f3413658cb222b5a6cc16ad
|
|
| BLAKE2b-256 |
3c043d734c8a8dea58cf85a68fdc2f78d2a427b73786313aa88da3308c1a8db0
|
Provenance
The following attestation bundles were made for alphaloops_freight_sdk-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on RunAlphaLoop/freight-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
alphaloops_freight_sdk-0.1.0-py3-none-any.whl -
Subject digest:
b91fbd49d90e9fdd3008f8cf8eb6704c7318edb8ac2a0d868674b8ff6ae7c0c3 - Sigstore transparency entry: 1071376811
- Sigstore integration time:
-
Permalink:
RunAlphaLoop/freight-sdk@f7444e0ac2e9f66acd9a9cb31d161653d27c0e11 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/RunAlphaLoop
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f7444e0ac2e9f66acd9a9cb31d161653d27c0e11 -
Trigger Event:
release
-
Statement type: