Skip to content

Player

High-level player object for convenient access to player data.

This class provides a convenient interface for accessing player data across multiple API endpoints. The riot account data is fetched immediately during creation, while other data is fetched lazily and cached within the object to avoid repeated API calls.

Source code in nexar/models/player.py
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
@dataclass
class Player:
    """
    High-level player object for convenient access to player data.

    This class provides a convenient interface for accessing player data
    across multiple API endpoints. The riot account data is fetched immediately
    during creation, while other data is fetched lazily and cached within the
    object to avoid repeated API calls.
    """

    client: NexarClient
    """The client instance to use for API calls."""

    game_name: str
    """Player's game name (without #)."""

    tag_line: str
    """Player's tag line (without #)."""

    riot_account: RiotAccount
    """The player's Riot account information."""

    region: Region | None = None
    """The player's region (defaults to client default)."""

    # Cached data (set after first fetch)
    _summoner: Summoner | None = None
    _league_entries: list[LeagueEntry] | None = None

    @classmethod
    async def create(
        cls,
        client: NexarClient,
        game_name: str,
        tag_line: str,
        *,
        region: Region | None = None,
    ) -> Player:
        """
        Create a Player instance and fetch the riot account data immediately.

        Args:
            client: The client instance to use for API calls
            game_name: Player's game name (without #)
            tag_line: Player's tag line (without #)
            region: The player's region (defaults to client default)

        Returns:
            Player instance with riot account data pre-fetched

        """
        riot_account = await client.get_riot_account(
            game_name,
            tag_line,
            region=region,
        )

        return cls(
            client=client,
            game_name=game_name,
            tag_line=tag_line,
            riot_account=riot_account,
            region=region,
        )

    @classmethod
    async def by_riot_id(
        cls,
        client: NexarClient,
        riot_id: str,
        *,
        region: Region | None = None,
    ) -> Player:
        """
        Create a Player instance from a Riot ID in "username#tagline" format.

        Args:
            client: The client instance to use for API calls
            riot_id: Riot ID in "username#tagline" format (e.g., "bexli#bex")
            region: The player's region (defaults to client default)

        Returns:
            Player instance with riot account data pre-fetched

        Raises:
            ValueError: If riot_id is not in the correct format

        """
        if "#" not in riot_id:
            msg = f"Invalid Riot ID format: '{riot_id}'. Expected 'username#tagline'"
            raise ValueError(msg)

        game_name, tag_line = riot_id.split("#", 1)

        if not game_name or not tag_line:
            msg = f"Invalid Riot ID format: '{riot_id}'. Both username and tagline must be non-empty"
            raise ValueError(msg)

        return await cls.create(
            client=client,
            game_name=game_name,
            tag_line=tag_line,
            region=region,
        )

    async def get_summoner(self) -> Summoner:
        """
        Get the player's summoner information.

        Returns:
            Summoner with summoner information

        """
        if self._summoner is None:
            self._summoner = await self.client.get_summoner_by_puuid(
                self.riot_account.puuid,
                region=self.region,
            )
        return self._summoner

    async def get_league_entries(self) -> list[LeagueEntry]:
        """
        Get the player's league entries.

        Returns:
            List of league entries for the player

        """
        if self._league_entries is None:
            self._league_entries = await self.client.get_league_entries_by_puuid(
                self.riot_account.puuid,
                region=self.region,
            )
        return self._league_entries

    async def get_match_ids(
        self,
        *,
        start_time: int | datetime | None = None,
        end_time: int | datetime | None = None,
        queue: Queue | int | None = None,
        match_type: MatchType | str | None = None,
        start: int = 0,
        count: int = 20,
    ) -> list[str]:
        """
        Get match IDs for the player.

        Args:
            start_time: Epoch timestamp in seconds or datetime for match start filter
            end_time: Epoch timestamp in seconds or datetime for match end filter
            queue: Queue ID filter (int or QueueId enum)
            match_type: Match type filter (str or MatchType enum)
            start: Start index (0-based)
            count: Number of match IDs to return (0-100)

        Returns:
            List of match IDs

        """
        return await self.client.get_match_ids_by_puuid(
            self.riot_account.puuid,
            start_time=start_time,
            end_time=end_time,
            queue=queue,
            match_type=match_type,
            start=start,
            count=count,
            region=self.region,
        )

    async def get_matches(
        self,
        *,
        start_time: int | datetime | None = None,
        end_time: int | datetime | None = None,
        queue: Queue | int | None = None,
        match_type: MatchType | str | None = None,
        start: int = 0,
        count: int = 20,
    ) -> MatchList:
        """
        Get match details for the player.

        Args:
            start_time: Epoch timestamp in seconds or datetime for match start filter
            end_time: Epoch timestamp in seconds or datetime for match end filter
            queue: Queue ID filter (int or QueueId enum)
            match_type: Match type filter (str or MatchType enum)
            start: Start index (0-based)
            count: Number of match IDs to return (0-100)

        Returns:
            MatchList of Match objects with detailed match information

        """
        match_ids = await self.get_match_ids(
            start_time=start_time,
            end_time=end_time,
            queue=queue,
            match_type=match_type,
            start=start,
            count=count,
        )

        matches: list[Match] = []
        for match_id in match_ids:
            match = await self.client.get_match(match_id, region=self.region)
            matches.append(match)
        return MatchList(matches, self.riot_account.puuid)

    async def get_last_match(self) -> Match | None:
        """
        Get the player's most recent match.

        Returns:
            Most recent Match object, or None if no matches found

        """
        match_ids = await self.get_match_ids(count=1)
        if not match_ids:
            return None

        return await self.client.get_match(match_ids[0], region=self.region)

    @property
    def puuid(self) -> str:
        """Get the player's PUUID."""
        return self.riot_account.puuid

    async def get_solo_rank(self) -> LeagueEntry | None:
        """
        Get the player's solo queue rank.

        - API queue type: RANKED_SOLO_5x5
        - Map: Summoner's Rift
        - Colloquial name: Solo Queue or Solo/Duo Queue

        Returns:
            LeagueEntry for solo queue, or None if unranked

        """
        league_entries = await self.get_league_entries()
        for entry in league_entries:
            if entry.queue_type == Queue.RANKED_SOLO_5x5:
                return entry
        return None

    async def get_flex_rank(self) -> LeagueEntry | None:
        """
        Get the player's flex queue rank.

        - API queue type: RANKED_FLEX_SR
        - Map: Summoner's Rift
        - Colloquial name: Flex Queue

        Returns:
            LeagueEntry for flex queue, or None if unranked

        """
        league_entries = await self.get_league_entries()
        for entry in league_entries:
            if entry.queue_type == Queue.RANKED_FLEX_SR:
                return entry
        return None

    async def get_solo_rank_value(self) -> tuple[int, int] | None:
        """
        Combined tier/rank value for the player's solo queue rank.

        Returns None if the player is unranked in solo queue.

        Useful for comparing or sorting players by solo queue rank.

        Returns:
            Tuple of (rank_value, league_points), or None if unranked

        """
        rank = await self.get_solo_rank()
        if rank is not None:
            return rank.rank_tuple
        return None

    async def get_top_champions(
        self,
        top_n: int = 5,
        count: int = 20,
        queue: Queue | int | None = None,
        match_type: MatchType | str | None = None,
    ) -> list[ChampionStats]:
        """
        Get top played champions.

        Args:
            top_n: Number of top champions to return (default 5)
            count: Number of recent matches to analyze (default 20)
            queue: Optional queue type filter
            match_type: Optional match type filter

        Returns:
            List of ChampionStats sorted by games played (descending)

        """
        matches = await self.get_matches(
            queue=queue,
            match_type=match_type,
            count=count,
        )
        champion_stats = matches.get_champion_stats()
        return sorted(champion_stats, key=lambda x: x.games_played, reverse=True)[:top_n]

    async def get_recent_performance_by_role(
        self,
        count: int = 50,
        queue: Queue | int | None = None,
    ) -> dict[str, dict[str, Any]]:
        """
        Get performance statistics grouped by role.

        Args:
            count: Number of recent matches to analyze (default 50)
            queue: Optional queue type filter

        Returns:
            Dictionary with role names as keys and performance stats as values

        """
        matches = await self.get_matches(queue=queue, count=count)
        puuid = self.riot_account.puuid

        role_stats: dict[str, dict[str, Any]] = {}

        for match in matches:
            # Find the participant for this player
            participant = match.participants.by_puuid(puuid)

            if not participant:
                continue

            role = participant.team_position.value if participant.team_position else "UNKNOWN"

            if role not in role_stats:
                role_stats[role] = {
                    "games": 0,
                    "wins": 0,
                    "kills": 0,
                    "deaths": 0,
                    "assists": 0,
                }

            role_stats[role]["games"] += 1
            if participant.win:
                role_stats[role]["wins"] += 1
            role_stats[role]["kills"] += participant.kills
            role_stats[role]["deaths"] += participant.deaths
            role_stats[role]["assists"] += participant.assists

        # Calculate averages and percentages
        for stats in role_stats.values():
            games = stats["games"]
            if games > 0:
                stats["win_rate"] = (stats["wins"] / games) * 100.0
                stats["avg_kills"] = stats["kills"] / games
                stats["avg_deaths"] = stats["deaths"] / games
                stats["avg_assists"] = stats["assists"] / games
                stats["avg_kda"] = (stats["kills"] + stats["assists"]) / stats["deaths"] if stats["deaths"] > 0 else 0.0

        return role_stats

    async def is_on_win_streak(self, min_games: int = 3) -> bool:
        """
        Check if the player is currently on a win streak.

        Args:
            min_games: Minimum number of games to consider a streak (default 3)

        Returns:
            True if the player is on a win streak of at least min_games

        """
        matches = await self.get_matches(count=min_games * 2)  # Get extra to be safe
        puuid = self.riot_account.puuid

        wins_in_a_row = 0
        for match in matches:
            # Find the participant for this player
            participant = match.participants.by_puuid(puuid)

            if not participant:
                continue

            if participant.win:
                wins_in_a_row += 1
            else:
                break  # Streak broken

        return wins_in_a_row >= min_games

    def refresh_cache(self) -> None:
        """Clear all cached data to force fresh API calls."""
        self._summoner = None
        self._league_entries = None

    def __str__(self) -> str:
        """Return string representation of the player."""
        return f"{self.game_name}#{self.tag_line}"

    def __repr__(self) -> str:
        """Detailed string representation of the player."""
        return f"Player(game_name='{self.game_name}', tag_line='{self.tag_line}')"

client instance-attribute

The client instance to use for API calls.

game_name instance-attribute

Player's game name (without #).

puuid property

Get the player's PUUID.

region = None class-attribute instance-attribute

The player's region (defaults to client default).

riot_account instance-attribute

The player's Riot account information.

tag_line instance-attribute

Player's tag line (without #).

__repr__()

Detailed string representation of the player.

Source code in nexar/models/player.py
def __repr__(self) -> str:
    """Detailed string representation of the player."""
    return f"Player(game_name='{self.game_name}', tag_line='{self.tag_line}')"

__str__()

Return string representation of the player.

Source code in nexar/models/player.py
def __str__(self) -> str:
    """Return string representation of the player."""
    return f"{self.game_name}#{self.tag_line}"

by_riot_id(client, riot_id, *, region=None) async classmethod

Create a Player instance from a Riot ID in "username#tagline" format.

Parameters:

Name Type Description Default
client NexarClient

The client instance to use for API calls

required
riot_id str

Riot ID in "username#tagline" format (e.g., "bexli#bex")

required
region Region | None

The player's region (defaults to client default)

None

Returns:

Type Description
Player

Player instance with riot account data pre-fetched

Raises:

Type Description
ValueError

If riot_id is not in the correct format

Source code in nexar/models/player.py
@classmethod
async def by_riot_id(
    cls,
    client: NexarClient,
    riot_id: str,
    *,
    region: Region | None = None,
) -> Player:
    """
    Create a Player instance from a Riot ID in "username#tagline" format.

    Args:
        client: The client instance to use for API calls
        riot_id: Riot ID in "username#tagline" format (e.g., "bexli#bex")
        region: The player's region (defaults to client default)

    Returns:
        Player instance with riot account data pre-fetched

    Raises:
        ValueError: If riot_id is not in the correct format

    """
    if "#" not in riot_id:
        msg = f"Invalid Riot ID format: '{riot_id}'. Expected 'username#tagline'"
        raise ValueError(msg)

    game_name, tag_line = riot_id.split("#", 1)

    if not game_name or not tag_line:
        msg = f"Invalid Riot ID format: '{riot_id}'. Both username and tagline must be non-empty"
        raise ValueError(msg)

    return await cls.create(
        client=client,
        game_name=game_name,
        tag_line=tag_line,
        region=region,
    )

create(client, game_name, tag_line, *, region=None) async classmethod

Create a Player instance and fetch the riot account data immediately.

Parameters:

Name Type Description Default
client NexarClient

The client instance to use for API calls

required
game_name str

Player's game name (without #)

required
tag_line str

Player's tag line (without #)

required
region Region | None

The player's region (defaults to client default)

None

Returns:

Type Description
Player

Player instance with riot account data pre-fetched

Source code in nexar/models/player.py
@classmethod
async def create(
    cls,
    client: NexarClient,
    game_name: str,
    tag_line: str,
    *,
    region: Region | None = None,
) -> Player:
    """
    Create a Player instance and fetch the riot account data immediately.

    Args:
        client: The client instance to use for API calls
        game_name: Player's game name (without #)
        tag_line: Player's tag line (without #)
        region: The player's region (defaults to client default)

    Returns:
        Player instance with riot account data pre-fetched

    """
    riot_account = await client.get_riot_account(
        game_name,
        tag_line,
        region=region,
    )

    return cls(
        client=client,
        game_name=game_name,
        tag_line=tag_line,
        riot_account=riot_account,
        region=region,
    )

get_flex_rank() async

Get the player's flex queue rank.

  • API queue type: RANKED_FLEX_SR
  • Map: Summoner's Rift
  • Colloquial name: Flex Queue

Returns:

Type Description
LeagueEntry | None

LeagueEntry for flex queue, or None if unranked

Source code in nexar/models/player.py
async def get_flex_rank(self) -> LeagueEntry | None:
    """
    Get the player's flex queue rank.

    - API queue type: RANKED_FLEX_SR
    - Map: Summoner's Rift
    - Colloquial name: Flex Queue

    Returns:
        LeagueEntry for flex queue, or None if unranked

    """
    league_entries = await self.get_league_entries()
    for entry in league_entries:
        if entry.queue_type == Queue.RANKED_FLEX_SR:
            return entry
    return None

get_last_match() async

Get the player's most recent match.

Returns:

Type Description
Match | None

Most recent Match object, or None if no matches found

Source code in nexar/models/player.py
async def get_last_match(self) -> Match | None:
    """
    Get the player's most recent match.

    Returns:
        Most recent Match object, or None if no matches found

    """
    match_ids = await self.get_match_ids(count=1)
    if not match_ids:
        return None

    return await self.client.get_match(match_ids[0], region=self.region)

get_league_entries() async

Get the player's league entries.

Returns:

Type Description
list[LeagueEntry]

List of league entries for the player

Source code in nexar/models/player.py
async def get_league_entries(self) -> list[LeagueEntry]:
    """
    Get the player's league entries.

    Returns:
        List of league entries for the player

    """
    if self._league_entries is None:
        self._league_entries = await self.client.get_league_entries_by_puuid(
            self.riot_account.puuid,
            region=self.region,
        )
    return self._league_entries

get_match_ids(*, start_time=None, end_time=None, queue=None, match_type=None, start=0, count=20) async

Get match IDs for the player.

Parameters:

Name Type Description Default
start_time int | datetime | None

Epoch timestamp in seconds or datetime for match start filter

None
end_time int | datetime | None

Epoch timestamp in seconds or datetime for match end filter

None
queue Queue | int | None

Queue ID filter (int or QueueId enum)

None
match_type MatchType | str | None

Match type filter (str or MatchType enum)

None
start int

Start index (0-based)

0
count int

Number of match IDs to return (0-100)

20

Returns:

Type Description
list[str]

List of match IDs

Source code in nexar/models/player.py
async def get_match_ids(
    self,
    *,
    start_time: int | datetime | None = None,
    end_time: int | datetime | None = None,
    queue: Queue | int | None = None,
    match_type: MatchType | str | None = None,
    start: int = 0,
    count: int = 20,
) -> list[str]:
    """
    Get match IDs for the player.

    Args:
        start_time: Epoch timestamp in seconds or datetime for match start filter
        end_time: Epoch timestamp in seconds or datetime for match end filter
        queue: Queue ID filter (int or QueueId enum)
        match_type: Match type filter (str or MatchType enum)
        start: Start index (0-based)
        count: Number of match IDs to return (0-100)

    Returns:
        List of match IDs

    """
    return await self.client.get_match_ids_by_puuid(
        self.riot_account.puuid,
        start_time=start_time,
        end_time=end_time,
        queue=queue,
        match_type=match_type,
        start=start,
        count=count,
        region=self.region,
    )

get_matches(*, start_time=None, end_time=None, queue=None, match_type=None, start=0, count=20) async

Get match details for the player.

Parameters:

Name Type Description Default
start_time int | datetime | None

Epoch timestamp in seconds or datetime for match start filter

None
end_time int | datetime | None

Epoch timestamp in seconds or datetime for match end filter

None
queue Queue | int | None

Queue ID filter (int or QueueId enum)

None
match_type MatchType | str | None

Match type filter (str or MatchType enum)

None
start int

Start index (0-based)

0
count int

Number of match IDs to return (0-100)

20

Returns:

Type Description
MatchList

MatchList of Match objects with detailed match information

Source code in nexar/models/player.py
async def get_matches(
    self,
    *,
    start_time: int | datetime | None = None,
    end_time: int | datetime | None = None,
    queue: Queue | int | None = None,
    match_type: MatchType | str | None = None,
    start: int = 0,
    count: int = 20,
) -> MatchList:
    """
    Get match details for the player.

    Args:
        start_time: Epoch timestamp in seconds or datetime for match start filter
        end_time: Epoch timestamp in seconds or datetime for match end filter
        queue: Queue ID filter (int or QueueId enum)
        match_type: Match type filter (str or MatchType enum)
        start: Start index (0-based)
        count: Number of match IDs to return (0-100)

    Returns:
        MatchList of Match objects with detailed match information

    """
    match_ids = await self.get_match_ids(
        start_time=start_time,
        end_time=end_time,
        queue=queue,
        match_type=match_type,
        start=start,
        count=count,
    )

    matches: list[Match] = []
    for match_id in match_ids:
        match = await self.client.get_match(match_id, region=self.region)
        matches.append(match)
    return MatchList(matches, self.riot_account.puuid)

get_recent_performance_by_role(count=50, queue=None) async

Get performance statistics grouped by role.

Parameters:

Name Type Description Default
count int

Number of recent matches to analyze (default 50)

50
queue Queue | int | None

Optional queue type filter

None

Returns:

Type Description
dict[str, dict[str, Any]]

Dictionary with role names as keys and performance stats as values

Source code in nexar/models/player.py
async def get_recent_performance_by_role(
    self,
    count: int = 50,
    queue: Queue | int | None = None,
) -> dict[str, dict[str, Any]]:
    """
    Get performance statistics grouped by role.

    Args:
        count: Number of recent matches to analyze (default 50)
        queue: Optional queue type filter

    Returns:
        Dictionary with role names as keys and performance stats as values

    """
    matches = await self.get_matches(queue=queue, count=count)
    puuid = self.riot_account.puuid

    role_stats: dict[str, dict[str, Any]] = {}

    for match in matches:
        # Find the participant for this player
        participant = match.participants.by_puuid(puuid)

        if not participant:
            continue

        role = participant.team_position.value if participant.team_position else "UNKNOWN"

        if role not in role_stats:
            role_stats[role] = {
                "games": 0,
                "wins": 0,
                "kills": 0,
                "deaths": 0,
                "assists": 0,
            }

        role_stats[role]["games"] += 1
        if participant.win:
            role_stats[role]["wins"] += 1
        role_stats[role]["kills"] += participant.kills
        role_stats[role]["deaths"] += participant.deaths
        role_stats[role]["assists"] += participant.assists

    # Calculate averages and percentages
    for stats in role_stats.values():
        games = stats["games"]
        if games > 0:
            stats["win_rate"] = (stats["wins"] / games) * 100.0
            stats["avg_kills"] = stats["kills"] / games
            stats["avg_deaths"] = stats["deaths"] / games
            stats["avg_assists"] = stats["assists"] / games
            stats["avg_kda"] = (stats["kills"] + stats["assists"]) / stats["deaths"] if stats["deaths"] > 0 else 0.0

    return role_stats

get_solo_rank() async

Get the player's solo queue rank.

  • API queue type: RANKED_SOLO_5x5
  • Map: Summoner's Rift
  • Colloquial name: Solo Queue or Solo/Duo Queue

Returns:

Type Description
LeagueEntry | None

LeagueEntry for solo queue, or None if unranked

Source code in nexar/models/player.py
async def get_solo_rank(self) -> LeagueEntry | None:
    """
    Get the player's solo queue rank.

    - API queue type: RANKED_SOLO_5x5
    - Map: Summoner's Rift
    - Colloquial name: Solo Queue or Solo/Duo Queue

    Returns:
        LeagueEntry for solo queue, or None if unranked

    """
    league_entries = await self.get_league_entries()
    for entry in league_entries:
        if entry.queue_type == Queue.RANKED_SOLO_5x5:
            return entry
    return None

get_solo_rank_value() async

Combined tier/rank value for the player's solo queue rank.

Returns None if the player is unranked in solo queue.

Useful for comparing or sorting players by solo queue rank.

Returns:

Type Description
tuple[int, int] | None

Tuple of (rank_value, league_points), or None if unranked

Source code in nexar/models/player.py
async def get_solo_rank_value(self) -> tuple[int, int] | None:
    """
    Combined tier/rank value for the player's solo queue rank.

    Returns None if the player is unranked in solo queue.

    Useful for comparing or sorting players by solo queue rank.

    Returns:
        Tuple of (rank_value, league_points), or None if unranked

    """
    rank = await self.get_solo_rank()
    if rank is not None:
        return rank.rank_tuple
    return None

get_summoner() async

Get the player's summoner information.

Returns:

Type Description
Summoner

Summoner with summoner information

Source code in nexar/models/player.py
async def get_summoner(self) -> Summoner:
    """
    Get the player's summoner information.

    Returns:
        Summoner with summoner information

    """
    if self._summoner is None:
        self._summoner = await self.client.get_summoner_by_puuid(
            self.riot_account.puuid,
            region=self.region,
        )
    return self._summoner

get_top_champions(top_n=5, count=20, queue=None, match_type=None) async

Get top played champions.

Parameters:

Name Type Description Default
top_n int

Number of top champions to return (default 5)

5
count int

Number of recent matches to analyze (default 20)

20
queue Queue | int | None

Optional queue type filter

None
match_type MatchType | str | None

Optional match type filter

None

Returns:

Type Description
list[ChampionStats]

List of ChampionStats sorted by games played (descending)

Source code in nexar/models/player.py
async def get_top_champions(
    self,
    top_n: int = 5,
    count: int = 20,
    queue: Queue | int | None = None,
    match_type: MatchType | str | None = None,
) -> list[ChampionStats]:
    """
    Get top played champions.

    Args:
        top_n: Number of top champions to return (default 5)
        count: Number of recent matches to analyze (default 20)
        queue: Optional queue type filter
        match_type: Optional match type filter

    Returns:
        List of ChampionStats sorted by games played (descending)

    """
    matches = await self.get_matches(
        queue=queue,
        match_type=match_type,
        count=count,
    )
    champion_stats = matches.get_champion_stats()
    return sorted(champion_stats, key=lambda x: x.games_played, reverse=True)[:top_n]

is_on_win_streak(min_games=3) async

Check if the player is currently on a win streak.

Parameters:

Name Type Description Default
min_games int

Minimum number of games to consider a streak (default 3)

3

Returns:

Type Description
bool

True if the player is on a win streak of at least min_games

Source code in nexar/models/player.py
async def is_on_win_streak(self, min_games: int = 3) -> bool:
    """
    Check if the player is currently on a win streak.

    Args:
        min_games: Minimum number of games to consider a streak (default 3)

    Returns:
        True if the player is on a win streak of at least min_games

    """
    matches = await self.get_matches(count=min_games * 2)  # Get extra to be safe
    puuid = self.riot_account.puuid

    wins_in_a_row = 0
    for match in matches:
        # Find the participant for this player
        participant = match.participants.by_puuid(puuid)

        if not participant:
            continue

        if participant.win:
            wins_in_a_row += 1
        else:
            break  # Streak broken

    return wins_in_a_row >= min_games

refresh_cache()

Clear all cached data to force fresh API calls.

Source code in nexar/models/player.py
def refresh_cache(self) -> None:
    """Clear all cached data to force fresh API calls."""
    self._summoner = None
    self._league_entries = None