wiktionary-api 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.
- wiktionary_api-0.1.0/.gitignore +176 -0
- wiktionary_api-0.1.0/LICENSE +21 -0
- wiktionary_api-0.1.0/PKG-INFO +109 -0
- wiktionary_api-0.1.0/README.md +77 -0
- wiktionary_api-0.1.0/docs/ENDPOINTS.md +119 -0
- wiktionary_api-0.1.0/pyproject.toml +89 -0
- wiktionary_api-0.1.0/src/wikt/__init__.py +11 -0
- wiktionary_api-0.1.0/src/wikt/client.py +754 -0
- wiktionary_api-0.1.0/src/wikt/py.typed +0 -0
- wiktionary_api-0.1.0/src/wikt/util.py +52 -0
- wiktionary_api-0.1.0/tests/__init__.py +1 -0
- wiktionary_api-0.1.0/tests/conftest.py +48 -0
- wiktionary_api-0.1.0/tests/test_data.py +86 -0
- wiktionary_api-0.1.0/tests/test_helpers.py +98 -0
- wiktionary_api-0.1.0/tests/test_math.py +66 -0
- wiktionary_api-0.1.0/tests/test_media.py +49 -0
- wiktionary_api-0.1.0/tests/test_page.py +107 -0
- wiktionary_api-0.1.0/tests/test_transform.py +47 -0
- wiktionary_api-0.1.0/tests/test_util.py +43 -0
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
# PyPI configuration file
|
|
171
|
+
.pypirc
|
|
172
|
+
|
|
173
|
+
# test files
|
|
174
|
+
|
|
175
|
+
test.pdf
|
|
176
|
+
*.wav
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nebil Ibrahim
|
|
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,109 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: wiktionary-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Synchronous Python client for the Wikimedia Wiktionary REST API
|
|
5
|
+
Project-URL: Homepage, https://github.com/NebilI/WiktionaryPythonAPI
|
|
6
|
+
Project-URL: Repository, https://github.com/NebilI/WiktionaryPythonAPI
|
|
7
|
+
Project-URL: Issues, https://github.com/NebilI/WiktionaryPythonAPI/issues
|
|
8
|
+
Project-URL: Documentation, https://github.com/NebilI/WiktionaryPythonAPI#readme
|
|
9
|
+
Author: Nebil Ibrahim
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: dictionary,requests,rest-api,wikimedia,wiktionary
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Requires-Dist: pypdf2<4,>=3.0.1
|
|
26
|
+
Requires-Dist: requests<3,>=2.32
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.3; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.9; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# WiktionaryPythonAPI
|
|
34
|
+
|
|
35
|
+
Synchronous Python client for the [Wiktionary REST API](https://en.wiktionary.org/api/rest_v1/#/) and related [Commons Core](https://api.wikimedia.org/wiki/Core_REST_API) media downloads.
|
|
36
|
+
|
|
37
|
+
**PyPI:** `wiktionary-api` · **Import:** `wikt`
|
|
38
|
+
|
|
39
|
+
Covers **all 41** path patterns in the live OpenAPI spec (`?spec`), plus PDF rendering and Commons helpers. See [docs/ENDPOINTS.md](docs/ENDPOINTS.md) for the full path → method map.
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
Works with any PEP 517 installer:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pip install wiktionary-api
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv add wiktionary-api
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
poetry add wiktionary-api
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Requires **Python 3.10+**.
|
|
58
|
+
|
|
59
|
+
## Quick start
|
|
60
|
+
|
|
61
|
+
Wikimedia requires a descriptive [User-Agent](https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy) with your application name and a contact email or URL.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from wikt import Wiktionary
|
|
65
|
+
|
|
66
|
+
wiki = Wiktionary("MyApp", "you@example.com")
|
|
67
|
+
|
|
68
|
+
# Definitions (Wiktionary-specific)
|
|
69
|
+
print(wiki.get_definition("hello"))
|
|
70
|
+
|
|
71
|
+
# HTML / revision metadata
|
|
72
|
+
print(wiki.get_html("hello")[:200])
|
|
73
|
+
print(wiki.get_revision("hello"))
|
|
74
|
+
|
|
75
|
+
# Math (check → render)
|
|
76
|
+
checked = wiki.check_math("tex", "E=mc^2")
|
|
77
|
+
svg = wiki.render_math("svg", checked["resource_location"])
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## API surface (summary)
|
|
81
|
+
|
|
82
|
+
| Area | Examples |
|
|
83
|
+
|------|----------|
|
|
84
|
+
| Page content | `page`, `get_definition`, `get_html`, `get_lint`, `get_mobile_html`, `get_revision`, `get_media_file_list`, `get_pdf` |
|
|
85
|
+
| Data / mobile | `get_citation`, `get_mobile_css`, `get_mobile_javascript`, `get_i18n` |
|
|
86
|
+
| Reading lists | `get_lists`, `create_list`, `update_list`, `delete_list`, entry CRUD, setup/teardown |
|
|
87
|
+
| Transforms | `transform_wikitext_to_html`, `transform_html_to_wikitext`, `transform_wikitext_to_lint`, `transform_wikitext_to_mobile_html` |
|
|
88
|
+
| Math | `check_math`, `get_math_formula`, `render_math` |
|
|
89
|
+
| Commons helpers | `get_media_files`, `download_media_files` |
|
|
90
|
+
|
|
91
|
+
Method docstrings document parameters, return types, and REST paths. Official sandbox: https://en.wiktionary.org/api/rest_v1/#/
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install -e ".[dev]"
|
|
97
|
+
# or: uv sync --all-extras
|
|
98
|
+
ruff check src tests
|
|
99
|
+
ruff format src tests
|
|
100
|
+
pytest tests/ -v
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Publishing
|
|
104
|
+
|
|
105
|
+
Releases publish to PyPI on `v*` tags via trusted publishing. See [.github/PYPI_PUBLISHING.md](.github/PYPI_PUBLISHING.md).
|
|
106
|
+
|
|
107
|
+
## License
|
|
108
|
+
|
|
109
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# WiktionaryPythonAPI
|
|
2
|
+
|
|
3
|
+
Synchronous Python client for the [Wiktionary REST API](https://en.wiktionary.org/api/rest_v1/#/) and related [Commons Core](https://api.wikimedia.org/wiki/Core_REST_API) media downloads.
|
|
4
|
+
|
|
5
|
+
**PyPI:** `wiktionary-api` · **Import:** `wikt`
|
|
6
|
+
|
|
7
|
+
Covers **all 41** path patterns in the live OpenAPI spec (`?spec`), plus PDF rendering and Commons helpers. See [docs/ENDPOINTS.md](docs/ENDPOINTS.md) for the full path → method map.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
Works with any PEP 517 installer:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install wiktionary-api
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
uv add wiktionary-api
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
poetry add wiktionary-api
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Requires **Python 3.10+**.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
Wikimedia requires a descriptive [User-Agent](https://foundation.wikimedia.org/wiki/Policy:Wikimedia_Foundation_User-Agent_Policy) with your application name and a contact email or URL.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from wikt import Wiktionary
|
|
33
|
+
|
|
34
|
+
wiki = Wiktionary("MyApp", "you@example.com")
|
|
35
|
+
|
|
36
|
+
# Definitions (Wiktionary-specific)
|
|
37
|
+
print(wiki.get_definition("hello"))
|
|
38
|
+
|
|
39
|
+
# HTML / revision metadata
|
|
40
|
+
print(wiki.get_html("hello")[:200])
|
|
41
|
+
print(wiki.get_revision("hello"))
|
|
42
|
+
|
|
43
|
+
# Math (check → render)
|
|
44
|
+
checked = wiki.check_math("tex", "E=mc^2")
|
|
45
|
+
svg = wiki.render_math("svg", checked["resource_location"])
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## API surface (summary)
|
|
49
|
+
|
|
50
|
+
| Area | Examples |
|
|
51
|
+
|------|----------|
|
|
52
|
+
| Page content | `page`, `get_definition`, `get_html`, `get_lint`, `get_mobile_html`, `get_revision`, `get_media_file_list`, `get_pdf` |
|
|
53
|
+
| Data / mobile | `get_citation`, `get_mobile_css`, `get_mobile_javascript`, `get_i18n` |
|
|
54
|
+
| Reading lists | `get_lists`, `create_list`, `update_list`, `delete_list`, entry CRUD, setup/teardown |
|
|
55
|
+
| Transforms | `transform_wikitext_to_html`, `transform_html_to_wikitext`, `transform_wikitext_to_lint`, `transform_wikitext_to_mobile_html` |
|
|
56
|
+
| Math | `check_math`, `get_math_formula`, `render_math` |
|
|
57
|
+
| Commons helpers | `get_media_files`, `download_media_files` |
|
|
58
|
+
|
|
59
|
+
Method docstrings document parameters, return types, and REST paths. Official sandbox: https://en.wiktionary.org/api/rest_v1/#/
|
|
60
|
+
|
|
61
|
+
## Development
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install -e ".[dev]"
|
|
65
|
+
# or: uv sync --all-extras
|
|
66
|
+
ruff check src tests
|
|
67
|
+
ruff format src tests
|
|
68
|
+
pytest tests/ -v
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Publishing
|
|
72
|
+
|
|
73
|
+
Releases publish to PyPI on `v*` tags via trusted publishing. See [.github/PYPI_PUBLISHING.md](.github/PYPI_PUBLISHING.md).
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT — see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Endpoint coverage
|
|
2
|
+
|
|
3
|
+
This package wraps the **English Wiktionary** Wikimedia REST API (`rest_v1`) plus Commons Core API helpers for downloading media bytes.
|
|
4
|
+
|
|
5
|
+
Coverage was verified against the live OpenAPI spec at `https://en.wiktionary.org/api/rest_v1/?spec` (41 path patterns). The `Wiktionary` class exposes a method for every documented route.
|
|
6
|
+
|
|
7
|
+
## Official documentation
|
|
8
|
+
|
|
9
|
+
| Resource | URL |
|
|
10
|
+
|----------|-----|
|
|
11
|
+
| Interactive API docs (Swagger UI) | https://en.wiktionary.org/api/rest_v1/#/ |
|
|
12
|
+
| OpenAPI spec (JSON) | https://en.wiktionary.org/api/rest_v1/?spec |
|
|
13
|
+
| Wikimedia REST API overview | https://www.mediawiki.org/wiki/Wikimedia_REST_API |
|
|
14
|
+
| Commons Core API (media file downloads) | https://api.wikimedia.org/wiki/Core_REST_API |
|
|
15
|
+
|
|
16
|
+
## Summary
|
|
17
|
+
|
|
18
|
+
| Category | Status |
|
|
19
|
+
|----------|--------|
|
|
20
|
+
| All paths in the Wiktionary OpenAPI spec | Implemented |
|
|
21
|
+
| PDF rendering (`GET /page/pdf/…`) | Implemented (`get_pdf`); works on Wiktionary but omitted from `?spec` |
|
|
22
|
+
| Wikipedia-only routes (e.g. `/page/summary/`) | Out of scope |
|
|
23
|
+
| MediaWiki Action API (`/w/api.php`) | Out of scope |
|
|
24
|
+
|
|
25
|
+
## Page content
|
|
26
|
+
|
|
27
|
+
| HTTP | REST path | Client method |
|
|
28
|
+
|------|-----------|---------------|
|
|
29
|
+
| GET | `/page/` | `page()` |
|
|
30
|
+
| GET | `/page/definition/{term}` | `get_definition` |
|
|
31
|
+
| GET | `/page/html/{title}` | `get_html` |
|
|
32
|
+
| GET | `/page/html/{title}/{revision}` | `get_html` |
|
|
33
|
+
| GET | `/page/lint/{title}` | `get_lint` |
|
|
34
|
+
| GET | `/page/lint/{title}/{revision}` | `get_lint` |
|
|
35
|
+
| GET | `/page/media-list/{title}` | `get_media_file_list` |
|
|
36
|
+
| GET | `/page/media-list/{title}/{revision}` | `get_media_file_list` |
|
|
37
|
+
| GET | `/page/mobile-html/{title}` | `get_mobile_html` |
|
|
38
|
+
| GET | `/page/mobile-html/{title}/{revision}` | `get_mobile_html` |
|
|
39
|
+
| GET | `/page/mobile-html-offline-resources/{title}` | `get_mobile_html_offline_resources` |
|
|
40
|
+
| GET | `/page/mobile-html-offline-resources/{title}/{revision}` | `get_mobile_html_offline_resources` |
|
|
41
|
+
| GET | `/page/title/{title}` | `get_revision` |
|
|
42
|
+
| GET | `/page/title/{title}/{revision}` | `get_revision` |
|
|
43
|
+
| GET | `/page/pdf/{title}/{format}/{type}` | `get_pdf`, `download_pdf` *(not in OpenAPI spec)* |
|
|
44
|
+
|
|
45
|
+
## Data
|
|
46
|
+
|
|
47
|
+
| HTTP | REST path | Client method |
|
|
48
|
+
|------|-----------|---------------|
|
|
49
|
+
| GET | `/data/citation/{format}/{query}` | `get_citation` |
|
|
50
|
+
| GET | `/data/css/mobile/{type}` | `get_mobile_css` |
|
|
51
|
+
| GET | `/data/javascript/mobile/{type}` | `get_mobile_javascript` |
|
|
52
|
+
| GET | `/data/i18n/{type}` | `get_i18n` |
|
|
53
|
+
| GET | `/data/lists/` | `get_lists` |
|
|
54
|
+
| POST | `/data/lists/` | `create_list` |
|
|
55
|
+
| POST | `/data/lists/batch` | `create_lists_batch` |
|
|
56
|
+
| GET | `/data/lists/changes/since/{date}` | `get_list_changes_since` |
|
|
57
|
+
| GET | `/data/lists/pages/{project}/{title}` | `get_lists_for_page` |
|
|
58
|
+
| POST | `/data/lists/setup` | `setup_lists` |
|
|
59
|
+
| POST | `/data/lists/teardown` | `teardown_lists` |
|
|
60
|
+
| PUT | `/data/lists/{id}` | `update_list` |
|
|
61
|
+
| DELETE | `/data/lists/{id}` | `delete_list` |
|
|
62
|
+
| GET | `/data/lists/{id}/entries/` | `get_list_entries` |
|
|
63
|
+
| POST | `/data/lists/{id}/entries/` | `create_list_entry` |
|
|
64
|
+
| POST | `/data/lists/{id}/entries/batch` | `create_list_entries_batch` |
|
|
65
|
+
| DELETE | `/data/lists/{id}/entries/{entry_id}` | `delete_list_entry` |
|
|
66
|
+
|
|
67
|
+
Reading list endpoints require an authenticated session and a `csrf_token` query parameter.
|
|
68
|
+
|
|
69
|
+
## Transform
|
|
70
|
+
|
|
71
|
+
| HTTP | REST path | Client method |
|
|
72
|
+
|------|-----------|---------------|
|
|
73
|
+
| POST | `/transform/wikitext/to/html` | `transform_wikitext_to_html` |
|
|
74
|
+
| POST | `/transform/wikitext/to/html/{title}` | `transform_wikitext_to_html` |
|
|
75
|
+
| POST | `/transform/wikitext/to/html/{title}/{revision}` | `transform_wikitext_to_html` |
|
|
76
|
+
| POST | `/transform/html/to/wikitext` | `transform_html_to_wikitext` |
|
|
77
|
+
| POST | `/transform/html/to/wikitext/{title}` | `transform_html_to_wikitext` |
|
|
78
|
+
| POST | `/transform/html/to/wikitext/{title}/{revision}` | `transform_html_to_wikitext` |
|
|
79
|
+
| POST | `/transform/wikitext/to/lint` | `transform_wikitext_to_lint` |
|
|
80
|
+
| POST | `/transform/wikitext/to/lint/{title}` | `transform_wikitext_to_lint` |
|
|
81
|
+
| POST | `/transform/wikitext/to/lint/{title}/{revision}` | `transform_wikitext_to_lint` |
|
|
82
|
+
| POST | `/transform/wikitext/to/mobile-html/{title}` | `transform_wikitext_to_mobile_html` |
|
|
83
|
+
|
|
84
|
+
Pass `title=None` (and optionally `revision=None`) to hit the path variants without `{title}` in the URL.
|
|
85
|
+
|
|
86
|
+
## Media / math
|
|
87
|
+
|
|
88
|
+
| HTTP | REST path | Client method |
|
|
89
|
+
|------|-----------|---------------|
|
|
90
|
+
| POST | `/media/math/check/{type}` | `check_math` |
|
|
91
|
+
| GET | `/media/math/formula/{hash}` | `get_math_formula` |
|
|
92
|
+
| GET | `/media/math/render/{format}/{hash}` | `render_math` |
|
|
93
|
+
|
|
94
|
+
`check_math` accepts `tex`, `inline-tex`, or `chem`. `render_math` accepts `svg`, `mml`, or `png`.
|
|
95
|
+
|
|
96
|
+
## Commons helpers (not Wiktionary REST v1)
|
|
97
|
+
|
|
98
|
+
| Purpose | Client method |
|
|
99
|
+
|---------|---------------|
|
|
100
|
+
| Download media bytes for a page | `get_media_files` |
|
|
101
|
+
| Save media files to disk | `download_media_files` |
|
|
102
|
+
|
|
103
|
+
## Utilities
|
|
104
|
+
|
|
105
|
+
| Purpose | Symbol |
|
|
106
|
+
|---------|--------|
|
|
107
|
+
| Save PDF response bytes | `pdf_from_bytes` (`wikt.util`) |
|
|
108
|
+
|
|
109
|
+
## Out of scope
|
|
110
|
+
|
|
111
|
+
- `/page/summary/{title}`, talk pages, recommendations (Wikipedia-only)
|
|
112
|
+
- MediaWiki Action API (`https://en.wiktionary.org/w/api.php`)
|
|
113
|
+
- Offline dumps → [wiktextract](https://github.com/tatuylonen/wiktextract)
|
|
114
|
+
|
|
115
|
+
## Re-checking coverage
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
python -c "import requests; s=requests.get('https://en.wiktionary.org/api/rest_v1/?spec', headers={'User-Agent':'MyApp (you@example.com)'}).json(); print(len(s['paths']), 'paths')"
|
|
119
|
+
```
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wiktionary-api"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Synchronous Python client for the Wikimedia Wiktionary REST API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Nebil Ibrahim" },
|
|
14
|
+
]
|
|
15
|
+
keywords = ["wiktionary", "wikimedia", "dictionary", "rest-api", "requests"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Text Processing :: Linguistic",
|
|
27
|
+
"Typing :: Typed",
|
|
28
|
+
]
|
|
29
|
+
dependencies = [
|
|
30
|
+
"requests>=2.32,<3",
|
|
31
|
+
"PyPDF2>=3.0.1,<4",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.optional-dependencies]
|
|
35
|
+
dev = [
|
|
36
|
+
"pytest>=8.3",
|
|
37
|
+
"ruff>=0.9",
|
|
38
|
+
"build>=1.2",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.urls]
|
|
42
|
+
Homepage = "https://github.com/NebilI/WiktionaryPythonAPI"
|
|
43
|
+
Repository = "https://github.com/NebilI/WiktionaryPythonAPI"
|
|
44
|
+
Issues = "https://github.com/NebilI/WiktionaryPythonAPI/issues"
|
|
45
|
+
Documentation = "https://github.com/NebilI/WiktionaryPythonAPI#readme"
|
|
46
|
+
|
|
47
|
+
[dependency-groups]
|
|
48
|
+
dev = [
|
|
49
|
+
"pytest>=8.3",
|
|
50
|
+
"ruff>=0.9",
|
|
51
|
+
"build>=1.2",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.hatch.build.targets.wheel]
|
|
55
|
+
packages = ["src/wikt"]
|
|
56
|
+
|
|
57
|
+
[tool.hatch.build.targets.sdist]
|
|
58
|
+
include = [
|
|
59
|
+
"/src",
|
|
60
|
+
"/tests",
|
|
61
|
+
"/docs",
|
|
62
|
+
"/README.md",
|
|
63
|
+
"/LICENSE",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.pytest.ini_options]
|
|
67
|
+
testpaths = ["tests"]
|
|
68
|
+
pythonpath = ["src"]
|
|
69
|
+
|
|
70
|
+
[tool.ruff]
|
|
71
|
+
line-length = 100
|
|
72
|
+
target-version = "py310"
|
|
73
|
+
src = ["src", "tests"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff.lint]
|
|
76
|
+
select = [
|
|
77
|
+
"E", # pycodestyle errors
|
|
78
|
+
"W", # pycodestyle warnings
|
|
79
|
+
"F", # pyflakes
|
|
80
|
+
"I", # isort
|
|
81
|
+
"B", # flake8-bugbear
|
|
82
|
+
"UP", # pyupgrade
|
|
83
|
+
]
|
|
84
|
+
ignore = [
|
|
85
|
+
"E501", # line length handled separately; docs/URLs are long
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.per-file-ignores]
|
|
89
|
+
"tests/**/*.py" = ["B011"]
|