_images/logo.svg

lolrune is a package which contains two clients (async and non-async), through which you can fetch League of Legends rune information for any champion.

Installation

There are two clients included with lolrune. You can install the default which uses the requests library like so:

On Unix-based OSes (you may need sudo)

$ python3 -m pip install -U lolrune

or on Windows

> py -3 -m pip install -U lolrune

In order to install dependencies required for the asynchronous client, which uses aiohttp, you may do the following:

$ python3 -m pip install -U lolrune[async]

The [async] part is 100% necessary in order to use the AioRuneClient, unless of course you have aiohttp installed already.

Note

It is typically recommended to install packages in a virtual environment by using pipenv.

Contents

Examples

The lolrune library has quite a bit of flexibility between sync/async clients, as well as return formatting.

Clients

There are two clients you can use to fetch champion rune data.

Note

If you’re looking for Wukong, search instead for monkeyking. Riot decided that’s what they’re going to call him, so here we are.

RuneClient

This client utilizes a requests.Session to retrieve rune data, and is therefore blocking/synchronous.

from lolrune import RuneClient


client = RuneClient()
champ_tup = client.get_runes('velkoz')

for champ in champ_tup:
   print('{0.name}: {0.description}'.format(champ))

Will yield Vel'Koz: Maximum AP and 1-shot potential.

Searching for a champion with more than one rune page, like Zoe, will yield:

Zoe: We all grow up! Well, you died
Zoe: Sorry! Beauty Always Has Tears

Note: All champion names are case insensitive with any special characters and spaces removed. For example, Vel'Koz becomes velkoz and Lee Sin becomes leesin.

AioRuneClient

This client utilizes an asyncio.AbstractEventLoop and an aiohttp.ClientSession to retrieve data, and is therefore non-blocking/asynchronous.

import asyncio
from lolrune import AioRuneClient

loop = asyncio.get_event_loop()
run = loop.run_until_complete

client = AioRuneClient()
# If you're in an async environment, you'll use await for all coroutines.
champ_tup = run(client.get_runes('velkoz'))

for champ in champ_tup:
   print('{0.name}: {0.description}'.format(champ))

Yields Vel'Koz: Maximum AP and 1-shot potential.

Searching for a champion with more than one rune page, like Riven, will yield:

Riven: Sacrifices Must be Made
Riven: No More Hesitation

Note: All champion names are case insensitive with any special characters and spaces removed. For example, Vel'Koz becomes velkoz and Lee Sin becomes leesin.

Return data format

There are a few ways in which you can interact with the data retrieved by lolrune.

Raw return formatting

The lolrune API returns its data in a Tuple[dict] format. You can easily interact with the raw data on this level.

Note: Most champions will return a tuple with a single item, i.e. a single rune page. Both RuneClient.get_raw() and AioRuneClient.get_raw() will automatically return data in this format:

(
   {
    'name': 'Varus',
    'title': 'Bloodshed Carries a Price',
    'url': 'http://runeforge.gg/loadouts/bloodshed-carries-price/'
    'description': 'Lethality focused long range poke with [Q].',
    'runes': {
      'primary': {
        'name': 'Sorcery',
        'keystone': 'Arcane Comet',
        'rest': [
          'Manaflow Band',
          'Celerity',
          'Scorch'
        ]
      },
      'secondary': {
        'name': 'Precision',
        'rest': [
          'Triumph',
          'Coup De Grace'
        ]
      }
    }
  },
  {
    'name': 'Varus',
    'title': 'Blighted Arrow Dominance',
    'url': 'http://runeforge.gg/loadouts/blighted-arrow-dominance/'
    'description': 'Massive sustained shred damage.',
    'runes': {
      'primary': {
        'name': 'Precision',
        'keystone': 'Press the Attack',
        'rest': [
          'Triumph',
          'Legend: Bloodline',
          'Coup De Grace'
        ]
      },
      'secondary': {
        'name': 'Domination',
        'rest': [
          'Taste of Blood',
          'Ravenous Hunter'
        ]
      }
    }
  }
)

Abstract return formatting

If you would prefer a more pythonic interface, one is provided.

lolrune includes a Champion class, which contains the returned RunePage, which holds the two rune Trees. In order to access this interface, you may call RuneClient.get_runes() and AioRuneClient.get_runes(), depending on your client of choice.

Structure:

Champion
├───description : str
├───name : str
├───runes : RunePage
│   ├───keystone : str
│   ├───primary : Tree
│   │   ├───name : str
│   │   └───runes : List[str]
│   └───secondary : Tree
│       ├───name : str
│       └───runes : List[str]
├───title : str
└───url : str

Usage:

>>> from lolrune import RuneClient
>>> client = RuneClient()
>>> champ = client.get_champ('varus')[0] # This method returns a tuple
>>> runes = champ.runes
>>> champ.name
'Varus'
>>> champ.title
'Bloodshed Carries a Price'
>>> champ.description
'Lethality focused long range poke with [Q].'
>>> runes.keystone
'Arcane Comet'
>>> runes.primary
Tree(name='Sorcery', runes=['Manaflow Band', 'Celerity', 'Scorch'])
>>> runes.secondary
Tree(name='Precision', runes=['Triumph', 'Coup De Grace'])

API Reference

Clients

class lolrune.RuneClient(session=None)

A client which allows you get a champion’s optimal runes. You can find a brief example here.

Parameters:session (requests.Session, optional) – The main session which is used to make all requests. If one is not passed, one will be created.
HEADERS

dict – Firefox headers for the particular version used to inspect the html.

URL

str – The runeforge.gg url used in requests.

dict – A dict containing all champ’s individual rune pages.

Note

The rune_links data is structured like so:

{
  "aatrox": [
    "http://runeforge.gg/loadouts/die-and-be-forgotten/"
  ],
  "ahri": [
    "http://runeforge.gg/loadouts/the-poking-fox/",
    "http://runeforge.gg/loadouts/burst-snowball-carry/"
  ], ...
}
get_raw(champion_name)

The main method to retrieve raw optimal runes for a given champion.

Parameters:champion_name (str) – Case insensitive name of the champion to get runes for.
Return type:Tuple[dict]
Returns:Tuple[dict] – A tuple of dicts which contain the rune information.

Note

Please see Raw return formatting for more information on the return type.

Raises:ChampNotFoundError – If the champion is not found in self.rune_links.
get_runes(champion_name)

A method to retrieve a champion’s runepage objects.

Parameters:champion_name (str) – Case insensitive name of the champion to get runes for.
Return type:Tuple[Champion]
Returns:Tuple[Champion] – A tuple of Champions.

Note

Please see Abstract return formatting and Champion for more information on the return type.

Raises:ChampNotFoundError – If the champion is not found in self.rune_links.
update_champs()

A method which updates self.rune_links. This is useful because runeforge.gg is frequently updating.

Raises:RuneConnectionError – If the GET response status is not 200.
class lolrune.AioRuneClient(session=None, loop=None)

An asynchronous version of RuneClient used to fetch optimal runes for champions. You can find a brief example here.

Parameters:
  • session (aiohttp.ClientSession, optional) – The aiohttp session used in all requests. If none is provided, a new session will be created.
  • loop (asyncio.AbstractEventLoop, optional) – The asyncio event loop. If none is provided, a new loop will be created.
HEADERS

dict – Firefox headers for the particular version used to inspect the html.

URL

str – The runeforge.gg url used in requests.

dict – A dict containing all champ’s individual rune pages.

Note

The rune_links data is structured like so:

{
  "aatrox": [
    "http://runeforge.gg/loadouts/die-and-be-forgotten/"
  ],
  "ahri": [
    "http://runeforge.gg/loadouts/the-poking-fox/",
    "http://runeforge.gg/loadouts/burst-snowball-carry/"
  ], ...
}
coroutine get_raw(self, champion_name)

A method to retrieve raw optimal runes for a given champion.

Parameters:champion_name (str) – Case insensitive name of the champion to get runes for.
Return type:Tuple[dict]
Returns:Tuple[dict] – A tuple of dicts which contain the rune information.

Note

Please see Raw return formatting for more information on the return type.

Raises:ChampNotFoundError – If the champion is not found in self.rune_links.
coroutine get_runes(self, champion_name)

A method to retrieve a champion’s runepage objects.

Parameters:champion_name (str) – Case insensitive name of the champion to get runes for.
Return type:Tuple[Champion]
Returns:Tuple[Champion] – A tuple of Champions.

Note

Please see Abstract return formatting and Champion for more information on the return type.

Raises:ChampNotFoundError – If the champion is not found in self.rune_links.
coroutine update_champs()

A method which updates self.rune_links. This is useful because runeforge.gg is frequently updating.

Raises:RuneConnectionError – If the request does not return with a status of 200.

Data Classes

class lolrune.Champion(rune_data)

Represents a champion and contains that champ’s rune page.

Parameters:rune_data (dict) – The entirety of the rune page data returned by RuneClient.get_raw() and AioRuneClient.get_raw().
name

str – The champion’s name e.g. 'Kalista'.

title

str – The title assigned to the particular champion’s rune page by runeforge.gg. This is largely meaningless, e.g. 'Bloodshed Carries a Price'.

description

str – A slightly less meaningless description of the rune page e.g., 'Lethality focused long range poke with [Q].'.

runes

RunePage – Contains rune information.

url

str – The runeforge page for the specific rune page.

Note

For more information on this object and other data objects, please see Abstract return formatting

class lolrune.RunePage(rune_page)

An object representing a specific rune page for a Champion.

Parameters:rune_page (dict) – The nested data contained in rune_data['runes'].
keystone

str – The keystone for the page, e.g. 'Arcane Comet'.

primary

Tree – A representation of the primary rune tree.

secondary

Tree – A representation of the secondary rune tree.

Note

For more information on this object and other data objects, please see Abstract return formatting

class lolrune.Tree(name, runes)

A namedtuple which represents a specific tree in a RunePage.

name

str – The name of the rune tree, e.g. 'Precision'.

runes

List[str] – A list of runes in a page, e.g.:

['Cheap Shot', 'Ghost Poro', 'Relentless Hunter']

Exceptions

exception lolrune.LoLRuneException

Base exception for library exceptions.

exception lolrune.RuneConnectionError(status)

Raised when a request does not have a status of 200.

Parameters:status (int) – The status of the request which failed.
exception lolrune.ChampNotFoundError(champ)

Raised when a champion is not found in self.rune_links.

Parameters:champ (str) – The champion which was not found.

Attribution

All lolrune data is obtained via scraping Runeforge.

I highly recommend you check them out!

rfgg

Indices and tables