Package containing tools to read and manipulate NASCAR data via the CF API.
Project description
nascar-api
A typed Python client for NASCAR's undocumented Content Feed (CF) API. Provides access to both historical and live race data across the Cup, Xfinity, and Truck series.
Built with Pydantic for data validation and tenacity for automatic retry logic.
Installation
pip install nascar-api
Or with Poetry:
poetry add nascar-api
Quick Start
from nascar_api.repos import HistoricNascarRepo
from nascar_api.enums import Series
repo = HistoricNascarRepo()
# Get all Cup Series races from 2024
races = repo.get_races(2024, Series.CUP)
for race in races:
print(f"{race.race_name} at {race.track_name} — Winner ID: {race.winner_driver_id}")
Features
Historical Data
from nascar_api.repos import HistoricNascarRepo
from nascar_api.enums import Series
repo = HistoricNascarRepo()
# Race schedules and results for any year/series
races = repo.get_races(2024, Series.CUP)
# Lap-by-lap timing data
lap_times = repo.get_lap_times(2024, Series.CUP, race_id=5161)
# Lap notes (cautions, incidents, flags)
lap_notes = repo.get_lap_notes(2024, Series.CUP, race_id=5161)
# Pit stop data with detailed timing and tire info
pit_stops = repo.get_pit_data(Series.CUP, race_id=5161)
# Full weekend feed (results, cautions, leaders, stages, pit reports)
weekend = repo.get_weekend_data(2024, Series.CUP, race_id=5161)
# Loop statistics (driver performance metrics)
loop_stats = repo.get_loopstats(2024, Series.CUP, race_id=5161)
Live Race Data
from nascar_api.repos import LiveNascarFeedRepo
from nascar_api.enums import Series
repo = LiveNascarFeedRepo()
# Current flag state across all active races
flags = repo.get_live_flags()
# Full live race feed (positions, speeds, pit stops, vehicle data)
feed = repo.get_live_feed()
for vehicle in feed.vehicles:
print(f"#{vehicle.vehicle_number} — P{vehicle.running_position}, "
f"Last Lap: {vehicle.last_lap_speed:.1f} mph")
# Live points standings
points = repo.get_live_points(Series.CUP, race_id=5161)
API Reference
Repositories
| Class | Description |
|---|---|
HistoricNascarRepo |
Historical race data (schedules, results, lap times, pit stops, weekend feeds, loop stats) |
LiveNascarFeedRepo |
Real-time race data (live flags, race feed, points standings) |
Models
| Model | Description |
|---|---|
RaceInfo |
Race metadata — schedule, track, distance, laps, cautions, speed, purse, broadcast info |
RaceLaps |
Per-driver lap-by-lap timing (lap times, speeds, running position) |
LapData |
Lap notes with flag states, incident notes, and involved drivers |
PitData |
Pit stop details — timing, tire changes, positions gained/lost |
WeekendInfo |
Full weekend container with race results and practice/qualifying runs |
WeekendRaceInfo |
Detailed race results, caution segments, race leaders, stage results, pit reports |
WeekendRunInfo |
Practice/qualifying session results |
LiveInfo |
Live race state — flag, lap, timing, and all vehicle telemetry |
FlagData |
Live flag state with timing and beneficiary info |
PointsData |
Championship points standings with stage breakdowns |
RaceLoopStat |
Race-level loop statistics with per-driver performance metrics |
Enums
| Enum | Values |
|---|---|
Series |
CUP (1), XFINITY (2), TRUCK (3) |
Flag |
GREEN (1), YELLOW (2), RED (3), WHITE (4), CHECKERED (5), HOT_TRACK (8), COLD_TRACK (9) |
Retry Behavior
All API requests automatically retry up to 3 times with a 2-second delay on transient failures (5xx errors, JSON decode errors). Requests that receive a 403 (data not available for that endpoint/year) do not retry.
Requirements
- Python 3.11+
- No API key required — NASCAR's CF API is publicly accessible
License
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 nascar_api-0.1.1.tar.gz.
File metadata
- Download URL: nascar_api-0.1.1.tar.gz
- Upload date:
- Size: 13.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76abe8066b9cd4136d74fc987d1a0a6ffc843e4e5ddf42c76cd27cb8231bb468
|
|
| MD5 |
cbccf6c73aa9b62fdbaac3bba7f1544a
|
|
| BLAKE2b-256 |
4c7faa128c5a2f3b01d6daf1142bd78a3ac65ff94f7fb89ea70ebbd7681483c1
|
Provenance
The following attestation bundles were made for nascar_api-0.1.1.tar.gz:
Publisher:
build-release.yml on TannerYohe/nascar-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nascar_api-0.1.1.tar.gz -
Subject digest:
76abe8066b9cd4136d74fc987d1a0a6ffc843e4e5ddf42c76cd27cb8231bb468 - Sigstore transparency entry: 1632011660
- Sigstore integration time:
-
Permalink:
TannerYohe/nascar-api@ef55dcdb4a118f3311ff95998648241843f0cf13 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TannerYohe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@ef55dcdb4a118f3311ff95998648241843f0cf13 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nascar_api-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nascar_api-0.1.1-py3-none-any.whl
- Upload date:
- Size: 20.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ec50f3b7769fa470c060559217094cf1c929139d3b0d4e680d21d588a8d44e3
|
|
| MD5 |
d7a1e7b0ed3c9b6eb38cbfddfe02f438
|
|
| BLAKE2b-256 |
f8d721363dbb5585cc146523897039110d036ccce35527f11f8e6d1fc837264d
|
Provenance
The following attestation bundles were made for nascar_api-0.1.1-py3-none-any.whl:
Publisher:
build-release.yml on TannerYohe/nascar-api
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nascar_api-0.1.1-py3-none-any.whl -
Subject digest:
3ec50f3b7769fa470c060559217094cf1c929139d3b0d4e680d21d588a8d44e3 - Sigstore transparency entry: 1632011690
- Sigstore integration time:
-
Permalink:
TannerYohe/nascar-api@ef55dcdb4a118f3311ff95998648241843f0cf13 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TannerYohe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-release.yml@ef55dcdb4a118f3311ff95998648241843f0cf13 -
Trigger Event:
push
-
Statement type: