Modern async Python wrapper for the OpenDota API with full type support
Project description
Python OpenDota SDK
A modern, async Python wrapper for the OpenDota API with full type safety and comprehensive coverage.
Features
- Async/await support - Built with
httpxfor modern async Python applications - Type safety - Full type hints and Pydantic models for all API responses
- Comprehensive coverage - Support for matches, players, heroes, and more endpoints
- Rate limiting aware - Handles API rate limits gracefully with proper error handling
- Simple API - Clean, intuitive interface following Python best practices
- Well tested - Comprehensive test suite with real API integration tests
- Python 3.9+ - Compatible with modern Python versions
Installation
pip install python-opendota-sdk
Or with uv:
uv add python-opendota-sdk
Quick Start
import asyncio
from opendota import OpenDota
async def main():
async with OpenDota() as client:
# Get recent public matches
matches = await client.get_public_matches()
print(f"Found {len(matches)} recent matches")
# Get detailed match data
match = await client.get_match(matches[0].match_id)
print(f"Duration: {match.duration // 60}m {match.duration % 60}s")
print(f"Winner: {'Radiant' if match.radiant_win else 'Dire'}")
# Get all heroes
heroes = await client.get_heroes()
print(f"Total heroes: {len(heroes)}")
asyncio.run(main())
Authentication
The OpenDota API supports optional API keys for higher rate limits:
# Option 1: Environment variable
export OPENDOTA_API_KEY="your-api-key"
# Option 2: Direct initialization
client = OpenDota(api_key="your-api-key")
Rate Limits:
- Free tier: 2,000 calls/day, 60 calls/minute
- With API key: Unlimited calls, higher rate limits
Output Formats
Choose between structured Pydantic models or raw JSON dictionaries:
# Pydantic models (default) - Full type safety
client = OpenDota(format='pydantic')
matches = await client.get_public_matches()
print(matches[0].match_id) # Type-safe access
# JSON dictionaries - Direct API response
client = OpenDota(format='json')
matches = await client.get_public_matches()
print(matches[0]['match_id']) # Dict access
API Reference
Matches
async with OpenDota() as client:
# Get detailed match data
match = await client.get_match(8461956309)
# Get recent public matches with MMR filter
high_mmr = await client.get_public_matches(mmr_ascending=4000)
# Get professional matches
pro_matches = await client.get_pro_matches()
Players
async with OpenDota() as client:
# Get player profile
player = await client.get_player(70388657)
print(f"Player: {player.profile.personaname}")
print(f"Rank: {player.rank_tier}")
# Get player matches with filters
pudge_matches = await client.get_player_matches(
account_id=70388657,
hero_id=14, # Pudge
limit=10,
win=1 # Only wins
)
Heroes
async with OpenDota() as client:
# Get all heroes
heroes = await client.get_heroes()
# Get hero statistics
hero_stats = await client.get_hero_stats()
for hero in hero_stats[:5]:
if hero.pro_pick:
winrate = hero.pro_win / hero.pro_pick * 100
print(f"{hero.localized_name}: {winrate:.1f}% WR")
Teams
async with OpenDota() as client:
# Get all teams
teams = await client.get_teams()
print(f"Total teams: {len(teams)}")
# Get specific team details
team = await client.get_team(8599101) # Team Spirit
print(f"{team['name']}: {team['rating']} rating")
# Get team roster
players = await client.get_team_players(8599101)
for player in players[:5]:
print(f" {player['name']}: {player['games_played']} games")
# Get team match history
matches = await client.get_team_matches(8599101, limit=10)
Pro Players
async with OpenDota() as client:
# Get all professional players
pro_players = await client.get_pro_players()
print(f"Total pro players: {len(pro_players)}")
# Filter by team
spirit_players = [p for p in pro_players if p.get('team_id') == 8599101]
Leagues
async with OpenDota() as client:
# Get all leagues/tournaments
leagues = await client.get_leagues()
premium = [l for l in leagues if l.get('tier') == 'premium']
# Get league details
league = await client.get_league(15728) # TI
# Get league matches
matches = await client.get_league_matches(15728, limit=50)
# Get teams in a league
teams = await client.get_league_teams(15728)
Available Endpoints
| Category | Method | Description |
|---|---|---|
| Matches | get_match(match_id) |
Get detailed match data |
get_public_matches(**filters) |
Get public matches | |
get_pro_matches(**filters) |
Get professional matches | |
get_parsed_matches(**filters) |
Get parsed match data | |
| Players | get_player(account_id) |
Get player profile |
get_player_matches(account_id, **filters) |
Get player match history | |
| Heroes | get_heroes() |
Get all heroes data |
get_hero_stats() |
Get hero statistics | |
| Teams | get_teams() |
Get all teams |
get_team(team_id) |
Get team details | |
get_team_players(team_id) |
Get team roster | |
get_team_matches(team_id, limit) |
Get team match history | |
| Pro Players | get_pro_players() |
Get all professional players |
| Leagues | get_leagues() |
Get all leagues/tournaments |
get_league(league_id) |
Get league details | |
get_league_matches(league_id, limit) |
Get league matches | |
get_league_teams(league_id) |
Get teams in a league |
Error Handling
from opendota.exceptions import (
OpenDotaAPIError,
OpenDotaNotFoundError,
OpenDotaRateLimitError
)
try:
match = await client.get_match(invalid_id)
except OpenDotaNotFoundError:
print("Match not found")
except OpenDotaRateLimitError:
print("Rate limit exceeded")
except OpenDotaAPIError as e:
print(f"API error: {e}")
Development
# Clone the repository
git clone https://github.com/DeepBlueCoding/python-opendota-sdk.git
cd python-opendota-sdk
# Install with development dependencies
uv sync --group dev
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=opendota
# Type checking
uv run mypy src/
# Linting
uv run ruff check src/ tests/
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
Acknowledgments
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 python_opendota_sdk-7.40.3.tar.gz.
File metadata
- Download URL: python_opendota_sdk-7.40.3.tar.gz
- Upload date:
- Size: 53.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5e292e6bdccf2ec2e3231003720684c949ef9633efe26db78bea0680fa56302
|
|
| MD5 |
a07d7c1c0ee15f4675eb124b1b631392
|
|
| BLAKE2b-256 |
5fca031b29cb745baf41f0f18d51f07766807d62f512d5a5aaae002a1e2e82f6
|
Provenance
The following attestation bundles were made for python_opendota_sdk-7.40.3.tar.gz:
Publisher:
publish.yml on DeepBlueCoding/python-opendota-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_opendota_sdk-7.40.3.tar.gz -
Subject digest:
e5e292e6bdccf2ec2e3231003720684c949ef9633efe26db78bea0680fa56302 - Sigstore transparency entry: 782296845
- Sigstore integration time:
-
Permalink:
DeepBlueCoding/python-opendota-sdk@fee7206024cef91ec25ed03bb09572a0fde4ac7c -
Branch / Tag:
refs/tags/v7.40.3 - Owner: https://github.com/DeepBlueCoding
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fee7206024cef91ec25ed03bb09572a0fde4ac7c -
Trigger Event:
push
-
Statement type:
File details
Details for the file python_opendota_sdk-7.40.3-py3-none-any.whl.
File metadata
- Download URL: python_opendota_sdk-7.40.3-py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb904f7da4b389dbcd94982b64683064a88c6dad220693f08e821dc75907fbef
|
|
| MD5 |
d5285debb2f120137078f8dea1fe1d14
|
|
| BLAKE2b-256 |
204eac14d9f02a035607cfd65be869b25c12713b3d170789e924335cea5fb495
|
Provenance
The following attestation bundles were made for python_opendota_sdk-7.40.3-py3-none-any.whl:
Publisher:
publish.yml on DeepBlueCoding/python-opendota-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
python_opendota_sdk-7.40.3-py3-none-any.whl -
Subject digest:
eb904f7da4b389dbcd94982b64683064a88c6dad220693f08e821dc75907fbef - Sigstore transparency entry: 782296846
- Sigstore integration time:
-
Permalink:
DeepBlueCoding/python-opendota-sdk@fee7206024cef91ec25ed03bb09572a0fde4ac7c -
Branch / Tag:
refs/tags/v7.40.3 - Owner: https://github.com/DeepBlueCoding
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fee7206024cef91ec25ed03bb09572a0fde4ac7c -
Trigger Event:
push
-
Statement type: