Skip to main content

lcu-driver

Python interface for LCU API. Only support Windows platform. Inspired in lcu-connector

Download

  • pip install lcu-driver

Code example

Change to a random chinese icon every time your run the application.
from json import dumps
from random import randint

from lcu_driver import Connector


connector = Connector()


async def set_random_icon():
    # random number of a chinese icon
    random_number = randint(50, 78)

    # make the request to set the icon
    icon = await connector.request('put', '/lol-summoner/v1/current-summoner/icon',
                                   data=dumps({'profileIconId': random_number}))

    # if HTTP status code is 201 the icon was applied successfully
    if icon.status == 201:
        print(f'Chinese icon number {random_number} was set correctly.')
    else:
        print('Unknown problem, the icon was not set.')

# fired when LCU API is ready to be used
@connector.event
async def connect():
    print('LCU API is ready to be used.')

    # check if the user is already logged into his account
    summoner = await connector.request('get', '/lol-summoner/v1/current-summoner')
    if summoner.status == 200:
        data = await summoner.json()

        # calls login method and update login.left_calls to 0
        # when login.left_calls is 0 the function can't be fired any more neither by websocket nor manually
        await login(None, None, data)

    else:
        print('Please login into your account to change your icon...')


# fired when League Client is closed (or disconnected from websocket)
@connector.event
async def disconnect():
    print('The client have been closed!')

# subscribe to the login websocket event, and calls the function only one time
@connector.ws_events(['/lol-summoner/v1/current-summoner'], event_types=['Update'],
                     max_calls=1)
async def login(typ, uri, data):
    print('Logged as', data['displayName'])
    await set_random_icon()


# opens websocket connection (may be used to wait until the client is closed)
connector.listen()
# starts everything
connector.start()

Classes and methods

class Connector

  • __init__(self, *, loop=None)

    • loop

Properties

  • pid

    Process Id.
  • protocols

    Tuple of allowed protocols.
  • port

  • auth_key

  • installation_path

  • address

  • ws_address

Methods

  • start()

    Start the driver.

  • listen()

    Keep connected until client closes. (open websocket connection).

  • stop_ws()

    Gracefully stops the websocket loop.

  • coroutine request(method: str, endpoint: str, **kwargs)

    • method - HTTP verb.
    • endpoint - Resource URL without protocol and host name.
    • **kwargs
  • ws_events(endpoints: list, *, event_types: list, max_calls=-1)

    • endpoints - List of URIs.
    • event_types - List of events types (Create, Update or Delete).
    • max_calls - Maximum times an event function can be called either by the websocket or manually. Set it to negative numbers to remove the limit.

Built-in library events

  • connect

    Fired when LCU API starts.
  • disconnect

    Fired when the client is closed.

Release files for lcu-driver 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lcu-driver 1.0.0
File Size Uploaded
lcu-driver-1.0.0.tar.gz 5.2 kB Details

Release files / lcu-driver-1.0.0.tar.gz

Download URL lcu-driver-1.0.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1b65b178348a00224c22e59cfb02b3247930b9400bbabad168f37d83c78cb838
BLAKE2b-256 checksum
How to use checksums
91957cf5ea78a83c96a283cc758d7350650cb9c754a7cd792a70fb0805e06f33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

Release history Release notifications | RSS feed

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.3

1 release file

2.1.2

1 release file

2.1.1

1 release file

2.1.0

1 release file

2.0.0

1 release file

This release

1.0.0 This release

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page