Skip to content

About

Python client for ParlayAPI sports odds, with a one-request CSV demo. Full data uses your own API key and allowance for private research. MIT-licensed code; API data redistribution rights are not included.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

parlay-api

Python 3.9+ SDK for ParlayAPI. The default install has no runtime dependencies and includes a one-request odds-to-CSV starter.

Get your first CSV without a key

To try the comparison before installing Python, open the basketball quickstart in Colab and choose Run all. Two fictional bookmakers quote the Comets and Owls. The notebook shows which book offers the higher payout for each team. The default exercise makes no API calls.

En español, prueba el ejemplo de cuotas de la NBA en Colab para convertir dos precios ficticios en una tabla de pandas.

Install the 0.3.6 wheel for Python 3.9 or later, then make one public NBA request. The CSV keeps the source's fractional-second precision in the bookmaker and market update columns. Missing or invalid clocks leave the corresponding cell empty.

python -m pip install https://github.com/JacobiusMakes/parlay-api-python/releases/download/v0.3.6/parlay_api-0.3.6-py3-none-any.whl
python -m parlay_api --sport basketball_nba > odds.csv

Open odds.csv and look for an event, bookmaker, outcome and price. A header alone means there were no usable rows in this response. You can also inspect the NBA demo in your browser.

Turn your NBA CSV into an offline game-by-game report. See both team prices from each bookmaker, along with missing sides and market clocks. The kit includes a fictional report you can open immediately. Record the receipt time with your next NBA preview to compare two books at a deadline. The downloadable recorder also saves an HTML report and keeps earlier captures.

For a DataFrame, watch the five-minute Python walkthrough or open the notebook and transcript. The lesson starts with two fictional outcomes and shows how to keep each returned price with its event, bookmaker and observation time when available.

To try the available boards in sequence, use the sample finder:

python -m parlay_api --find-example > odds.csv

It checks NBA, MLB and NHL in order and moves on only when the previous board returned zero events. It stops on a nonempty board or an error, including a rate limit. Diagnostics go to stderr and the CSV goes to stdout. With no arguments the CLI still makes one MLB request. Both demo modes ignore any API key in the environment.

When your example has the fields you need, create an account for your own API key. Check account access and cost for the sport and market you plan to request.

The demo returns at most the first five US moneyline events, with a shared limit of 60 requests per hour per IP. Supported demo sports are baseball_mlb, basketball_nba, americanfootball_nfl, icehockey_nhl, soccer_epl and mma_mixed_martial_arts. The demo has no market, bookmaker or live filter. Availability varies by sport, event and source; a sample does not establish full coverage. An empty response produces a CSV header and a diagnostic.

CSV preserves source prices and source timestamps. Ambiguous duplicate groups and invalid outcomes are excluded with diagnostics on stderr. Missing timestamps stay empty; timestamps are not freshness guarantees. The starter makes no rankings or profit claims, and has no automatic retries, polling or key storage.

If your first request fails, prepare a private support report from the HTTP status, route and optional request ID. The example runs offline.

Serve a private FastAPI snapshot

Run the FastAPI coverage starter to read game and source counts from a local endpoint. Start with fictional NBA data, then use your server-side key for a single coverage snapshot. Refreshing the local endpoint reuses that snapshot.

Check which Python package is installed

The distribution name for pip is parlay-api. In Python, import parlay_api. Use the same interpreter for installation and for the command below:

python -c "from importlib.metadata import version; print(version('parlay-api'))"
python -m parlay_api --help

The wheel linked above reports 0.3.6. Compare that value with the version in your environment and the current PyPI listing. Both verification commands run locally. If a deadline matters to your report, keep the time you received the response alongside the source clock.

Backtest forecasts against the 2024 NBA Finals

Boston lost Game 4 by 38. How much better would a forecast look if you let the model revise it the next morning? Read the worked example or change a forecast in browser Python. The notebook uses official final scores and fictional probabilities. It runs without an API key.

Compare an existing odds integration

Run the local migration check against two saved NBA moneyline responses. It checks the request filters, event identity, bookmaker, outcome prices and timestamps your application requires. The fictional example runs with Python alone. Try an empty board or an HTTP 403 to see which check fails.

Plan a request schedule before polling

Use the free API workload planner to write down your active window, refresh interval, separately polled sports, requests per refresh and active days. Include every required endpoint and page. The planner needs no account or key and does not make API requests.

Leave credit cost unknown until you verify the unit cost for your exact request shape in the current documentation. The estimate uses your assumptions; it does not establish live coverage, entitlement or the freshness of returned records.

For several request shapes with different or unknown unit costs, use the offline request-budget kit. It includes a CSV template, exact JSON export and a self-contained notebook. Unpriced work keeps the total credit estimate unknown.

Continue with your own account

Create your own account, then set PARLAY_API_KEY in your terminal. Keep your key private. Explicitly add --full to make one account request and export it for your own analysis:

python -m parlay_api --full > my-odds.csv
python -m parlay_api --full --markets h2h,spreads,totals --no-include-live > pregame.csv

Account requests use US regions and American odds, with include_live=true explicit by default. --no-include-live requests pregame data. The same six sports are supported by the starter, and full mode accepts h2h, spreads and totals. Requested markets are not a promise that every event or book supplies them. Your account allowance applies; without --full, the command continues to use the demo even when a key is set.

Use the Odds workspace to configure a request and estimate refresh credits. Current plans, allowances and rate limits are at parlay-api.com/pricing. Choose capacity for your intended requests and refresh schedule; this starter does not start a scheduled job.

Use the Python client in your project

The library remains available for application code. Pass your key explicitly:

import os
from parlay_api import ParlayAPI

key = os.environ.get("PARLAY_API_KEY", "").strip()
if not key:
    raise SystemExit("Set PARLAY_API_KEY to the key for this account.")
client = ParlayAPI(api_key=key)
events = client.odds("baseball_mlb", regions="us", markets="h2h")
if not events:
    print("No events returned for this request.")
else:
    for event in events:
        print(event.get("id"), event.get("home_team"), event.get("away_team"))

For existing integrations, ParlayAPI() also accepts the legacy PARLAYAPI_KEY environment variable. The command-line starter uses PARLAY_API_KEY only.

Check game-line coverage before spending credits

In the repository version of the Python client, odds_coverage makes one authenticated, zero-credit request. For example, to check recent EPL moneylines for bet365 and Caesars:

import os
from parlay_api import ParlayAPI

key = os.environ.get("PARLAY_API_KEY", "").strip()
if not key:
    raise SystemExit("Set PARLAY_API_KEY to the key for this account.")
client = ParlayAPI(api_key=key)
filters = {"bookmakers": ["bet365", "caesars"], "markets": "h2h"}
report = client.odds_coverage("soccer_epl", **filters, fresh_within_seconds=900)
rows = {row["source"]: row for row in report["sources"]}
for book in filters["bookmakers"]:
    row = rows.get(book)
    if row and row["markets_with_h2h"] > 0:
        print(book, row["games_covered"], "games, latest age in seconds:", row["latest_age_seconds"])
    else:
        print(book, "no moneyline counted for this request")

Use each requested book's markets_with_h2h and games_covered to decide whether to make a separate, metered client.odds("soccer_epl", **filters) call for actual prices. Either book may be absent. A book with games_covered == 0 can still have games outside the requested window. The default is pregame. Use live=True for the in-play board or include_live=True for both.

The freshness cutoff accepts 60 to 86,400 seconds and applies to each book's last_update. The most recent age can include a verification of an unchanged price. total_games_covered counts distinct events on the board before the per-book freshness cutoff. The response includes the server's as_of time.

Read a final football score by event ID. Run the saved Portugal–U.S. 0–0 example locally, then try a pending match. The reader preserves zero and matches each score to the named team even when the away score arrives first.

The client includes sports, odds, events, scores, historical odds, player props, futures, usage and other endpoint methods. Check current API documentation for parameters, plan requirements and coverage. If migrating from another API, verify your actual request and response handling against the migration guide; endpoint similarities do not establish identical coverage or behavior.

from parlay_api import InvalidAPIKeyError, ParlayAPIError, RateLimitedError

try:
    events = client.odds("baseball_mlb", markets="h2h")
except InvalidAPIKeyError:
    print("Check the API key for this account.")
except RateLimitedError:
    print("Rate limit reached; review the request schedule.")
except ParlayAPIError as error:
    print(type(error).__name__)

Diagnose six first-response outcomes, including an exhausted allowance, a plan lookback, an empty selection and a stale market timestamp.

Practice choosing a next check with the offline first-response rehearsal. Its twelve invented cases distinguish authentication, access, rate-limit and transport outcomes, with explicit attempt and wait budgets. The Python command runs without keys or API requests.

After a successful SDK request, client.last_quota contains the returned usage headers. Header fields may be None when the service does not provide them.

Practice a disconnect, duplicate update and reconnect using the offline WebSocket replay. It runs with Python alone and includes a fictional price trace.

With the wheel above installed, add the WebSocket dependency with python -m pip install "websockets>=11.0". WebSocket access is Business tier and up; see the current docs before connecting.

Request delayed Pinnacle game lines

To request delayed pregame NBA moneylines, pass pinnacle_delayed as the only bookmaker. This is an authenticated REST odds request and normal odds credit charges apply.

import os
from parlay_api import ParlayAPI

key = os.environ.get("PARLAY_API_KEY", "").strip()
if not key:
    raise SystemExit("Set PARLAY_API_KEY to the key for this account.")
client = ParlayAPI(api_key=key)
events = client.odds("basketball_nba", markets="h2h", bookmakers="pinnacle_delayed")
print("Events returned:", len(events))

Prices are usually 1 to 16 minutes old. The service excludes prices older than 25 minutes, so the board can be empty. This delayed feed covers pregame REST game lines only. The standard live Pinnacle feed is unavailable. Current Pinnacle coverage disclosure

Existing examples

Compare a +120 quote with a +105 close in the worked Python notebook. Read the calculated price difference, then inspect how simulated books priced the same game at the close. The tables and chart open in your browser.

Load a historical closing-lines CSV into SQLite. Start with three fictional rows, run the missing-price query, then import a saved export into a new private database. No API request is needed for the workshop.

The installed command and the standalone odds_workspace.py download use the same source file. With no package installation, download that file and run python3 odds_workspace.py; the same flags apply. See the source.

The repository also contains:

These additional files are repository examples. Download or clone them separately; pip install parlay-api does not create an examples directory.

License and data use

The software is MIT licensed; see LICENSE. Installing or sharing this code grants no data distribution rights. API data use is governed by the applicable Terms and any written agreement. This starter is intended for personal analysis and does not offer a shared community feed. These tool defaults do not amend existing customer agreements. Each person running it should use their own account and key.

Development and support

From a checkout, run the standalone offline tests with python -m unittest discover -s examples -p 'test_odds_workspace.py'. After installing a built wheel into a clean environment, run python /absolute/path/to/tests/test_installed_package.py from outside the checkout to verify the installed entry point and replay the same fixture tests. All test requests are mocked.

Report bugs at GitHub issues or contact Support privately.

About

Python client for ParlayAPI sports odds, with a one-request CSV demo. Full data uses your own API key and allowance for private research. MIT-licensed code; API data redistribution rights are not included.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages