Metadata-Version: 2.4
Name: openwec
Version: 0.3.1
Summary: Python SDK for endurance racing data — WEC, ELMS, ALMS, Le Mans Cup, IMSA
Author: Paloma C.
License-Expression: LicenseRef-Proprietary
Project-URL: Homepage, https://openwec.com
Project-URL: Documentation, https://api.openwec.com/docs
Project-URL: Repository, https://github.com/palomacdev/openwec
Project-URL: Bug Tracker, https://github.com/palomacdev/openwec/issues
Keywords: motorsport,endurance racing,WEC,Le Mans,ELMS,IMSA,timing data,lap times,pandas
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: pandas>=2.0
Provides-Extra: plotting
Requires-Dist: matplotlib>=3.7; extra == "plotting"
Provides-Extra: dev
Requires-Dist: matplotlib>=3.7; extra == "dev"
Requires-Dist: jupyter>=1.0; extra == "dev"
Requires-Dist: ipykernel>=6.0; extra == "dev"
Requires-Dist: twine>=5.0; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Dynamic: license-file

# openwec

**Python SDK for endurance racing data — WEC, ELMS, ALMS, Le Mans Cup, IMSA.**

Inspired by [FastF1](https://github.com/theOehrly/Fast-F1), OpenWEC gives you lap-by-lap timing data, stint analytics, and race results from endurance racing as pandas DataFrames — in one line.

→ **[openwec.com](https://openwec.com)** — Live dashboard  
→ **[api.openwec.com/docs](https://api.openwec.com/docs)** — API reference  
→ **[github.com/palomacdev/openwec](https://github.com/palomacdev/openwec)** — Source

---

## Installation

```bash
pip install openwec

# With plotting support
pip install openwec[plotting]
```

---

## Quick start

```python
import openwec

# Public endpoints work without a key.
# Request a free key at https://openwec.com/api-keys
openwec.configure(api_key="your-key-here")  # required for laps and analytics

# Load any session — WEC, ELMS, ALMS, Le Mans Cup, or IMSA
session = openwec.Session("WEC", 2026, "Le Mans", "Race")
print(session)
# Session(WEC 2026 LE MANS — Race, id=6556)

# Results as a DataFrame (no key needed)
results = session.results()
print(results[["position", "car_number", "car_class", "team", "drivers"]].head(10))

# Lap-by-lap data for one car (no key needed)
laps = session.laps(car="7")
print(laps[["lap_number", "lap_time_s", "s1_s", "s2_s", "s3_s"]].head())

# Endurance-specific: filter laps by driver within a shared-drive car
# (unique to endurance racing — not possible in FastF1)
conway_laps     = session.driver_laps("Conway", car="7")
kobayashi_laps  = session.driver_laps("Kobayashi", car="7")
print(f"Conway pace:    {conway_laps['lap_time_s'].median():.3f}s")
print(f"Kobayashi pace: {kobayashi_laps['lap_time_s'].median():.3f}s")

# Stints and pace
stints     = session.stints(car_class="HYPERCAR")
pace       = session.pace(car_class="HYPERCAR")
pit_window = session.pit_window(car="7")

# Plots (requires matplotlib)
session.plot_lap_evolution(car="7")
session.plot_stint_chart(car_class="HYPERCAR")
session.plot_gap_to_leader(car_class="HYPERCAR")
```

---

## Coverage

| Series | Seasons |
|--------|---------|
| FIA WEC | 2012–2026 |
| ELMS | 2012–2026 |
| ALMS (Asian) | 2022–2026 |
| Le Mans Cup | 2017–2026 |
| IMSA | 2014–2026 |

**2M+ laps** across all series.

---

## API key

Public endpoints (results, driver profiles, team profiles, driver search) require no key.  
Lap-by-lap data and analytics endpoints require a free API key.

→ **[Request a key at openwec.com/api-keys](https://openwec.com/api-keys)**

---

## Errors and rate limits

Reads made without a key share a per-minute budget. A sweep over many sessions
will reach it, and the API answers `429` with a `Retry-After`. Every failure
mode has its own exception, so you can tell them apart:

| Status | Exception | What it means |
|--------|-----------|---------------|
| 401 | `OpenWECAuthError` | no key, and this endpoint needs one |
| 403 | `OpenWECPermissionError` | the key is valid but not allowed here |
| 404 | `OpenWECNotFoundError` | no such session, driver or team |
| 429 | `OpenWECRateLimitError` | budget spent — carries `.retry_after` |
| 5xx | `OpenWECServerError` | the API failed; the request was fine |

All of them derive from `OpenWECError`.

```python
from openwec import OpenWECRateLimitError
import time

try:
    laps = session.laps()
except OpenWECRateLimitError as e:
    time.sleep(e.retry_after or 60)   # None means the API did not say
    laps = session.laps()
```

Or let the SDK wait for you. It is **off by default** — a library should not
block your notebook without being asked:

```python
openwec.configure(max_retries=3)          # wait out up to three 429s
openwec.configure(retry_max_wait=30)      # but never sleep more than 30s at once
```

A `Retry-After` longer than `retry_max_wait` raises instead of sleeping, and a
`429` without a `Retry-After` always raises — there is nothing to wait for.

Configuring a key raises your budget and removes the shared one.

---

## Session methods

| Method | Description | Key required |
|--------|-------------|-------------|
| `.results()` | Race classification as DataFrame | No |
| `.laps(car="7")` | Lap-by-lap data for one car | No |
| `.laps()` | Lap-by-lap data, whole session | **Yes** |
| `.driver_laps(name, car="7")` | Laps filtered by driver name ⚑ | No |
| `.driver_laps(name)` | Same, across the whole session | **Yes** |
| `.stints(car_class=None)` | Stint breakdown per car | No |
| `.gaps(car_class=None)` | Gap to leader evolution | No |
| `.pace(car_class=None)` | Average green-flag pace | **Yes** |
| `.pit_window(car=None)` | Optimal pit window estimate | **Yes** |
| `.plot_lap_evolution(car)` | Lap time chart | No |
| `.plot_stint_chart()` | Strategy/stint chart | No |
| `.plot_gap_to_leader()` | Gap to leader chart | No |

The line is what a page shows versus what a consumer extracts: one car's laps
draw a chart, a whole session's laps are a dataset. A key you *do* send is
always validated — an invalid one is refused with 401 even on a public method.

⚑ **Unique to endurance racing** — multiple drivers share a car. `driver_laps()` has no equivalent in FastF1.

---

## Example notebooks

| Notebook | Description |
|----------|-------------|
| [le_mans_2026.ipynb](examples/le_mans_2026.ipynb) | Full race analysis — results, pace, stints, plots |
| [driver_career.ipynb](examples/driver_career.ipynb) | Cross-series career analysis for a driver |

---

## License

Three different things, with three different answers. This page used to show
one word, and one word cannot tell them apart.

**The SDK code.** Versions 0.1.0 through 0.3.0 were published here under the
MIT License. That grant is irrevocable for the copies already distributed: if
you installed one of those versions, you keep the MIT rights to that code.
From 0.3.1 onward the SDK, like the rest of the project, is **proprietary —
all rights reserved**. The full text ships with the package, in `LICENSE`.

**The API service.** A key is permission to use the service. It is not a
licence to the project's source and grants no rights to anything behind the
endpoint. What the key allows comes with the key.

**The racing data.** It is not ours to license. It comes from Al Kamel Systems
public timing exports, and OpenWEC is not affiliated with Al Kamel, the ACO,
the FIA or IMSA. Results you compute from the data are yours; the dataset
itself is someone else's. See `DATA_POLICY.md`.
