lpdb_python 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ permissions:
12
+ contents: read
13
+ checks: write
14
+
15
+ jobs:
16
+ test:
17
+ name: Test
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v6
22
+
23
+ - name: Setup Python
24
+ uses: actions/setup-python@v6
25
+ with:
26
+ python-version-file: "pyproject.toml"
27
+
28
+ - name: Install uv
29
+ uses: astral-sh/setup-uv@v7
30
+ with:
31
+ enable-cache: true
32
+
33
+ - name: Setup project
34
+ run: uv sync --all-extras --dev
35
+
36
+ - name: Run tests
37
+ run: uv run pytest --junit-xml=pytest.xml
38
+ env:
39
+ API_KEY: ${{ secrets.LPDB_API_KEY }}
40
+
41
+ - name: Publish Test Results
42
+ if: ${{ always() }}
43
+ uses: mikepenz/action-junit-report@v6
44
+ with:
45
+ report_paths: "**/*.xml"
46
+ annotate_only: ${{ github.event_name == 'pull_request' }}
47
+
48
+ lint:
49
+ name: Lint
50
+ runs-on: ubuntu-latest
51
+ steps:
52
+ - name: Checkout repository
53
+ uses: actions/checkout@v6
54
+ - name: Setup Python
55
+ uses: actions/setup-python@v6
56
+ with:
57
+ python-version-file: "pyproject.toml"
58
+ - name: Check styling
59
+ uses: psf/black@stable
@@ -0,0 +1,33 @@
1
+ name: Publish
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ # Publish on any tag starting with a `v`, e.g., v0.1.0
7
+ - v*
8
+
9
+ jobs:
10
+ run:
11
+ runs-on: ubuntu-latest
12
+ environment:
13
+ name: pypi
14
+ permissions:
15
+ id-token: write
16
+ contents: read
17
+ steps:
18
+ - name: Checkout
19
+ uses: actions/checkout@v6
20
+
21
+ - name: Setup Python
22
+ uses: actions/setup-python@v6
23
+ with:
24
+ python-version-file: "pyproject.toml"
25
+
26
+ - name: Install uv
27
+ uses: astral-sh/setup-uv@v7
28
+
29
+ - name: Build
30
+ run: uv build
31
+
32
+ - name: Publish
33
+ run: uv publish
@@ -0,0 +1,174 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ElectricalBoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: lpdb_python
3
+ Version: 0.1.0
4
+ Author-email: ElectricalBoy <electricalboy01@gmail.com>
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/ElectricalBoy/LPDB_python
7
+ Project-URL: Changelog, https://github.com/ElectricalBoy/LPDB_python/releases
8
+ Project-URL: Issues, https://github.com/ElectricalBoy/LPDB_python/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.12
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.32.5
15
+ Provides-Extra: async
16
+ Requires-Dist: aiohttp>=3.13.2; extra == "async"
17
+ Dynamic: license-file
18
+
19
+ # LPDB_python
20
+
21
+ [![CI](https://github.com/ElectricalBoy/LPDB_python/actions/workflows/ci.yml/badge.svg)](https://github.com/ElectricalBoy/LPDB_python/actions/workflows/ci.yml)
22
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
23
+ ![GitHub License](https://img.shields.io/github/license/ElectricalBoy/LPDB-python)
24
+
25
+ LPDB_python provides Python interfaces for the [Liquipedia Database API](https://liquipedia.net/api) (LPDB API).
26
+
27
+ ## LPDB Session
28
+
29
+ Python wrapper for LPDB session is defined in [session.py](src/lpdb/session.py). The wrapper provides the following
30
+ differences from making your own requests:
31
+
32
+ - Type hints
33
+ - Validation of data type names being requested
34
+ If an invalid data type is supplied, then the session will raise `ValueError` before attempting to make a request.
35
+ - Error / warning handling
36
+ If an error is returned by LPDB, then they will be converted to and raised as a Python exception.
37
+ - Pre-configured request header, including formatting of your API key in the request header
38
+
39
+ ```python
40
+ import lpdb_python as lpdb
41
+
42
+ # These are equivalent
43
+ session = lpdb.LpdbSession("your_lpdb_api_key")
44
+ session = lpdb.LpdbSession("Apikey your_lpdb_api_key")
45
+ ```
46
+
47
+ ## LPDB Data Types
48
+
49
+ Data types in LPDB can be found in <https://liquipedia.net/commons/Help:LiquipediaDB>.
50
+
51
+ The raw data returned from LPDB may not be in the corresponding Python types. To help easily access the data,
52
+ [defs.py](src/lpdb/defs.py) file provides wrappers for each available data types that offers converted data
53
+ as object properties.
54
+
55
+ A property provided by the wrapper may be `None` if the raw data passed to the constructor of the wrapper
56
+ did not contain the data, or if it contained an empty string. Thus, the user should be checking for `None`
57
+ where appropriate.
58
+
59
+ ### Example
60
+
61
+ ```python
62
+ import lpdb_python as lpdb
63
+
64
+ session = lpdb.LpdbSession("your_lpdb_api_key")
65
+
66
+ matches = [
67
+ lpdb.Match(lpdb_raw_match)
68
+ for lpdb_raw_match in session.make_request(
69
+ "match",
70
+ "leagueoflegends",
71
+ conditions="[[parent::World_Championship/2025]]",
72
+ streamurls="true",
73
+ )
74
+ ]
75
+ ```
76
+
77
+ ## License
78
+
79
+ This library is licensed under the [MIT License](./LICENSE), unless otherwise stated in the header of a file.
80
+ It should be noted, however, that the data you will be fetching from LPDB API is licensed under [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/).
81
+ See Liquipedia API Terms of Use [here](https://liquipedia.net/api-terms-of-use).
82
+
83
+ ## Disclaimer
84
+
85
+ "Liquipedia" is a registered trademark of Team Liquid. Liquipedia does not endorse or sponsor this project.
@@ -0,0 +1,67 @@
1
+ # LPDB_python
2
+
3
+ [![CI](https://github.com/ElectricalBoy/LPDB_python/actions/workflows/ci.yml/badge.svg)](https://github.com/ElectricalBoy/LPDB_python/actions/workflows/ci.yml)
4
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
5
+ ![GitHub License](https://img.shields.io/github/license/ElectricalBoy/LPDB-python)
6
+
7
+ LPDB_python provides Python interfaces for the [Liquipedia Database API](https://liquipedia.net/api) (LPDB API).
8
+
9
+ ## LPDB Session
10
+
11
+ Python wrapper for LPDB session is defined in [session.py](src/lpdb/session.py). The wrapper provides the following
12
+ differences from making your own requests:
13
+
14
+ - Type hints
15
+ - Validation of data type names being requested
16
+ If an invalid data type is supplied, then the session will raise `ValueError` before attempting to make a request.
17
+ - Error / warning handling
18
+ If an error is returned by LPDB, then they will be converted to and raised as a Python exception.
19
+ - Pre-configured request header, including formatting of your API key in the request header
20
+
21
+ ```python
22
+ import lpdb_python as lpdb
23
+
24
+ # These are equivalent
25
+ session = lpdb.LpdbSession("your_lpdb_api_key")
26
+ session = lpdb.LpdbSession("Apikey your_lpdb_api_key")
27
+ ```
28
+
29
+ ## LPDB Data Types
30
+
31
+ Data types in LPDB can be found in <https://liquipedia.net/commons/Help:LiquipediaDB>.
32
+
33
+ The raw data returned from LPDB may not be in the corresponding Python types. To help easily access the data,
34
+ [defs.py](src/lpdb/defs.py) file provides wrappers for each available data types that offers converted data
35
+ as object properties.
36
+
37
+ A property provided by the wrapper may be `None` if the raw data passed to the constructor of the wrapper
38
+ did not contain the data, or if it contained an empty string. Thus, the user should be checking for `None`
39
+ where appropriate.
40
+
41
+ ### Example
42
+
43
+ ```python
44
+ import lpdb_python as lpdb
45
+
46
+ session = lpdb.LpdbSession("your_lpdb_api_key")
47
+
48
+ matches = [
49
+ lpdb.Match(lpdb_raw_match)
50
+ for lpdb_raw_match in session.make_request(
51
+ "match",
52
+ "leagueoflegends",
53
+ conditions="[[parent::World_Championship/2025]]",
54
+ streamurls="true",
55
+ )
56
+ ]
57
+ ```
58
+
59
+ ## License
60
+
61
+ This library is licensed under the [MIT License](./LICENSE), unless otherwise stated in the header of a file.
62
+ It should be noted, however, that the data you will be fetching from LPDB API is licensed under [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/).
63
+ See Liquipedia API Terms of Use [here](https://liquipedia.net/api-terms-of-use).
64
+
65
+ ## Disclaimer
66
+
67
+ "Liquipedia" is a registered trademark of Team Liquid. Liquipedia does not endorse or sponsor this project.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools >= 80", "setuptools-scm[simple]>=8"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "lpdb_python"
7
+ authors = [
8
+ { name="ElectricalBoy", email="electricalboy01@gmail.com" },
9
+ ]
10
+ classifiers = [
11
+ "Programming Language :: Python :: 3",
12
+ "Operating System :: OS Independent",
13
+ ]
14
+ dynamic = ["version"]
15
+ requires-python = ">= 3.12"
16
+ readme = "README.md"
17
+ license = "MIT"
18
+ dependencies = [
19
+ "requests>=2.32.5"
20
+ ]
21
+
22
+ [project.urls]
23
+ Homepage = "https://github.com/ElectricalBoy/LPDB_python"
24
+ Changelog = "https://github.com/ElectricalBoy/LPDB_python/releases"
25
+ Issues = "https://github.com/ElectricalBoy/LPDB_python/issues"
26
+
27
+ [project.optional-dependencies]
28
+ async = [
29
+ "aiohttp>=3.13.2"
30
+ ]
31
+
32
+ [dependency-groups]
33
+ dev = [
34
+ {include-group = "test"},
35
+ {include-group = "lint"}
36
+ ]
37
+ test = [
38
+ "pytest",
39
+ "pytest-asyncio",
40
+ ]
41
+ lint = [
42
+ "black",
43
+ ]
44
+
45
+ [tool.pytest.ini_options]
46
+ pythonpath = [
47
+ "src"
48
+ ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,37 @@
1
+ """
2
+ Python interface for Liquipedia Database (LPDB) API
3
+ """
4
+
5
+ import importlib.metadata as _metadata
6
+
7
+ from .defs import *
8
+ from .session import *
9
+
10
+ __all__ = [
11
+ "OpponentType",
12
+ "Broadcasters",
13
+ "Company",
14
+ "Datapoint",
15
+ "ExternalMediaLink",
16
+ "LpdbError",
17
+ "LpdbWarning",
18
+ "LpdbSession",
19
+ "Match",
20
+ "MatchGame",
21
+ "MatchOpponent",
22
+ "Placement",
23
+ "Player",
24
+ "Series",
25
+ "SquadPlayer",
26
+ "StandingsEntry",
27
+ "StandingsTable",
28
+ "Team",
29
+ "Tournament",
30
+ "Transfer",
31
+ "TeamTemplate",
32
+ ]
33
+
34
+ try:
35
+ __version__ = _metadata.version(__name__)
36
+ except _metadata.PackageNotFoundError:
37
+ __version__ = "0.0.0"
@@ -0,0 +1,3 @@
1
+ from .async_session import AsyncLpdbSession
2
+
3
+ __all__ = ["AsyncLpdbSession"]
@@ -0,0 +1,133 @@
1
+ from datetime import date
2
+ from http import HTTPStatus
3
+ from types import TracebackType
4
+ from typing import Any, Literal, Optional, override
5
+
6
+ import aiohttp
7
+
8
+ from ..session import AbstractLpdbSession, LpdbDataType, LpdbError
9
+
10
+ __all__ = ["AsyncLpdbSession"]
11
+
12
+
13
+ class AsyncLpdbSession(AbstractLpdbSession):
14
+ """
15
+ Asynchronous implementation of a LPDB session
16
+ """
17
+
18
+ __session: aiohttp.ClientSession
19
+
20
+ def __init__(self, api_key, base_url=AbstractLpdbSession.BASE_URL):
21
+ super().__init__(api_key, base_url=base_url)
22
+ self.__session = aiohttp.ClientSession(
23
+ self._base_url, headers=self._get_header()
24
+ )
25
+
26
+ def __enter__(self) -> None:
27
+ raise TypeError("Use async with instead")
28
+
29
+ def __exit__(
30
+ self,
31
+ exc_type: Optional[type[BaseException]],
32
+ exc_val: Optional[BaseException],
33
+ exc_tb: Optional[TracebackType],
34
+ ) -> None:
35
+ pass
36
+
37
+ async def __aenter__(self) -> "AsyncLpdbSession":
38
+ return self
39
+
40
+ async def __aexit__(
41
+ self,
42
+ exc_type: Optional[type[BaseException]],
43
+ exc_val: Optional[BaseException],
44
+ exc_tb: Optional[TracebackType],
45
+ ) -> None:
46
+ await self.__session.close()
47
+
48
+ @staticmethod
49
+ async def get_wikis() -> set[str]:
50
+ async with aiohttp.ClientSession("https://liquipedia.net/") as session:
51
+ async with session.get(
52
+ "api.php",
53
+ params={"action": "listwikis"},
54
+ headers={"accept": "application/json", "accept-encoding": "gzip"},
55
+ ) as response:
56
+ wikis = await response.json()
57
+ return set(wikis["allwikis"].keys())
58
+
59
+ @staticmethod
60
+ async def __handle_response(
61
+ response: aiohttp.ClientResponse,
62
+ ) -> list[dict[str, Any]]:
63
+ return AbstractLpdbSession._parse_results(
64
+ response.status, await response.json()
65
+ )
66
+
67
+ @override
68
+ async def make_request(
69
+ self,
70
+ lpdb_datatype: LpdbDataType,
71
+ wiki: str | list[str],
72
+ limit: int = 20,
73
+ offset: int = 0,
74
+ conditions: Optional[str] = None,
75
+ query: Optional[str | list[str]] = None,
76
+ order: Optional[str | list[tuple[str, Literal["asc", "desc"]]]] = None,
77
+ groupby: Optional[str | list[tuple[str, Literal["asc", "desc"]]]] = None,
78
+ **kwargs,
79
+ ) -> list[dict[str, Any]]:
80
+ if not AbstractLpdbSession._validate_datatype_name(lpdb_datatype):
81
+ raise ValueError(f'Invalid LPDB data type: "{lpdb_datatype}"')
82
+ async with self.__session.get(
83
+ lpdb_datatype,
84
+ params=AbstractLpdbSession._parse_params(
85
+ wiki=wiki,
86
+ limit=limit,
87
+ offset=offset,
88
+ conditions=conditions,
89
+ query=query,
90
+ order=order,
91
+ groupby=groupby,
92
+ **kwargs,
93
+ ),
94
+ ) as response:
95
+ return await AsyncLpdbSession.__handle_response(response)
96
+
97
+ @override
98
+ async def make_count_request(
99
+ self,
100
+ lpdb_datatype,
101
+ wiki: str,
102
+ conditions: Optional[str] = None,
103
+ ) -> int:
104
+ response = await self.make_request(
105
+ lpdb_datatype, wiki=wiki, conditions=conditions, query="count::objectname"
106
+ )
107
+ return response[0]["count_objectname"]
108
+
109
+ @override
110
+ async def get_team_template(
111
+ self, wiki: str, template: str, date: Optional[date] = None
112
+ ) -> Optional[dict[str, Any]]:
113
+ params = {
114
+ "wiki": wiki,
115
+ "template": template,
116
+ }
117
+ if date != None:
118
+ params["date"] = date.isoformat()
119
+ async with self.__session.get("teamtemplate", params=params) as response:
120
+ parsed_response = await AsyncLpdbSession.__handle_response(response)
121
+ if parsed_response[0] == None:
122
+ return None
123
+ return parsed_response[0]
124
+
125
+ @override
126
+ async def get_team_template_list(
127
+ self, wiki: str, pagination: int = 1
128
+ ) -> list[dict[str, Any]]:
129
+ async with self.__session.get(
130
+ "teamtemplatelist",
131
+ params={"wiki": wiki, "pagination": pagination},
132
+ ) as response:
133
+ return await AsyncLpdbSession.__handle_response(response)