Skip to main content

A Python 3 asynchronous library committed to communicating with LOL server through the LCU API in a simple and flexible way .

Project description

moonblade

A Python 3 asynchronous library committed to communicating with LOL server through the LCU API in a simple and flexible way.

Setup

pip install moonblade

Usage

moonblade consists of MoonBlade, Router, and Node.

MoonBlade

MoonBlade is a connector to connect to LOL server. At the beginning, it is necessary to import the class.

from moonblade import MoonBlade

To communicating with LOL server, you need to start MoonBlade first.

mb = MoonBlade()
mb.start()

Similarly, when stopping the use of MoonBlade, it is necessary to stop MoonBlade.

mb.stop()

MoonBlade is alse support context managers.

async with MoonBlade() as mb:
    ...
    while True:
        await asyncio.sleep(1)

Router

Router is used to distribute events received from the LOL server. Before use, it is also necessary to import the class.

from moonblade import Router

register

To receive events, we need to register asynchronous handlers. The handler should be able to accept a dict param.

async def example(data: dict):
    pass

router = Router()
router.register(route = "/moonblade/start", event_type = "All", handler = example)

Note that Router is a singleton class that points to the same Router no matter how many times it is instantiated.

Router can also be used without instantiation.

Router.register(route = "/moonblade/start", event_type = "All", handler = example)

Router can also be use as a decorator to register route.

@Router.register(route = "/moonblade/start", event_type = "All")
async def example(data: dict):
    pass

In fact, I recommend using this way. It should be noted that when registering route with a decorator, the handler param should be None.

We can also register asynchronous methods, which will be introduced later.

event_type

Including Create, Update, Delete and All. Default to All and case-insensitive.

fake

An asynchronous method to fake an event from the server.

await Router.fake(None, 'Update', '/moonblade/start')

Node

Router can register asynchronous methods. In this situation, the class witch the method in should be a subclass of Node.

class C(Node):

    def __init__(self) -> None:
        ...
        super().__init__()

    @Router.register('/moonblade/start')
    async def example(self, data: dict):
        pass

Also, we can add for key in self.__dir__(): getattr(self, key) to the end of the __init__ method to achieve the same effect.

class C:
    def __init__(self) -> None:
        for key in self.__dir__():
            getattr(self, key)

    @Router.register('/moonblade/start')
    async def example(self, data: dict):
        pass

Application

For more detailed usage instructions, reference the library Diana witch is based on moonblade.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moonblade-1.0.5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

moonblade-1.0.5-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file moonblade-1.0.5.tar.gz.

File metadata

  • Download URL: moonblade-1.0.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for moonblade-1.0.5.tar.gz
Algorithm Hash digest
SHA256 d3666389df738d13b77609502ae9d78ff8719512f74d4304b8b8d869eae82cf8
MD5 47974f5f0d8753dc26953b3d98dbee2f
BLAKE2b-256 b32631b9b4e0831076494fe898658588302ec107be9785b0804a8ff6b7b26013

See more details on using hashes here.

File details

Details for the file moonblade-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: moonblade-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.11

File hashes

Hashes for moonblade-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 58183a6068a363cafb2d47db3df3112a5127f1e6c0e70e986f36005584c0ecd5
MD5 327dbaaf6d6fcd225b8aa362a780278d
BLAKE2b-256 88b8e8640f432a5b7abcb6005e1511fceda7077dbd3b5d57e851e375bbd8b8c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page