Skip to main content

odds-tools (Python)

Dependency-free betting-odds math: format conversion, bookmaker margin, no-vig fair odds (multiplicative, additive, power, Shin), accumulators, system bets, Kelly staking, expected value and arbitrage. Typed, tested, Python 3.9+.

The same API is available for JavaScript/TypeScript as the odds-tools npm package; both are tested against one shared set of test vectors.

pip install odds-tools

Examples

from odds_tools import (
    convert,
    format_american,
    decimal_to_american,
    margin,
    fair_odds,
    fair_probabilities,
    accumulator_payout,
    system_bet,
    system_payout,
    expected_value,
    kelly_stake,
    arbitrage,
    round_half_up,
    OddsError,
)

# Conversions: decimal, fractional, american, hongkong, indonesian, malay, probability
convert("5/2", "fractional", "decimal")  # 3.5
convert(-110, "american", "fractional")  # '10/11'
convert(1.5, "hongkong", "malay")  # -0.667
format_american(decimal_to_american(1.91))  # '-110'

# Margin and fair odds of one market (1X2)
prices = [1.36, 5.35, 9.4]
margin(prices)  # 0.0286 -> 2.86 %
fair_odds(prices)  # [1.399, 5.503, 9.669]  multiplicative
fair_probabilities(prices, "shin")  # [0.723, 0.178, 0.099]

# Accumulator with a void leg, and a 2/3 system bet
accumulator_payout(10, [1.91, 1.83, 2.05], ["win", "void", "win"])  # 39.155
system_bet([1.9, 2.1, 2.4], 2, 30)  # 3 bets of 10.0, max payout 135.9
system_payout([1.9, 2.1, 2.4], 2, 30, ["win", "win", "lose"])  # 39.9

# Value and staking
expected_value(2.2, probability=0.5, stake=100)  # 10.0
kelly_stake(1000, 2.2, probability=0.5, fraction=0.5)  # 41.67 (half Kelly)

# Arbitrage across bookmakers, stakes rounded to cents
arb = arbitrage([2.1, 2.05], total_stake=100, decimals=2)
arb.stakes, arb.profit  # (49.4, 50.6), 3.73

round_half_up(2.675, 2)  # 2.68 (built-in round gives 2.67)

try:
    convert(50, "american", "decimal")
except OddsError as exc:  # OddsError is a ValueError
    print(exc)  # american odds must be >= +100 or <= -100 (got 50)

Outputs in comments are rounded; functions return full-precision floats.

Edge cases

  • Decimal odds must be > 1; 0, 1.0, negatives, NaN, infinities, booleans and strings raise OddsError.
  • probability_to_decimal needs 0 < p < 1; expected_value and kelly_* accept 0 <= p <= 1.
  • American odds between −100 and +100 are invalid; decimal_to_american(2.0) returns +100.
  • The additive method raises if a long shot would get a non-positive probability; the Shin method needs an overround >= 1.
  • Kelly never returns a negative stake (no edge -> 0).

Full documentation, formulas and references: https://github.com/SportApi-net/odds-tools#readme

Need live odds data?

odds-tools needs no API key and works with prices from any source. For a commercial feed of pre-match and live decimal odds, see SportAPI and the SportAPI documentation (from $30/month, free 2-day trial; get a key via Telegram).

License

MIT © 2026 SportAPI

Metadata

Release files for odds-tools 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for odds-tools 0.1.1
File Size Uploaded
odds_tools-0.1.1.tar.gz 15.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for odds-tools 0.1.1
File Interpreter ABI Platform
odds_tools-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / odds_tools-0.1.1.tar.gz

Download URL odds_tools-0.1.1.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
85031ce185bfcfbde154feef7d4b015eb375333e7309d6ec6cd3f434deede2cc
BLAKE2b-256 checksum
How to use checksums
fde6ca3ca63695b97551f6ccbf851a115147ac2e2b0526f1be03c6e9195dd5cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / odds_tools-0.1.1-py3-none-any.whl

Download URL odds_tools-0.1.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34f83e4a5521d1121a83966a8f016138716781cc23a21710891778e2c3b53baa
BLAKE2b-256 checksum
How to use checksums
79acb0fd95513a15c0bbc1c25085e6bab609aaf0645ac330884c3af36e45080f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page