An asynchronous Python 3 library designed to communicate with the LOL server via the LCU API in a simple and flexible way.
Project description
moonblade
An asynchronous Python 3 library designed to communicate with the LOL server via the LCU API in a simple and flexible way.
Setup
pip install moonblade
Usage
moonblade consists of three core components: MoonBlade, Router, and Node.
MoonBlade
MoonBlade is a connector for establishing communication with the LOL server.
Before using it, you need to import the class:
from moonblade import MoonBlade
To start communication with the LOL server, create an instance of MoonBlade and call start():
mb = MoonBlade()
await mb.start()
To stop communication:
await mb.stop()
MoonBlade also supports use as an asynchronous context manager:
async with MoonBlade() as mb:
...
while True:
await asyncio.sleep(1)
Router
Router is responsible for dispatching events received from the LOL server.
Before using it, import the class:
from moonblade import Router
register
To receive events, you need to register asynchronous handlers.
The register function accepts three parameters: route, event_types, and handler.
route
A route can be a URI or a path.
If the route ends with a "/", it is treated as a path; otherwise, as a URI.
Additionally, moonblade exposes the URI "/moonblade", which dispatches:
A Create event when a connection to the LOL service is successfully established;
A Delete event when the connection is lost;
No Update event is dispatched for this URI.
event_types
Accepts one of the strings Create, Update, Delete, or All, or an iterable containing any combination of these strings.
Defaults to "All". Case-insensitive.
handler
The handler must be an asynchronous function that accepts a single dict.
async def example(data: dict):
pass
You can create a Router instance and register a route:
router = Router()
router.register(route = "/moonblade", event_types = "Create", handler = example)
Note: Router is a singleton. All instances refer to the same underlying object.
You can also register without instantiating:
Router.register(route = "/moonblade", event_types = ("Create",), handler = example)
Or use the decorator style (recommended).
When using the decorator, you must omit the handler parameter:
@Router.register(route = "/moonblade", event_types = ["Create"])
async def example(data: dict):
pass
Router also supports registering asynchronous class methods, described below.
unregister
You can unregister a previously registered handler:
router.unregister(route = "/moonblade", event_types = {"Create"}, handler = example)
If handler is set to None, all handlers for the specified route and event types will be unregistered.
fake
You can simulate events from the server using the asynchronous fake method:
await Router.fake(data = None, event_type = 'Create', uri = '/moonblade')
await Router.fake(data = None, event_type = 'Delete', uri = '/moonblade')
Node
You can also register asynchronous class methods as event handlers.
In this case, the class must inherit from Node:
class N(Node):
def __init__(self) -> None:
...
super().__init__()
@Router.register('/moonblade', 'Create')
async def moonblade_start(self, data: dict):
pass
Alternatively, if not inheriting from Node, you can trigger handler registration by iterating over __dir__():
class N:
def __init__(self) -> None:
for key in self.__dir__():
getattr(self, key)
@Router.register('/moonblade', 'Delete')
async def moonblade_stop(self, data: dict):
pass
Application
For more detailed usage instructions, reference the library Diana which is built on top of moonblade.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moonblade-1.1.3.tar.gz.
File metadata
- Download URL: moonblade-1.1.3.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6fb07520813f7f916bc0e04ccbfe354434d6eef710c89a822e8e0f868755fe8
|
|
| MD5 |
ba33dc15ec29fc7160187e0dee6a8d90
|
|
| BLAKE2b-256 |
ef326f4d6cd1a26acbf5290c1a15c210f1e762b5de41a16f092e0ee53f9a383a
|
File details
Details for the file moonblade-1.1.3-py3-none-any.whl.
File metadata
- Download URL: moonblade-1.1.3-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f60f4744a77d19ff8d906e1b7328c66f774c4a7d5a2f81bcbca609f98906543b
|
|
| MD5 |
060c2aa407d0c155358b4416571de3e3
|
|
| BLAKE2b-256 |
56943ed2c63041cfe3c282d44c3b4c6ce03f211a47501a0ab6074963ee87efe2
|