pyke

pyke

PyPI - Version Documentation

pyke is a thin async Riot API wrapper for League of Legends.

Installation

Install the latest version directly from PyPI:

pip install pyke-lol

You need Python 3.10+


Quickstart

import asyncio

from pyke import Continent, Pyke, exceptions

async def main() -> None:
    # Initialize the API
    async with Pyke("RGAPI-...", timeout=60, print_url=True) as api:
        # Every pyke method follows the same convention as the Riot API
        # For example account/v1/accounts/by-riot-id/{gameName}/{tagLine} becomes:
        account = await api.account.by_riot_id(Continent.EUROPE, "saves", "000")

        print(f"Riot ID: {account['gameName']}#{account['tagLine']}")
        print(f"PUUID:   {account['puuid']}")

        # pyke throws typed exceptions matching Riot API error codes
        try:
            region = await 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"Region:  {region['region']}")

Custom Exception Handling

Typed exceptions for all HTTP status codes:

from pyke import exceptions

try:
    summoner = await 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 (Error Code: 429)
except exceptions.InternalServerError as e:
    print(f"Server error: {e}")  # Internal server error (Error Code: 500)

Resources


For any questions or help, please reach out on Discord: .irm

  1"""# pyke
  2
  3[![PyPI - Version](https://img.shields.io/pypi/v/pyke-lol)](https://pypi.org/project/pyke-lol/)
  4[![Documentation](https://img.shields.io/badge/Documentation-blue)](https://diodemusic.github.io/pyke/)
  5
  6**pyke** is a thin async Riot API wrapper for League of Legends.
  7
  8## Installation
  9
 10Install the latest version directly from PyPI:
 11
 12```bash
 13pip install pyke-lol
 14```
 15
 16> You need Python 3.10+
 17
 18---
 19
 20## Quickstart
 21
 22```py
 23import asyncio
 24
 25from pyke import Continent, Pyke, exceptions
 26
 27async def main() -> None:
 28    # Initialize the API
 29    async with Pyke("RGAPI-...", timeout=60, print_url=True) as api:
 30        # Every pyke method follows the same convention as the Riot API
 31        # For example account/v1/accounts/by-riot-id/{gameName}/{tagLine} becomes:
 32        account = await api.account.by_riot_id(Continent.EUROPE, "saves", "000")
 33
 34        print(f"Riot ID: {account['gameName']}#{account['tagLine']}")
 35        print(f"PUUID:   {account['puuid']}")
 36
 37        # pyke throws typed exceptions matching Riot API error codes
 38        try:
 39            region = await api.account.region_by_puuid(
 40                Continent.EUROPE, account["puuid"]
 41            )
 42        except exceptions.DataNotFound as e:
 43            print(e)  # Output: Data not found (Error Code: 404)
 44            quit()
 45
 46        print(f"Region:  {region['region']}")
 47```
 48
 49## Custom Exception Handling
 50
 51Typed exceptions for all HTTP status codes:
 52
 53```py
 54from pyke import exceptions
 55
 56try:
 57    summoner = await api.summoner.by_puuid(Region.EUW, "NonExistentPuuid")
 58except exceptions.DataNotFound as e:
 59    print(f"Not found: {e}")     # Data not found (Error Code: 404)
 60except exceptions.RateLimitExceeded as e:
 61    print(f"Rate limited: {e}")  # Rate limit exceeded (Error Code: 429)
 62except exceptions.InternalServerError as e:
 63    print(f"Server error: {e}")  # Internal server error (Error Code: 500)
 64```
 65
 66## Resources
 67
 68- **[API Documentation](https://diodemusic.github.io/pyke/pyke.html)**
 69- **[Examples Directory](https://github.com/diodemusic/pyke/tree/master/examples)**
 70- **[PyPI Package](https://pypi.org/project/pyke-lol/)**
 71- **[GitHub Repository](https://github.com/diodemusic/pyke)**
 72
 73---
 74
 75For any questions or help, please reach out on Discord: `.irm`
 76"""
 77
 78from . import ddragon, endpoints, enums, exceptions
 79from .__version__ import __author__, __title__, __version__
 80from .enums.continent import Continent
 81from .enums.division import Division
 82from .enums.level import Level
 83from .enums.match_type import MatchType
 84from .enums.queue import Queue
 85from .enums.region import Region
 86from .enums.tier import Tier
 87from .main import DataDragon, Pyke
 88
 89__all__ = [
 90    "ddragon",
 91    "exceptions",
 92    "Continent",
 93    "Division",
 94    "Level",
 95    "Queue",
 96    "Region",
 97    "Tier",
 98    "MatchType",
 99    "DataDragon",
100    "Pyke",
101    "__author__",
102    "__title__",
103    "__version__",
104    "endpoints",
105    "enums",
106]
class Continent(enum.Enum):
 5class Continent(Enum):
 6    """# Continent to execute against"""
 7
 8    AMERICAS = "americas"
 9    ASIA = "asia"
10    EUROPE = "europe"
11    SEA = "sea"

Continent to execute against

AMERICAS = <Continent.AMERICAS: 'americas'>
ASIA = <Continent.ASIA: 'asia'>
EUROPE = <Continent.EUROPE: 'europe'>
SEA = <Continent.SEA: 'sea'>
class Division(enum.Enum):
 5class Division(Enum):
 6    """# Ranked division"""
 7
 8    I = "I"  # noqa: E741
 9    II = "II"
10    III = "III"
11    IV = "IV"

Ranked division

I = <Division.I: 'I'>
II = <Division.II: 'II'>
III = <Division.III: 'III'>
IV = <Division.IV: 'IV'>
class Level(enum.Enum):
 5class Level(Enum):
 6    """# Challenge level"""
 7
 8    NONE = "NONE"
 9    IRON = "IRON"
10    BRONZE = "BRONZE"
11    SILVER = "SILVER"
12    GOLD = "GOLD"
13    PLATINUM = "PLATINUM"
14    EMERALD = "EMERALD"
15    DIAMOND = "DIAMOND"
16    MASTER = "MASTER"
17    GRANDMASTER = "GRANDMASTER"
18    CHALLENGER = "CHALLENGER"
19    HIGHEST_NOT_LEADERBOARD_ONLY = "HIGHEST_NOT_LEADERBOARD_ONLY"
20    HIGHEST = "HIGHEST"
21    LOWEST = "LOWEST"

Challenge level

NONE = <Level.NONE: 'NONE'>
IRON = <Level.IRON: 'IRON'>
BRONZE = <Level.BRONZE: 'BRONZE'>
SILVER = <Level.SILVER: 'SILVER'>
GOLD = <Level.GOLD: 'GOLD'>
PLATINUM = <Level.PLATINUM: 'PLATINUM'>
EMERALD = <Level.EMERALD: 'EMERALD'>
DIAMOND = <Level.DIAMOND: 'DIAMOND'>
MASTER = <Level.MASTER: 'MASTER'>
GRANDMASTER = <Level.GRANDMASTER: 'GRANDMASTER'>
CHALLENGER = <Level.CHALLENGER: 'CHALLENGER'>
HIGHEST_NOT_LEADERBOARD_ONLY = <Level.HIGHEST_NOT_LEADERBOARD_ONLY: 'HIGHEST_NOT_LEADERBOARD_ONLY'>
HIGHEST = <Level.HIGHEST: 'HIGHEST'>
LOWEST = <Level.LOWEST: 'LOWEST'>
class Queue(enum.Enum):
5class Queue(Enum):
6    """# Ranked queue type"""
7
8    SOLO_DUO = "RANKED_SOLO_5x5"
9    FLEX = "RANKED_FLEX_SR"

Ranked queue type

SOLO_DUO = <Queue.SOLO_DUO: 'RANKED_SOLO_5x5'>
FLEX = <Queue.FLEX: 'RANKED_FLEX_SR'>
class Region(enum.Enum):
 5class Region(Enum):
 6    """# Region to execute against"""
 7
 8    BR = "br1"
 9    EUNE = "eun1"
10    EUW = "euw1"
11    JP = "jp1"
12    KR = "kr"
13    LAN = "la1"
14    LAS = "la2"
15    ME = "me1"
16    NA = "na1"
17    OCE = "oc1"
18    RU = "ru"
19    TR = "tr1"
20    SG = "sg2"  # covers PH, SG, and TH — all route to the sg2 server
21    TW = "tw2"
22    VN = "vn2"

Region to execute against

BR = <Region.BR: 'br1'>
EUNE = <Region.EUNE: 'eun1'>
EUW = <Region.EUW: 'euw1'>
JP = <Region.JP: 'jp1'>
KR = <Region.KR: 'kr'>
LAN = <Region.LAN: 'la1'>
LAS = <Region.LAS: 'la2'>
ME = <Region.ME: 'me1'>
NA = <Region.NA: 'na1'>
OCE = <Region.OCE: 'oc1'>
RU = <Region.RU: 'ru'>
TR = <Region.TR: 'tr1'>
SG = <Region.SG: 'sg2'>
TW = <Region.TW: 'tw2'>
VN = <Region.VN: 'vn2'>
class Tier(enum.Enum):
 5class Tier(Enum):
 6    """# Ranked tier"""
 7
 8    IRON = "IRON"
 9    BRONZE = "BRONZE"
10    SILVER = "SILVER"
11    GOLD = "GOLD"
12    PLATINUM = "PLATINUM"
13    EMERALD = "EMERALD"
14    DIAMOND = "DIAMOND"
15    MASTER = "MASTER"
16    GRANDMASTER = "GRANDMASTER"
17    CHALLENGER = "CHALLENGER"

Ranked tier

IRON = <Tier.IRON: 'IRON'>
BRONZE = <Tier.BRONZE: 'BRONZE'>
SILVER = <Tier.SILVER: 'SILVER'>
GOLD = <Tier.GOLD: 'GOLD'>
PLATINUM = <Tier.PLATINUM: 'PLATINUM'>
EMERALD = <Tier.EMERALD: 'EMERALD'>
DIAMOND = <Tier.DIAMOND: 'DIAMOND'>
MASTER = <Tier.MASTER: 'MASTER'>
GRANDMASTER = <Tier.GRANDMASTER: 'GRANDMASTER'>
CHALLENGER = <Tier.CHALLENGER: 'CHALLENGER'>
class MatchType(enum.Enum):
 5class MatchType(Enum):
 6    """# Type of match"""
 7
 8    RANKED = "ranked"
 9    NORMAL = "normal"
10    TOURNEY = "tourney"
11    TUTORIAL = "tutorial"

Type of match

RANKED = <MatchType.RANKED: 'ranked'>
NORMAL = <MatchType.NORMAL: 'normal'>
TOURNEY = <MatchType.TOURNEY: 'tourney'>
TUTORIAL = <MatchType.TUTORIAL: 'tutorial'>
class DataDragon:
 83class DataDragon:
 84    def __init__(self, timeout: int = 60, print_url: bool = False) -> None:
 85        self._client = _BaseDataDragonClient(timeout, print_url)
 86
 87        self.spellbuffs = SpellbuffsData(self._client)
 88        self.item = ItemData(self._client)
 89        self.runes_reforged = RunesReforgedData(self._client)
 90        self.language = LanguageData(self._client)
 91        self.item_modifiers = ItemModifiersData(self._client)
 92        self.champion_full = ChampionFullData(self._client)
 93        self.summoner = SummonerData(self._client)
 94        self.champion = ChampionData(self._client)
 95        self.challenges = ChallengesData(self._client)
 96        self.mission_assets = MissionAssetsData(self._client)
 97        self.sticker = StickerData(self._client)
 98        self.profileicon = ProfileiconData(self._client)
 99        self.map = MapData(self._client)
100
101    async def __aenter__(self) -> DataDragon:
102        return self
103
104    async def __aexit__(
105        self,
106        exc_type: BaseException | None,
107        exc: BaseException | None,
108        tb: types.TracebackType | None,
109    ) -> None:
110        await self.aclose()
111
112    async def aclose(self) -> None:
113        await self._client.aclose()
DataDragon(timeout: int = 60, print_url: bool = False)
84    def __init__(self, timeout: int = 60, print_url: bool = False) -> None:
85        self._client = _BaseDataDragonClient(timeout, print_url)
86
87        self.spellbuffs = SpellbuffsData(self._client)
88        self.item = ItemData(self._client)
89        self.runes_reforged = RunesReforgedData(self._client)
90        self.language = LanguageData(self._client)
91        self.item_modifiers = ItemModifiersData(self._client)
92        self.champion_full = ChampionFullData(self._client)
93        self.summoner = SummonerData(self._client)
94        self.champion = ChampionData(self._client)
95        self.challenges = ChallengesData(self._client)
96        self.mission_assets = MissionAssetsData(self._client)
97        self.sticker = StickerData(self._client)
98        self.profileicon = ProfileiconData(self._client)
99        self.map = MapData(self._client)
spellbuffs
item
runes_reforged
language
item_modifiers
champion_full
summoner
champion
challenges
mission_assets
sticker
profileicon
map
async def aclose(self) -> None:
112    async def aclose(self) -> None:
113        await self._client.aclose()
class Pyke:
36class Pyke:
37    """# Main entrypoint for interacting with the Riot API
38
39    **Example:**  
40        `async with Pyke("RGAPI-...") as api:`
41
42    **Args:**  
43        `api_key (str | None)` Your Riot API key.  
44        `timeout (int, optional)` Request timeout in seconds. Defaults to 60.  
45        `print_url (bool, optional)` Print endpoint URL. Defaults to False.  
46    """  # fmt: skip
47
48    def __init__(
49        self,
50        api_key: str | None,
51        timeout: int = 60,
52        print_url: bool = False,
53    ) -> None:
54        self._client = _BaseRiotClient(api_key, timeout, print_url)
55
56        self.account = AccountEndpoint(self._client)
57        self.champion_mastery = ChampionMasteryEndpoint(self._client)
58        self.champion = ChampionEndpoint(self._client)
59        self.clash = ClashEndpoint(self._client)
60        self.league_exp = LeagueExpEndpoint(self._client)
61        self.league = LeagueEndpoint(self._client)
62        self.lol_challenges = ChallengesEndpoint(self._client)
63        self.lol_status = StatusEndpoint(self._client)
64        self.match = MatchEndpoint(self._client)
65        self.spectator = SpectatorEndpoint(self._client)
66        self.summoner = SummonerEndpoint(self._client)
67
68    async def __aenter__(self) -> Pyke:
69        return self
70
71    async def __aexit__(
72        self,
73        exc_type: BaseException | None,
74        exc: BaseException | None,
75        tb: types.TracebackType | None,
76    ) -> None:
77        await self.aclose()
78
79    async def aclose(self) -> None:
80        await self._client.aclose()

Main entrypoint for interacting with the Riot API

Example:
async with Pyke("RGAPI-...") as api:

Args:
api_key (str | None) Your Riot API key.
timeout (int, optional) Request timeout in seconds. Defaults to 60.
print_url (bool, optional) Print endpoint URL. Defaults to False.

Pyke(api_key: str | None, timeout: int = 60, print_url: bool = False)
48    def __init__(
49        self,
50        api_key: str | None,
51        timeout: int = 60,
52        print_url: bool = False,
53    ) -> None:
54        self._client = _BaseRiotClient(api_key, timeout, print_url)
55
56        self.account = AccountEndpoint(self._client)
57        self.champion_mastery = ChampionMasteryEndpoint(self._client)
58        self.champion = ChampionEndpoint(self._client)
59        self.clash = ClashEndpoint(self._client)
60        self.league_exp = LeagueExpEndpoint(self._client)
61        self.league = LeagueEndpoint(self._client)
62        self.lol_challenges = ChallengesEndpoint(self._client)
63        self.lol_status = StatusEndpoint(self._client)
64        self.match = MatchEndpoint(self._client)
65        self.spectator = SpectatorEndpoint(self._client)
66        self.summoner = SummonerEndpoint(self._client)
account
champion_mastery
champion
clash
league_exp
league
lol_challenges
lol_status
match
spectator
summoner
async def aclose(self) -> None:
79    async def aclose(self) -> None:
80        await self._client.aclose()
__author__ = $GITHUB_REPOSITORY_OWNER
__title__ = 'pyke'
__version__ = '3.2.0'