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.0

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.0
File Size Uploaded
odds_tools-0.1.0.tar.gz 15.2 kB Details

Built distribution (wheel)

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

Total release size: 30.4 kB

Release files / odds_tools-0.1.0.tar.gz

Download URL odds_tools-0.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ed8fafb9057819c3e8eb4618ce6e7b10f3d787346a522c97ebd65799860b78c2
BLAKE2b-256 checksum
How to use checksums
933bd240711b86874b5fc899efc1cbd0b1c7a300025def8eba8665f37bfc79fc
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.0-py3-none-any.whl

Download URL odds_tools-0.1.0-py3-none-any.whl
Size 15.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
220d38724387b541325ca9f8791735dd04f5272399282aed29a08cc088b40f32
BLAKE2b-256 checksum
How to use checksums
9fceac349b84a41c5d3d7fa0b6b6e1a0dc7ce827e44f334d1e765b434a35cb40
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

0.1.1

2 release files

This release

0.1.0 This release

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