2020 High level Python framework for the Riot Games API, support for AsyncIO and Django
Project description
Pyot
About the documentation
The documentation is separated into different pages at the top navbar.
- Core section documents the core modules, objects and settings of Pyot.
- Pipeline section documents the Low level API of Pyot's Pipeline objects.
- Models section documents the objects APIs for each available model.
- Stores section documents the available Stores configurable to the pipeline.
- Limiters section documents the available Rate Limiters for the RiotAPI Store.
- Utils section documents the available helper functions and objects of Pyot.
- Developers section has contributing guidelines and wanted features.
Portal: Pyot Documentations
Pyot is a Python Framework for the Riot Games API, including League of Legends, Teamfight Tactics, Valorant and Legend of Runeterra (soon). It specializes at doing task in async environment to get the expected result faster than synchronous code. Pyot is highly inspired by Cassiopeia, you will notice that it has similar approach and structure.
Features
Read this entirely to get a better idea of what is Pyot possible at.
- AsyncIO Based: No more waiting forever, concurrent calls and jobs made faster, highly configurable settings and wide range of tools to speed you right now.
- Synchronous Compatible: An adapted version of Pyot that runs on synchronous environment, Pyot will expose part of its API synchronously in its secondary module called Syot.
- Django Support: Full support for Django Caches Framework and its new 3.1 async Views, just add
pyot
to the installed apps and point your setting modules on yoursettings.py
file. - Community Projects Integrated: Take a step to dump the late and poor updated DDragon, we going beta testing directly using Cdragon and Meraki, BangingHeads' DDragon replacement is also coming soon.
- Caches Integrated: A wide range of Caches Stores is available right out of the box, we currently have Omnistone(Python), RedisCache(RAM), DiskCache(File) and soontm an SQL Cache.
- Multiple Models: Available models are League of Legends, Teamfight Tactics and Valorant, holding onto Legend of Runeterra.
- Autocompletion Included: Forget the standard dictionary keys, triple your code efficiency now with autocompletion enabled.
- Perfect Rate Limiter: Pyot Rate Limiter is production tested in all asynchronous, multithreaded and even multiprocessed environments, rate limiters for perfectionists.
- User Friendly Docs: Meet a friendly docs that "should" be better to read and understand.
Requirements
- A computer/laptop with electricity and internet connection.
- Know what is and how to code in Python.
- Ability to read the docs.
- Python version >= 3.7.
- Django version >= 3.0 if used.
Installation
pip install pyot
Quick Start
Activate the Pyot Settings for the model before entering main program, or on the __init__.py
of your working module.
from pyot.core import Settings
import os
Settings(
MODEL = "LOL",
DEFAULT_PLATFORM = "NA1",
DEFAULT_REGION = "AMERICAS",
DEFAULT_LOCALE= "EN_US",
PIPELINE = [
{"BACKEND": "pyot.stores.Omnistone"},
{"BACKEND": "pyot.stores.MerakiCDN"},
{"BACKEND": "pyot.stores.CDragon"},
{
"BACKEND": "pyot.stores.RiotAPI",
"API_KEY": os.environ["RIOT_API_KEY"], # API KEY
}
]
).activate() # <- DON'T FORGET TO ACTIVATE THE SETTINGS
This pipeline settings is only specific to League of Legends Model, for example, TFT doesn't have support of the MerakiCDN.
Now in your main file or module.
from pyot.models import lol
from pyot.utils import loop_run
async def main():
summoner = await lol.Summoner(name="Morimorph", platform="NA1").get()
print(summoner.level)
loop_run(main())
There is an issue on aiohttp related to a
ProactorConnector
Error when used withasyncio.run()
on Windows (it appears to be closed but more related issue surged because of this),loop_run()
is the same asasyncio.get_event_loop().run_until_complete()
imported from the utils module of pyot.
Django
Plugging Pyot into Django is really easy.
DEPRECATED
Since v1.1.0: The module
djot
for Django has been removed, nowpyot
can be installed natively.
Installation
Create a file (the example will use pipelines.py
) under any of the Django modules (either under an app folder or project folder):
This example has test
as the project directory and pipelines.py
as the module. Inside the file add up the needed Pyot Settings. The below example settings is AN EXAMPLE, you can customize the Settings for your needs. Don't forget to activate the settings.
#test/pipelines.py
from pyot.core import Settings
import os
Settings(
MODEL = "LOL",
DEFAULT_PLATFORM = "NA1",
DEFAULT_REGION = "AMERICAS",
DEFAULT_LOCALE= "EN_US",
PIPELINE = [
{"BACKEND": "pyot.stores.Omnistone"},
{"BACKEND": "pyot.stores.MerakiCDN"},
{"BACKEND": "pyot.stores.CDragon"},
{
"BACKEND": "pyot.stores.RiotAPI",
"API_KEY": os.environ["RIOT_API_KEY"],
}
]
).activate()
Then in your projects settings.py
file, add pyot
to the INSTALLED_APPS
.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'pyot',
]
In the same settings.py
file, add the file path to a reserved variable for Pyot called PYOT_SETTINGS
.
# Supposing the pyot settings file is at: test/pipelines.py
PYOT_SETTINGS = [
'test.pipelines'
]
You can define multiple settings in different files if you want to keep 1 setting per app (supposing you have 1 app per game model).
Syot
Syot is a back ported version of Pyot to synchronous code (although I don't see a reason of not going async), this might be an option for those who don't want to go async or want to be REALLY FLEXIBLE by using the 2 world at the same time, which is in some case for Django views.
You still need to activate the Settings for Syot to work.
Syot and Pyot shares the same pipeline per each model so you can use the 2 world together without problem of any. They won't have any conflict UNLESS UNLESS and UNLESS you try to activate the same Settings twice both in Syot and Pyot.
Below documentation only applies to Syot.
The rest of the API please refer to Pyot documentation by replacing pyot
with syot
instead, awaitables needs to be executed with loop_run()
.
Similarities
- All Pyot Object's methods that are not marked with "awaitable" are usable in Syot, that includes Pyot Object's
dict()
,json()
and others not mentioned. - All the models API are available on Syot, with some minor changes listed below.
Differences
- Lose the advantage of cooperative tasks that speeds 10x the calls in exchange of flexibility or a ... mOrE rEAdAblE COdE ?
- The Pyot Pipeline Low Level API is not available in synchronous environment, you would need to do
loop_run()
for every single pipeline coroutine. - The Pyot Gatherer is also not supported here, because it is a feature only for asynchrounous environment.
- Instead of
from pyot
dofrom syot
to import the synchronous version of Pyot. - You no longer need to
await
theget()
methods on the Objects, andget()
is now "chainable", meaning you can chain attributes and other methods right afterget()
.
Example Usage
Activate the settings before you script entry point or module __init__.py
from syot.core import Settings
import os
Settings(
MODEL = "LOL",
DEFAULT_PLATFORM = "NA1",
DEFAULT_REGION = "AMERICAS",
DEFAULT_LOCALE= "EN_US",
PIPELINE = [
{"BACKEND": "pyot.stores.Omnistone"},
{"BACKEND": "pyot.stores.MerakiCDN"},
{"BACKEND": "pyot.stores.CDragon"},
{
"BACKEND": "pyot.stores.RiotAPI",
"API_KEY": os.environ["RIOT_API_KEY"], # API KEY
}
]
).activate() # <- DON'T FORGET TO ACTIVATE THE SETTINGS
Example of Syot code
from syot.models import lol
summoner = lol.Summoner(name="Morimorph", platform="NA1").get()
print(summoner.level)
#OR using method chains:
print(lol.Summoner(name="Morimorph", platform="NA1").get().level)
Contributing
Contributions are welcome! If you have idea or opinions on how things can be improved, don’t hesitate to let us know by posting an issue on GitHub or @ing me on the Riot API Discord channel. And we always want to hear from our users, even (especially) if it’s just letting us know how you are using Pyot.
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
File details
Details for the file pyot-1.1.4.tar.gz
.
File metadata
- Download URL: pyot-1.1.4.tar.gz
- Upload date:
- Size: 60.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b72f40be88340dc3eb3f73096612063ccdef563aa17f60c5f0b99e9aacde56e0 |
|
MD5 | 2ec0bd9c52218ff9054ef9653e043980 |
|
BLAKE2b-256 | 24b38cfb1365843a405b9474e58463f848c056ef345a824f4dedd81d8a3419ef |
Provenance
File details
Details for the file pyot-1.1.4-py3-none-any.whl
.
File metadata
- Download URL: pyot-1.1.4-py3-none-any.whl
- Upload date:
- Size: 82.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41a44a9b888c1a73d19fc8b984bf81c6c662ebd80308d12313fee43d6477cc3b |
|
MD5 | ebebb049b40c5667ded9b2ec50553c4a |
|
BLAKE2b-256 | 144c6f38cffd242ac2ff9764a31174884fd63548544ebee5b0150d973c106d1e |