A Riot API wrapper specifically for League of Legends.
Project description
pyke
pyke is a production-ready Riot API wrapper with intelligent rate limiting and robust error handling, specifically designed for League of Legends.
Key Features
- Smart Rate Limiting - Dynamic request throttling based on API headers to maximize throughput while preventing 429 errors
- Resilient Retry Logic - Retry strategies for rate limits and server errors with intelligent exponential backoff
- Type-Safe - Full Pydantic model support with comprehensive type hints for autocompletion and validation
- Pythonic API - Clean, intuitive interface that mirrors Riot's API structure exactly
- Production Logging - Standard Python logging integration with configurable levels
- Highly Configurable - Customize timeouts, retry limits, rate limiting behavior, and more
Installation
Install the latest version directly from PyPI:
pip install pyke-lol
Note: You need Python 3.9+ to use pyke.
Quickstart
from pyke import Continent, Pyke, exceptions
# Initialize the API
api = Pyke("RGAPI-...")
# Every pyke method follows the same convention as the Riot API
# For example account/v1/accounts/by-riot-id/{gameName}/{tagLine} becomes:
account = api.account.by_riot_id(Continent.EUROPE, "saves", "000")
# Every response is a Pydantic model with dot notation access
print(f"Riot ID: {account.game_name}#{account.tag_line}")
print(f"PUUID: {account.puuid}")
# Pydantic models provide convenient serialization
print(account.model_dump_json()) # JSON string
print(account.model_dump()) # Python dictionary
# pyke throws typed exceptions matching Riot API error codes
try:
region = api.account.region_by_puuid(Continent.EUROPE, account.puuid)
except exceptions.DataNotFound as e:
print(e) # Output: Data not found (Error Code: 404)
quit()
print(f"PUUID: {region.puuid}")
print(f"Game: {region.game}")
print(f"Region: {region.region}")
Configuration
pyke offers extensive configuration options for production use:
from pyke import Pyke
api = Pyke(
api_key="RGAPI-...",
smart_rate_limiting=True, # Enable intelligent rate limiting (default: True)
timeout=60, # Request timeout in seconds (default: 60)
max_rate_limit_retries=5, # Max retries for 429 errors (default: 5)
max_server_error_retries=3, # Max retries for 502/503/504 (default: 3)
)
Smart Rate Limiting
pyke's rate limiting algorithm analyzes response headers to:
- Calculate optimal wait times between requests
- Maximize throughput without hitting rate limits
- Automatically respect
Retry-Afterheaders on 429 responses
Result: Zero rate limit violations while maintaining maximum request speed.
Intelligent Retry Logic
pyke uses separate retry strategies for different error types:
Rate Limit Errors (429):
- Independent retry counter (default: 5 attempts)
- Respects
Retry-Afterheader from API - Logs retry progress:
Rate limit retries: 2/5
Server Errors (502/503/504):
- Separate retry counter (default: 3 attempts)
- Error-specific exponential backoff:
- 504 Gateway Timeout: 10s base (10s → 20s → 40s) - longer recovery for backend timeouts
- 502/503 Server Errors: 5s base (5s → 10s → 20s) - faster recovery for transient issues
- Prevents infinite retry loops while maintaining resilience
Logging
pyke uses Python's standard logging module for comprehensive diagnostics:
import logging
from pyke import Pyke
# Configure logging before creating Pyke instance
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
datefmt="%H:%M:%S",
)
api = Pyke("RGAPI-...")
Log Levels
- DEBUG: Detailed diagnostic information
- INFO: Request URLs with rate limit tracking:
(45/100) - https://na1.api.riotgames.com/... - WARNING: Retries, rate limiting, malformed API responses
- ERROR: Critical failures
Common Configurations
# Production (quiet) - only warnings and errors
logging.basicConfig(level=logging.WARNING)
# Development (verbose) - see all requests
logging.basicConfig(level=logging.INFO)
# Debugging - maximum verbosity
logging.basicConfig(level=logging.DEBUG)
# Completely silent
logging.getLogger('pyke').setLevel(logging.CRITICAL)
# Log to file
logging.basicConfig(
level=logging.INFO,
filename="api_requests.log",
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)
Advanced Features
Type Safety with Pydantic Models
All API responses are Pydantic models with full type hints:
from pyke import Pyke, Region
api = Pyke("RGAPI-...")
account = api.account.by_riot_id(Continent.EUROPE, "saves", "000")
summoner = api.summoner.by_puuid(Region.EUW, account.puuid)
# Dot notation access with autocomplete
print(summoner.puuid) # Type: str
print(summoner.summoner_level) # Type: int
print(summoner.profile_icon_id) # Type: int
# JSON serialization
json_str = summoner.model_dump_json()
dict_data = summoner.model_dump()
Custom Exception Handling
pyke provides typed exceptions for all HTTP status codes:
from pyke import exceptions
try:
summoner = api.summoner.by_puuid(Region.EUW, "NonExistentPuuid")
except exceptions.DataNotFound as e:
print(f"Not found: {e}") # Data not found (Error Code: 404)
except exceptions.RateLimitExceeded as e:
print(f"Rate limited: {e}") # Rate limit exceeded after 5 retries (Error Code: 429)
except exceptions.InternalServerError as e:
print(f"Server error: {e}") # Internal server error (Error Code: 500)
Available exceptions:
BadRequest (400), Unauthorized (401), Forbidden (403), DataNotFound (404), MethodNotAllowed (405), UnsupportedMediaType (415), RateLimitExceeded (429), InternalServerError (500), BadGateway (502), ServiceUnavailable (503), GatewayTimeout (504)
Continental vs Regional Routing
pyke automatically handles Riot's routing requirements:
from pyke import Continent, Region
# Continental routing (Account-V1, Match-V5)
account = api.account.by_riot_id(Continent.EUROPE, "saves", "000")
# Regional routing (Summoner-V4, League-V4, etc.)
summoner = api.summoner.by_puuid(Region.EUW, account.puuid)
Continental Routing:
AMERICAS: NA, BR, LAN, LASASIA: KR, JPEUROPE: EUNE, EUW, ME1, TR, RUSEA: OCE, SG2, TW2, VN2
Complete Feature List
- Smart Rate Limiting - Dynamic throttling based on API headers
- Dual Retry Strategies - Separate 429 and 50x retry logic with exponential backoff
- Type-Safe Models - 97 Pydantic models with full type hints
- Production Logging - Standard Python logging with configurable levels
- Custom Exceptions - 11 typed exception classes for precise error handling
- Continental Routing - Automatic routing for Account/Match endpoints
- Configurable Timeouts - Adjust request timeouts for slow endpoints
- Mirror API Design - Intuitive mapping to Riot's API structure
- Pythonic Interface - Clean, idiomatic Python code
- 94% Test Coverage - Comprehensive integration test suite
- Python 3.9-3.14 - Tested across 6 Python versions
Documentation & Resources
- API Documentation - Complete API reference with examples
- Examples Directory - 15+ working examples covering all features
- PyPI Package - Official package distribution
- GitHub Repository - Source code and issue tracking
Contributing & Support
Found a bug or have a feature request? Open an issue on GitHub.
For questions or help, reach out on Discord: .irm
License
MIT License - see LICENSE.txt for details.
Made with ❤️ for the League of Legends developer community
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 pyke_lol-2.1.0.tar.gz.
File metadata
- Download URL: pyke_lol-2.1.0.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7f130fd228eca33ca7e21a3dd413818fee2f52fb8229f0dfe5f2229edebd704
|
|
| MD5 |
1c3a0fc103b2f83073083eea71c7bde4
|
|
| BLAKE2b-256 |
dc09661097acd82d1655095d2fc3a1f987160d0007b521a0e89d816230c6485d
|
Provenance
The following attestation bundles were made for pyke_lol-2.1.0.tar.gz:
Publisher:
python-publish.yml on diodemusic/pyke
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyke_lol-2.1.0.tar.gz -
Subject digest:
b7f130fd228eca33ca7e21a3dd413818fee2f52fb8229f0dfe5f2229edebd704 - Sigstore transparency entry: 660732766
- Sigstore integration time:
-
Permalink:
diodemusic/pyke@a79c58a8dc85dc67d9e2583b95f3825bc34b92ea -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/diodemusic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a79c58a8dc85dc67d9e2583b95f3825bc34b92ea -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyke_lol-2.1.0-py3-none-any.whl.
File metadata
- Download URL: pyke_lol-2.1.0-py3-none-any.whl
- Upload date:
- Size: 49.6 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 |
99f4311b7b426ec07b45e7d77ff3eda3348431aa58b84a542482830c24d173d7
|
|
| MD5 |
6c872594a941aa43d0ee5fb444d8d0d1
|
|
| BLAKE2b-256 |
e7c27d655881c287e3604288b05f49af796d0aab3cbcb554501490ffe6a78739
|
Provenance
The following attestation bundles were made for pyke_lol-2.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on diodemusic/pyke
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyke_lol-2.1.0-py3-none-any.whl -
Subject digest:
99f4311b7b426ec07b45e7d77ff3eda3348431aa58b84a542482830c24d173d7 - Sigstore transparency entry: 660732768
- Sigstore integration time:
-
Permalink:
diodemusic/pyke@a79c58a8dc85dc67d9e2583b95f3825bc34b92ea -
Branch / Tag:
refs/tags/v2.1.0 - Owner: https://github.com/diodemusic
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a79c58a8dc85dc67d9e2583b95f3825bc34b92ea -
Trigger Event:
release
-
Statement type: