2020 High level Python framework for the Riot Games API, support for AsyncIO and Django
Project description
Pyot
The documentation is separated into different pages at the top navbar.
- Framework Cores section documents the core settings and features that Pyot uses.
- Models API section documents the API objects for each model.
- Pipeline Stores section documents of the official stores configurable to the pipeline. 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, but none of the objects are being reused from Cassiopeia, everything is rewritten into a more lighter version.
Features
- AsyncIO Support: No more waiting forever, concurrent calls and jobs made faster, highly configurable semaphores and clients sessions to your needs.
- Django Support: Full support for Django Caches Framework and its new 3.1 async Views, the Pyot Framework activation will be handled by an installable app called Djot.
- Synchronous Adaptation: There is a adapted version that runs on synchronous environment, Pyot will expose part of its API synchronously in the extended module called Syot .
- Community Projects Integrated: Take a step to dump the late and poor updated DDragon, we going beta testing directly using Cdragon and Meraki.
- Stores Integrated: A runtime Cache is provided to avoid repeated calls, possible SQL and Redis store coming. For Django you have the integrated Django Cache Store.
- 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.
- Perfect Rate Limiter: Rate Limiter is tested in asynchronous and multithreaded environments.
- 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
- 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.
import pyot
import os
pyot.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",
"KEY": os.environ["RIOT_API_KEY"], # API KEY
}
]
).activate() # <- DON'T FORGET TO ACTIVATE THE SETTINGS
Note: 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.
import pyot
async def main():
summoner = await pyot.lol.Summoner(name="Morimorph", platform="NA1").get()
print(summoner.level)
pyot.run(main())
Note: There is an issue on aiohttp related to a ProactorConnector
Error when used with asyncio.run()
(it appears to be closed but more related issue surged because of this), pyot.run()
is the same as asyncio.get_event_loop().run_until_complete()
, just shortened for you.
Djot
Djot is an installable app that will integrate Pyot to your Django application by taking care of the Pyot Settings. This little app is installed together with Pyot.
Setup
Create a file (preferably named pyot.py
) under any of the Django modules (either under an app folder or project folder):
This example will take test
as the project directory, so create a pyot.py
file inside it and 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/pyot.py
import pyot
import os
import aiohttp
from datetime import timedelta as td
pyot.Settings(
MODEL = "LOL",
GATHERER = {
"LOGS_ENABLED": True,
"SESSION_CLASS": aiohttp.ClientSession,
"CANCEL_ON_RAISE": False,
},
DEFAULT_PLATFORM = "NA1",
DEFAULT_REGION = "AMERICAS",
DEFAULT_LOCALE= "EN_US",
PIPELINE = [
{
"BACKEND": "pyot.stores.Omnistone",
},
{
# If you want to use Django Cache for the pipeline, read the Stores section
"BACKEND": "pyot.stores.DjangoCache",
"ALIAS": "pyot-redis",
},
{
"BACKEND": "pyot.stores.MerakiCDN",
},
{
"BACKEND": "pyot.stores.CDragon",
},
{
"BACKEND": "pyot.stores.RiotAPI",
"KEY": os.environ["RIOT_API_KEY"],
}
]
).activate()
Then in your projects settings.py
file, add djot
to the INSTALLED_APPS
.
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djot',
]
In the same settings.py
file, add the file path to a reserved variable for Djot called PYOT_SETTINGS
.
Supposing the file is at: test/pyot.py
PYOT_SETTINGS = [
'test.pyot'
]
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 an adaptation 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.
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.
Similarities
- All Pyot Object's methods that are not marked with 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 100x 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
pyot.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
import pyot
doimport 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
import syot
import os
syot.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",
"KEY": os.environ["RIOT_API_KEY"], # API KEY
}
]
).activate() # <- DON'T FORGET TO ACTIVATE THE SETTINGS
Example of Syot code
import syot
summoner = syot.lol.Summoner(name="Morimorph", platform="NA1").get()
print(summoner.level)
#OR using method chains:
print(syot.lol.Summoner(name="Morimorph", platform="NA1").get().level)
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.0.0.tar.gz
.
File metadata
- Download URL: pyot-1.0.0.tar.gz
- Upload date:
- Size: 53.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db49ab7eb205ab85f5b118c61647b9d68cb9ef049760615cdcedcbf8cff2e0c9 |
|
MD5 | 1c3ebeb927acca02125a8af945370b0f |
|
BLAKE2b-256 | 685f2281122eb431ab0d0dd8b1ba15ee640ba84577cdc7ef381865f9f2d3663e |
Provenance
File details
Details for the file pyot-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: pyot-1.0.0-py3-none-any.whl
- Upload date:
- Size: 67.0 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/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d248180c058b59272554f9718bdd12b336f4c767054e43ae8efee388544153d4 |
|
MD5 | 12559052b126097eed68b08aa29cdebb |
|
BLAKE2b-256 | 85e68034bc197f682e6ab2fbd7f9ce408caca19b2b6f1e5cca1d934da085cdf0 |