Wikipedia-API 0.12.0__tar.gz → 0.14.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.
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/API.rst +80 -4
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/CHANGES.rst +14 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/CLI.rst +42 -6
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/DESIGN.rst +212 -33
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/DEVELOPMENT.rst +9 -6
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/PKG-INFO +38 -4
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/README.rst +37 -3
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/README_processed.rst +37 -3
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/SKILL.md +47 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/async.py +47 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/cli.sh +27 -0
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/sync.py +41 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/SKILL.md +56 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/async.py +93 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/cli.sh +70 -0
- wikipedia_api-0.14.0/SKILLS/custom_page_output/sync.py +81 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/SKILL.md +46 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/async.py +44 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/cli.sh +30 -0
- wikipedia_api-0.14.0/SKILLS/explore_nearby/sync.py +37 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/SKILL.md +50 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/async.py +56 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/cli.sh +27 -0
- wikipedia_api-0.14.0/SKILLS/media_audit/sync.py +49 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/SKILL.md +47 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/async.py +52 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/cli.sh +35 -0
- wikipedia_api-0.14.0/SKILLS/multilingual_content/sync.py +43 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/SKILL.md +48 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/async.py +60 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/cli.sh +38 -0
- wikipedia_api-0.14.0/SKILLS/research_topic/sync.py +53 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/example_async.py +33 -13
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/example_sync.py +33 -10
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/pyproject.toml +60 -25
- wikipedia_api-0.14.0/wikipediaapi/__init__.py +150 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/_base_wikipedia_page.py +8 -4
- wikipedia_api-0.14.0/wikipediaapi/_enums/__init__.py +196 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/coordinate_type.py +64 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/coordinates_prop.py +78 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/direction.py +56 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/geosearch_sort.py +51 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/globe.py +58 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/namespace.py +148 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/redirect_filter.py +61 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/search_info.py +64 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/search_prop.py +110 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/search_qi_profile.py +78 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/search_sort.py +62 -0
- wikipedia_api-0.14.0/wikipediaapi/_enums/search_what.py +64 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/__init__.py +17 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/async_http_client.py +125 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/base_http_client.py +257 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/retry_after_wait.py +48 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/retry_utils.py +30 -0
- wikipedia_api-0.14.0/wikipediaapi/_http_client/sync_http_client.py +123 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/__init__.py +26 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/async_images_dict.py +69 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/async_pages_dict.py +118 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/base_pages_dict.py +97 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/images_dict.py +73 -0
- wikipedia_api-0.14.0/wikipediaapi/_pages_dict/pages_dict.py +121 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/__init__.py +21 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/base_params.py +64 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/coordinates_params.py +87 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/geo_search_params.py +136 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/imageinfo_params.py +58 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/images_params.py +59 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/protocols.py +8 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/random_params.py +60 -0
- wikipedia_api-0.14.0/wikipediaapi/_params/search_params.py +118 -0
- wikipedia_api-0.14.0/wikipediaapi/_resources/__init__.py +15 -0
- wikipedia_api-0.14.0/wikipediaapi/_resources/async_wikipedia_resource.py +830 -0
- wikipedia_api-0.14.0/wikipediaapi/_resources/base_wikipedia_resource.py +1335 -0
- wikipedia_api-0.14.0/wikipediaapi/_resources/wikipedia_resource.py +874 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/__init__.py +25 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/coordinate.py +42 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/geo_box.py +53 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/geo_point.py +49 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/geo_search_meta.py +30 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/image_info.py +44 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/search_meta.py +30 -0
- wikipedia_api-0.14.0/wikipediaapi/_types/search_results.py +32 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/_version.py +1 -1
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/async_wikipedia.py +5 -1
- wikipedia_api-0.14.0/wikipediaapi/async_wikipedia_image.py +282 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/async_wikipedia_page.py +17 -14
- wikipedia_api-0.14.0/wikipediaapi/cli.py +55 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/__init__.py +4 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/base.py +368 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/category_commands.py +172 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/geo_commands.py +387 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/image_commands.py +174 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/link_commands.py +213 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/page_commands.py +305 -0
- wikipedia_api-0.14.0/wikipediaapi/commands/search_commands.py +277 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/__init__.py +23 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wiki_connection_error.py +27 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wiki_http_error.py +30 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wiki_http_timeout_error.py +27 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wiki_invalid_json_error.py +26 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wiki_rate_limit_error.py +33 -0
- wikipedia_api-0.14.0/wikipediaapi/exceptions/wikipedia_exception.py +20 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia.py +6 -2
- wikipedia_api-0.14.0/wikipediaapi/wikipedia_image.py +242 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia_page.py +21 -15
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/wikipedia_page_section.py +6 -3
- wikipedia_api-0.12.0/wikipediaapi/__init__.py +0 -127
- wikipedia_api-0.12.0/wikipediaapi/_enums.py +0 -959
- wikipedia_api-0.12.0/wikipediaapi/_http_client.py +0 -495
- wikipedia_api-0.12.0/wikipediaapi/_pages_dict.py +0 -255
- wikipedia_api-0.12.0/wikipediaapi/_params.py +0 -429
- wikipedia_api-0.12.0/wikipediaapi/_resources.py +0 -2576
- wikipedia_api-0.12.0/wikipediaapi/_types.py +0 -194
- wikipedia_api-0.12.0/wikipediaapi/cli.py +0 -1481
- wikipedia_api-0.12.0/wikipediaapi/exceptions.py +0 -134
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/.gitignore +0 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/LICENSE +0 -0
- {wikipedia_api-0.12.0 → wikipedia_api-0.14.0}/wikipediaapi/extract_format.py +0 -0
|
@@ -7,7 +7,9 @@ Wikipedia
|
|
|
7
7
|
* ``page(title, ns=Namespace.MAIN)``
|
|
8
8
|
* ``pages(titles)`` — create a ``PagesDict`` of lazy pages (no network call)
|
|
9
9
|
* ``coordinates(page, *, limit=10, primary='primary', prop=('globe',), distance_from_point=None (GeoPoint), distance_from_page=None)`` → ``list[Coordinate]``
|
|
10
|
-
* ``images(page, *, limit=10, images=None, direction=Direction.ASCENDING)`` → ``
|
|
10
|
+
* ``images(page, *, limit=10, images=None, direction=Direction.ASCENDING)`` → ``ImagesDict``
|
|
11
|
+
* ``imageinfo(image, *, prop=('url', 'width', 'height', ...), limit=1)`` → ``list[ImageInfo]``
|
|
12
|
+
* ``batch_imageinfo(images, *, prop=('url', 'width', 'height', ...), limit=1)`` → ``dict[str, list[ImageInfo]]``
|
|
11
13
|
* ``geosearch(*, coord=None (GeoPoint), page=None, bbox=None (GeoBox), radius=500, max_dim=None, sort='distance', limit=10, ns=Namespace.MAIN, prop=None)`` → ``PagesDict``
|
|
12
14
|
* ``random(*, limit=1, ns=Namespace.MAIN, filter_redir='nonredirects')`` → ``PagesDict``
|
|
13
15
|
* ``search(query, *, ns=Namespace.MAIN, limit=10, prop=None, info=None, sort='relevance')`` → ``SearchResults``
|
|
@@ -22,7 +24,9 @@ Same constructor parameters as ``Wikipedia``. All methods are coroutines
|
|
|
22
24
|
* ``page(title, ns=Namespace.MAIN)`` — returns an ``AsyncWikipediaPage`` (no network call)
|
|
23
25
|
* ``pages(titles)`` — create an ``AsyncPagesDict`` of lazy pages (no network call)
|
|
24
26
|
* ``await coordinates(page, ...)`` → ``list[Coordinate]``
|
|
25
|
-
* ``await images(page, ...)`` → ``
|
|
27
|
+
* ``await images(page, ...)`` → ``ImagesDict``
|
|
28
|
+
* ``await imageinfo(image, ...)`` → ``list[ImageInfo]``
|
|
29
|
+
* ``await batch_imageinfo(images, ...)`` → ``dict[str, list[ImageInfo]]``
|
|
26
30
|
* ``await geosearch(...)`` → ``PagesDict``
|
|
27
31
|
* ``await random(...)`` → ``PagesDict``
|
|
28
32
|
* ``await search(query, ...)`` → ``SearchResults``
|
|
@@ -46,7 +50,7 @@ WikipediaPage
|
|
|
46
50
|
* ``categories`` - categories this page belongs to ({title: ``WikipediaPage``})
|
|
47
51
|
* ``categorymembers`` - pages in this category, when ``ns=Namespace.CATEGORY`` ({title: ``WikipediaPage``})
|
|
48
52
|
* ``coordinates`` - geographic coordinates (list of ``Coordinate``); triggers ``coordinates`` API call with default params
|
|
49
|
-
* ``images`` - images/files on this page (``
|
|
53
|
+
* ``images`` - images/files on this page (``ImagesDict``); triggers ``images`` API call with default params
|
|
50
54
|
* ``geosearch_meta`` - ``GeoSearchMeta`` or ``None``; set when page came from ``geosearch()`` (plain property, no fetch)
|
|
51
55
|
* ``search_meta`` - ``SearchMeta`` or ``None``; set when page came from ``search()`` (plain property, no fetch)
|
|
52
56
|
* ``displaytitle``
|
|
@@ -87,7 +91,7 @@ return coroutines (awaitable with ``await``).
|
|
|
87
91
|
* ``await page.categories`` — awaitable property; ``{title: AsyncWikipediaPage}`` dict
|
|
88
92
|
* ``await page.categorymembers`` — awaitable property; ``{title: AsyncWikipediaPage}`` dict
|
|
89
93
|
* ``await page.coordinates`` — awaitable property; ``list[Coordinate]``
|
|
90
|
-
* ``await page.images`` — awaitable property; ``
|
|
94
|
+
* ``await page.images`` — awaitable property; ``ImagesDict``
|
|
91
95
|
* ``page.geosearch_meta`` — plain property; ``GeoSearchMeta | None`` (no await)
|
|
92
96
|
* ``page.search_meta`` — plain property; ``SearchMeta | None`` (no await)
|
|
93
97
|
* ``await page.exists()`` — coroutine method; lazily fetches ``pageid`` via ``info`` if not yet cached
|
|
@@ -103,6 +107,60 @@ WikipediaPageSection
|
|
|
103
107
|
* ``section_by_title(title)``
|
|
104
108
|
* ``full_text(level=1)`` - rendered text of this section and all descendants
|
|
105
109
|
|
|
110
|
+
WikipediaImage
|
|
111
|
+
---------------
|
|
112
|
+
Lazy representation of a Wikipedia/Commons file page. No network call is
|
|
113
|
+
made at construction time; accessing ``imageinfo`` (or any convenience
|
|
114
|
+
property derived from it) triggers the minimum API call needed.
|
|
115
|
+
|
|
116
|
+
* ``title`` — file title including the ``File:`` prefix
|
|
117
|
+
* ``language`` — two-letter language code
|
|
118
|
+
* ``namespace`` — integer namespace number (6 for files)
|
|
119
|
+
* ``pageid`` — MediaWiki page ID
|
|
120
|
+
* ``imageinfo`` — list of ``ImageInfo`` objects (lazy-fetched; triggers API call)
|
|
121
|
+
* ``url`` — full URL of the file (from first ``ImageInfo``)
|
|
122
|
+
* ``width`` — image width in pixels (from first ``ImageInfo``)
|
|
123
|
+
* ``height`` — image height in pixels (from first ``ImageInfo``)
|
|
124
|
+
* ``size`` — file size in bytes (from first ``ImageInfo``)
|
|
125
|
+
* ``mime`` — MIME type (from first ``ImageInfo``)
|
|
126
|
+
* ``mediatype`` — MediaWiki media type (from first ``ImageInfo``)
|
|
127
|
+
* ``sha1`` — SHA-1 hash of the file (from first ``ImageInfo``)
|
|
128
|
+
* ``timestamp`` — ISO 8601 timestamp of this revision (from first ``ImageInfo``)
|
|
129
|
+
* ``user`` — username of the uploader (from first ``ImageInfo``)
|
|
130
|
+
* ``descriptionurl`` — URL of the file description page (from first ``ImageInfo``)
|
|
131
|
+
* ``descriptionshorturl`` — short URL of the description page (from first ``ImageInfo``)
|
|
132
|
+
|
|
133
|
+
AsyncWikipediaImage
|
|
134
|
+
--------------------
|
|
135
|
+
Async mirror of ``WikipediaImage``. All properties that trigger network calls
|
|
136
|
+
are awaitable (use ``await``).
|
|
137
|
+
|
|
138
|
+
* ``title``, ``language``, ``namespace``, ``pageid`` — plain properties (no await)
|
|
139
|
+
* ``await imageinfo`` — awaitable property; list of ``ImageInfo`` objects
|
|
140
|
+
* ``await url`` — awaitable property; full URL of the file
|
|
141
|
+
* ``await width`` — awaitable property; image width in pixels
|
|
142
|
+
* ``await height`` — awaitable property; image height in pixels
|
|
143
|
+
* ``await size`` — awaitable property; file size in bytes
|
|
144
|
+
* ``await mime`` — awaitable property; MIME type
|
|
145
|
+
* ``await mediatype`` — awaitable property; MediaWiki media type
|
|
146
|
+
* ``await sha1`` — awaitable property; SHA-1 hash of the file
|
|
147
|
+
* ``await timestamp`` — awaitable property; ISO 8601 timestamp
|
|
148
|
+
* ``await user`` — awaitable property; username of uploader
|
|
149
|
+
* ``await descriptionurl`` — awaitable property; description page URL
|
|
150
|
+
* ``await descriptionshorturl`` — awaitable property; short description page URL
|
|
151
|
+
|
|
152
|
+
ImagesDict
|
|
153
|
+
----------
|
|
154
|
+
A ``dict[str, WikipediaImage]`` subclass with batch convenience methods.
|
|
155
|
+
|
|
156
|
+
* ``imageinfo(*, prop=_DEFAULT_PROP, limit=1)`` → ``dict[str, list[ImageInfo]]`` — batch-fetch ``imageinfo`` for all images via ``batch_imageinfo()``
|
|
157
|
+
|
|
158
|
+
AsyncImagesDict
|
|
159
|
+
---------------
|
|
160
|
+
Async mirror of ``ImagesDict``.
|
|
161
|
+
|
|
162
|
+
* ``await imageinfo(*, prop=_DEFAULT_PROP, limit=1)`` → ``dict[str, list[ImageInfo]]``
|
|
163
|
+
|
|
106
164
|
ExtractFormat
|
|
107
165
|
-------------
|
|
108
166
|
* ``WIKI`` - plain-text wiki markup (``==Heading==``)
|
|
@@ -194,6 +252,24 @@ Frozen dataclass attached to pages returned by ``search()``.
|
|
|
194
252
|
* ``wordcount: int`` — word count
|
|
195
253
|
* ``timestamp: str`` — last edit timestamp (ISO 8601)
|
|
196
254
|
|
|
255
|
+
``ImageInfo``
|
|
256
|
+
~~~~~~~~~~~~~
|
|
257
|
+
Frozen dataclass representing one file revision from ``prop=imageinfo``.
|
|
258
|
+
All fields are optional and depend on the ``iiprop`` parameter and file
|
|
259
|
+
availability.
|
|
260
|
+
|
|
261
|
+
* ``url: str | None`` — full URL of the file
|
|
262
|
+
* ``descriptionurl: str | None`` — URL of the file description page
|
|
263
|
+
* ``descriptionshorturl: str | None`` — short URL of the description page
|
|
264
|
+
* ``width: int | None`` — image width in pixels
|
|
265
|
+
* ``height: int | None`` — image height in pixels
|
|
266
|
+
* ``size: int | None`` — file size in bytes
|
|
267
|
+
* ``mime: str | None`` — MIME type (e.g. ``"image/jpeg"``)
|
|
268
|
+
* ``mediatype: str | None`` — MediaWiki media type (e.g. ``"BITMAP"``)
|
|
269
|
+
* ``sha1: str | None`` — SHA-1 hash of the file content
|
|
270
|
+
* ``timestamp: str | None`` — ISO 8601 timestamp of this revision
|
|
271
|
+
* ``user: str | None`` — username of the uploader
|
|
272
|
+
|
|
197
273
|
``SearchResults``
|
|
198
274
|
~~~~~~~~~~~~~~~~~
|
|
199
275
|
Wrapper returned by ``search()``.
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
0.14.0
|
|
5
|
+
------
|
|
6
|
+
|
|
7
|
+
* Add WikipediaImage, ImagesDict, and imageinfo API - `PR 525`_
|
|
8
|
+
|
|
9
|
+
.. _PR 525: https://github.com/martin-majlis/Wikipedia-API/pull/525
|
|
10
|
+
|
|
11
|
+
0.13.0
|
|
12
|
+
------
|
|
13
|
+
|
|
14
|
+
* Pass parameters to the underlying htttp client - `PR 520`_
|
|
15
|
+
|
|
16
|
+
.. _PR 520: https://github.com/martin-majlis/Wikipedia-API/pull/520
|
|
17
|
+
|
|
4
18
|
0.12.0
|
|
5
19
|
------
|
|
6
20
|
|
|
@@ -15,12 +15,35 @@ Every command supports the following options:
|
|
|
15
15
|
* ``-v, --variant`` — Language variant (e.g. ``zh-cn``, ``zh-tw``)
|
|
16
16
|
* ``-f, --extract-format`` — Extraction format: ``wiki`` or ``html`` (default: ``wiki``)
|
|
17
17
|
* ``-n, --namespace`` — Wikipedia namespace number (default: ``0`` = Main)
|
|
18
|
+
* ``--max-retries`` — Maximum number of retry attempts for transient errors (HTTP 429, 5xx, timeouts, connection errors). Set to ``0`` to disable retries entirely (default: ``3``)
|
|
19
|
+
* ``--retry-wait`` — Base wait time in seconds between retries; actual wait uses exponential backoff (``retry_wait * 2^attempt``). For HTTP 429 the ``Retry-After`` header value is used instead (default: ``1.0``)
|
|
18
20
|
* ``-h, --help`` — Show help for any command
|
|
19
21
|
|
|
20
22
|
Commands that return lists also support:
|
|
21
23
|
|
|
22
24
|
* ``--json`` — Output results as JSON
|
|
23
25
|
|
|
26
|
+
Retry Configuration
|
|
27
|
+
-------------------
|
|
28
|
+
|
|
29
|
+
Control retry behavior for network issues and rate limiting:
|
|
30
|
+
|
|
31
|
+
Use custom retry settings::
|
|
32
|
+
|
|
33
|
+
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0
|
|
34
|
+
|
|
35
|
+
Disable retries entirely (fail fast on first error)::
|
|
36
|
+
|
|
37
|
+
wikipedia-api search "Python" --max-retries 0
|
|
38
|
+
|
|
39
|
+
Use aggressive retrying for unreliable connections::
|
|
40
|
+
|
|
41
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278" --max-retries 10 --retry-wait 3.0
|
|
42
|
+
|
|
43
|
+
Combine with other options::
|
|
44
|
+
|
|
45
|
+
wikipedia-api random --limit 5 --max-retries 1 --retry-wait 0.5 --language de
|
|
46
|
+
|
|
24
47
|
Getting Help
|
|
25
48
|
------------
|
|
26
49
|
|
|
@@ -173,10 +196,23 @@ Output as JSON::
|
|
|
173
196
|
|
|
174
197
|
wikipedia-api images "Python (programming language)" --json
|
|
175
198
|
|
|
199
|
+
Fetch image metadata (URL, dimensions, MIME type, uploader, etc.) with
|
|
200
|
+
the ``--imageinfo`` flag::
|
|
201
|
+
|
|
202
|
+
wikipedia-api images "Mount Everest" --imageinfo
|
|
203
|
+
|
|
204
|
+
Display imageinfo metadata as JSON::
|
|
205
|
+
|
|
206
|
+
wikipedia-api images "Mount Everest" --imageinfo --json
|
|
207
|
+
|
|
176
208
|
Limit the number of images::
|
|
177
209
|
|
|
178
210
|
wikipedia-api images "Earth" --limit 50
|
|
179
211
|
|
|
212
|
+
Combine options::
|
|
213
|
+
|
|
214
|
+
wikipedia-api images "Earth" --limit 20 --imageinfo --language de
|
|
215
|
+
|
|
180
216
|
Geosearch
|
|
181
217
|
---------
|
|
182
218
|
|
|
@@ -227,8 +263,8 @@ Complete Workflow Example
|
|
|
227
263
|
|
|
228
264
|
Fetch a page summary, then explore its sections and links::
|
|
229
265
|
|
|
230
|
-
# Get summary
|
|
231
|
-
wikipedia-api summary "Python (programming language)"
|
|
266
|
+
# Get summary with custom retry settings
|
|
267
|
+
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0
|
|
232
268
|
|
|
233
269
|
# List sections
|
|
234
270
|
wikipedia-api sections "Python (programming language)"
|
|
@@ -248,11 +284,11 @@ Fetch a page summary, then explore its sections and links::
|
|
|
248
284
|
# Show coordinates for a geographic page
|
|
249
285
|
wikipedia-api coordinates "Mount Everest"
|
|
250
286
|
|
|
251
|
-
# Search for pages near a location
|
|
252
|
-
wikipedia-api geosearch --coord "27.9881|86.9250"
|
|
287
|
+
# Search for pages near a location with aggressive retrying
|
|
288
|
+
wikipedia-api geosearch --coord "27.9881|86.9250" --max-retries 10 --retry-wait 3.0
|
|
253
289
|
|
|
254
|
-
# Search Wikipedia
|
|
255
|
-
wikipedia-api search "Mount Everest"
|
|
290
|
+
# Search Wikipedia with retries disabled
|
|
291
|
+
wikipedia-api search "Mount Everest" --max-retries 0
|
|
256
292
|
|
|
257
293
|
# Get random pages
|
|
258
294
|
wikipedia-api random --limit 3
|
|
@@ -34,25 +34,85 @@ File Layout
|
|
|
34
34
|
|
|
35
35
|
wikipediaapi/
|
|
36
36
|
├── __init__.py # Public exports
|
|
37
|
-
├──
|
|
38
|
-
|
|
39
|
-
│ ├──
|
|
40
|
-
│
|
|
41
|
-
├──
|
|
42
|
-
│ ├──
|
|
43
|
-
│ ├──
|
|
44
|
-
│
|
|
45
|
-
├──
|
|
46
|
-
|
|
47
|
-
├──
|
|
37
|
+
├── cli.py # Command line interface (main entry point)
|
|
38
|
+
├── commands/ # CLI command modules
|
|
39
|
+
│ ├── __init__.py
|
|
40
|
+
│ ├── base.py # Shared utilities and common options
|
|
41
|
+
│ ├── page_commands.py # Page content commands
|
|
42
|
+
│ ├── link_commands.py # Link-related commands
|
|
43
|
+
│ ├── category_commands.py # Category commands
|
|
44
|
+
│ ├── geo_commands.py # Geographic commands
|
|
45
|
+
│ ├── image_commands.py # Image file commands
|
|
46
|
+
│ └── search_commands.py # Search and discovery commands
|
|
47
|
+
├── _http_client/ # Transport layer package
|
|
48
|
+
│ ├── __init__.py
|
|
49
|
+
│ ├── base_http_client.py # Shared retry & config logic
|
|
50
|
+
│ ├── sync_http_client.py # Blocking httpx.Client
|
|
51
|
+
│ ├── async_http_client.py # Non-blocking httpx.AsyncClient
|
|
52
|
+
│ ├── retry_utils.py # Retry utilities
|
|
53
|
+
│ └── retry_after_wait.py # Retry-After header handling
|
|
54
|
+
├── _resources/ # API layer package
|
|
55
|
+
│ ├── __init__.py
|
|
56
|
+
│ ├── base_wikipedia_resource.py # Param builders, parsers, dispatchers
|
|
57
|
+
│ ├── wikipedia_resource.py # Sync public API methods
|
|
58
|
+
│ └── async_wikipedia_resource.py # Async public API methods
|
|
59
|
+
├── _types/ # Typed dataclasses package
|
|
60
|
+
│ ├── __init__.py
|
|
61
|
+
│ ├── coordinate.py # Coordinate dataclass
|
|
62
|
+
│ ├── geo_point.py # GeoPoint dataclass
|
|
63
|
+
│ ├── geo_box.py # GeoBox dataclass
|
|
64
|
+
│ ├── geo_search_meta.py # GeoSearchMeta dataclass
|
|
65
|
+
│ ├── image_info.py # ImageInfo dataclass
|
|
66
|
+
│ ├── search_meta.py # SearchMeta dataclass
|
|
67
|
+
│ └── search_results.py # SearchResults dataclass
|
|
68
|
+
├── _params/ # Query parameter dataclasses package
|
|
69
|
+
│ ├── __init__.py
|
|
70
|
+
│ ├── base_params.py # Base parameter class
|
|
71
|
+
│ ├── coordinates_params.py # CoordinatesParams
|
|
72
|
+
│ ├── geo_search_params.py # GeoSearchParams
|
|
73
|
+
│ ├── images_params.py # ImagesParams
|
|
74
|
+
│ ├── random_params.py # RandomParams
|
|
75
|
+
│ ├── search_params.py # SearchParams
|
|
76
|
+
│ └── protocols.py # Protocol constants
|
|
77
|
+
├── _pages_dict/ # PagesDict and ImagesDict package
|
|
78
|
+
│ ├── __init__.py
|
|
79
|
+
│ ├── base_pages_dict.py # Base PagesDict functionality
|
|
80
|
+
│ ├── pages_dict.py # PagesDict (sync)
|
|
81
|
+
│ ├── async_pages_dict.py # AsyncPagesDict
|
|
82
|
+
│ ├── images_dict.py # ImagesDict (sync)
|
|
83
|
+
│ └── async_images_dict.py # AsyncImagesDict
|
|
84
|
+
├── _enums/ # Enums package
|
|
85
|
+
│ ├── __init__.py
|
|
86
|
+
│ ├── coordinate_type.py # CoordinateType enum
|
|
87
|
+
│ ├── coordinates_prop.py # CoordinatesProp enum
|
|
88
|
+
│ ├── direction.py # Direction enum
|
|
89
|
+
│ ├── geosearch_sort.py # GeoSearchSort enum
|
|
90
|
+
│ ├── globe.py # Globe enum
|
|
91
|
+
│ ├── namespace.py # Namespace enum
|
|
92
|
+
│ ├── redirect_filter.py # RedirectFilter enum
|
|
93
|
+
│ ├── search_info.py # SearchInfo enum
|
|
94
|
+
│ ├── search_prop.py # SearchProp enum
|
|
95
|
+
│ ├── search_qi_profile.py # SearchQiProfile enum
|
|
96
|
+
│ ├── search_sort.py # SearchSort enum
|
|
97
|
+
│ └── search_what.py # SearchWhat enum
|
|
98
|
+
├── exceptions/ # Exception classes package
|
|
99
|
+
│ ├── __init__.py
|
|
100
|
+
│ ├── wikipedia_exception.py # Base exception
|
|
101
|
+
│ ├── wiki_connection_error.py # Connection errors
|
|
102
|
+
│ ├── wiki_http_error.py # HTTP errors
|
|
103
|
+
│ ├── wiki_http_timeout_error.py # Timeout errors
|
|
104
|
+
│ ├── wiki_invalid_json_error.py # JSON parsing errors
|
|
105
|
+
│ └── wiki_rate_limit_error.py # Rate limiting errors
|
|
48
106
|
├── wikipedia.py # Wikipedia (sync concrete client)
|
|
49
107
|
├── async_wikipedia.py # AsyncWikipedia (async concrete client)
|
|
50
108
|
├── _base_wikipedia_page.py # BaseWikipediaPage (shared page state & methods)
|
|
51
109
|
├── wikipedia_page.py # WikipediaPage (lazy sync page object)
|
|
52
110
|
├── async_wikipedia_page.py # AsyncWikipediaPage (lazy async page object)
|
|
111
|
+
├── wikipedia_image.py # WikipediaImage (lazy sync file page object)
|
|
112
|
+
├── async_wikipedia_image.py # AsyncWikipediaImage (lazy async file page object)
|
|
53
113
|
├── wikipedia_page_section.py # WikipediaPageSection
|
|
54
114
|
├── extract_format.py # ExtractFormat enum (WIKI / HTML)
|
|
55
|
-
└── namespace.py #
|
|
115
|
+
└── namespace.py # Legacy namespace module (redirects to _enums.namespace)
|
|
56
116
|
|
|
57
117
|
|
|
58
118
|
Class Hierarchy
|
|
@@ -70,7 +130,9 @@ The inheritance chains are::
|
|
|
70
130
|
|
|
71
131
|
BaseWikipediaPage
|
|
72
132
|
├── WikipediaPage
|
|
73
|
-
|
|
133
|
+
├── AsyncWikipediaPage
|
|
134
|
+
├── WikipediaImage
|
|
135
|
+
└── AsyncWikipediaImage
|
|
74
136
|
|
|
75
137
|
Concrete clients compose one transport and one API mixin::
|
|
76
138
|
|
|
@@ -228,12 +290,12 @@ Full Class Diagram
|
|
|
228
290
|
Transport Layer
|
|
229
291
|
---------------
|
|
230
292
|
|
|
231
|
-
``_http_client
|
|
293
|
+
``_http_client/`` package implements the HTTP transport layer with three classes.
|
|
232
294
|
|
|
233
295
|
BaseHTTPClient
|
|
234
296
|
~~~~~~~~~~~~~~
|
|
235
297
|
|
|
236
|
-
Abstract base that holds shared configuration (language, variant,
|
|
298
|
+
Abstract base in ``base_http_client.py`` that holds shared configuration (language, variant,
|
|
237
299
|
user-agent, extract format, retry parameters, extra API params) and
|
|
238
300
|
the ``_check_and_correct_params()`` validator. It does **not** make
|
|
239
301
|
HTTP requests directly.
|
|
@@ -241,14 +303,14 @@ HTTP requests directly.
|
|
|
241
303
|
SyncHTTPClient
|
|
242
304
|
~~~~~~~~~~~~~~
|
|
243
305
|
|
|
244
|
-
Provides a blocking ``_get(language, params) -> dict`` method backed by
|
|
306
|
+
Provides a blocking ``_get(language, params) -> dict`` method in ``sync_http_client.py`` backed by
|
|
245
307
|
``httpx.Client``. Retry logic uses ``tenacity`` with exponential
|
|
246
308
|
backoff; ``Retry-After`` headers are honoured for HTTP 429 responses.
|
|
247
309
|
|
|
248
310
|
AsyncHTTPClient
|
|
249
311
|
~~~~~~~~~~~~~~~
|
|
250
312
|
|
|
251
|
-
Provides an ``async def _get(language, params) -> dict`` coroutine
|
|
313
|
+
Provides an ``async def _get(language, params) -> dict`` coroutine in ``async_http_client.py``
|
|
252
314
|
backed by ``httpx.AsyncClient``. Retry logic mirrors
|
|
253
315
|
``SyncHTTPClient`` but uses ``tenacity``'s ``AsyncRetrying``.
|
|
254
316
|
|
|
@@ -256,16 +318,21 @@ Both clients construct the endpoint URL as::
|
|
|
256
318
|
|
|
257
319
|
https://{language}.wikipedia.org/w/api.php
|
|
258
320
|
|
|
321
|
+
Additional utilities:
|
|
322
|
+
|
|
323
|
+
- ``retry_utils.py`` - Common retry utilities and helpers
|
|
324
|
+
- ``retry_after_wait.py`` - Retry-After header handling logic
|
|
325
|
+
|
|
259
326
|
|
|
260
327
|
API Layer
|
|
261
328
|
---------
|
|
262
329
|
|
|
263
|
-
``_resources
|
|
330
|
+
``_resources/`` package implements the API layer with three classes.
|
|
264
331
|
|
|
265
332
|
BaseWikipediaResource
|
|
266
333
|
~~~~~~~~~~~~~~~~~~~~~
|
|
267
334
|
|
|
268
|
-
Pure mixin with no HTTP transport. Contains:
|
|
335
|
+
Pure mixin in ``base_wikipedia_resource.py`` with no HTTP transport. Contains:
|
|
269
336
|
|
|
270
337
|
* **Parameter builders** (``_*_params``) — each returns a ``dict``
|
|
271
338
|
ready to pass to the dispatcher.
|
|
@@ -279,7 +346,7 @@ Pure mixin with no HTTP transport. Contains:
|
|
|
279
346
|
WikipediaResource
|
|
280
347
|
~~~~~~~~~~~~~~~~~
|
|
281
348
|
|
|
282
|
-
Thin synchronous mixin. Each public API method (``extracts``,
|
|
349
|
+
Thin synchronous mixin in ``wikipedia_resource.py``. Each public API method (``extracts``,
|
|
283
350
|
``info``, ``langlinks``, ``links``, ``backlinks``, ``categories``,
|
|
284
351
|
``categorymembers``) is a one-liner that delegates to the appropriate
|
|
285
352
|
sync dispatch helper::
|
|
@@ -293,7 +360,7 @@ sync dispatch helper::
|
|
|
293
360
|
AsyncWikipediaResource
|
|
294
361
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
295
362
|
|
|
296
|
-
Mirror of ``WikipediaResource`` using async dispatch helpers
|
|
363
|
+
Mirror of ``WikipediaResource`` using async dispatch helpers in ``async_wikipedia_resource.py``::
|
|
297
364
|
|
|
298
365
|
async def extracts(self, page, **kwargs):
|
|
299
366
|
return await self._async_dispatch_prop(
|
|
@@ -472,7 +539,7 @@ In ``_base_wikipedia_page.py``, add a cache slot in
|
|
|
472
539
|
Step 3 — Add the Parameter Builder
|
|
473
540
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
474
541
|
|
|
475
|
-
In ``BaseWikipediaResource`` (``_resources.py``), add::
|
|
542
|
+
In ``BaseWikipediaResource`` (``_resources/base_wikipedia_resource.py``), add::
|
|
476
543
|
|
|
477
544
|
def _templates_params(self, page: WikipediaPage) -> dict[str, Any]:
|
|
478
545
|
"""
|
|
@@ -495,7 +562,7 @@ In ``BaseWikipediaResource`` (``_resources.py``), add::
|
|
|
495
562
|
Step 4 — Add the Response Parser
|
|
496
563
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
497
564
|
|
|
498
|
-
In ``BaseWikipediaResource
|
|
565
|
+
In ``BaseWikipediaResource`` (``_resources/base_wikipedia_resource.py``), add::
|
|
499
566
|
|
|
500
567
|
def _build_templates(
|
|
501
568
|
self, extract: Any, page: WikipediaPage
|
|
@@ -691,19 +758,20 @@ preserved when adding new functionality.
|
|
|
691
758
|
``_build_*`` implementations without duplication.
|
|
692
759
|
* All raises must be documented in the docstring.
|
|
693
760
|
|
|
694
|
-
**Typed data (``_types
|
|
761
|
+
**Typed data (``_types/`` package)**
|
|
695
762
|
|
|
696
|
-
* ``
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
* ``
|
|
700
|
-
|
|
763
|
+
* ``coordinate.py`` — ``Coordinate`` frozen ``@dataclass`` value objects
|
|
764
|
+
* ``geo_point.py`` — ``GeoPoint`` frozen ``@dataclass`` value objects
|
|
765
|
+
* ``geo_box.py`` — ``GeoBox`` frozen ``@dataclass`` value objects
|
|
766
|
+
* ``geo_search_meta.py`` — ``GeoSearchMeta`` frozen ``@dataclass`` value objects
|
|
767
|
+
* ``search_meta.py`` — ``SearchMeta`` frozen ``@dataclass`` value objects
|
|
768
|
+
* ``search_results.py`` — ``SearchResults`` wrapper around ``PagesDict``
|
|
701
769
|
|
|
702
|
-
**Parameter dataclasses (``_params
|
|
770
|
+
**Parameter dataclasses (``_params/`` package)**
|
|
703
771
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
772
|
+
Each query submodule has a frozen ``@dataclass`` (e.g.
|
|
773
|
+
``CoordinatesParams``, ``ImagesParams``) that maps clean Python
|
|
774
|
+
names to MediaWiki API parameter names with a configurable prefix.
|
|
707
775
|
* Pipe-separated MediaWiki parameters (for example ``prop``, ``info``,
|
|
708
776
|
and ``images``) are exposed as iterable-only inputs in the Python API.
|
|
709
777
|
They are normalized to ``"|"``-joined strings in ``__post_init__``
|
|
@@ -712,6 +780,31 @@ preserved when adding new functionality.
|
|
|
712
780
|
API call; ``cache_key()`` returns a hashable tuple for per-parameter
|
|
713
781
|
caching.
|
|
714
782
|
|
|
783
|
+
**Enums (``_enums/`` package)**
|
|
784
|
+
|
|
785
|
+
Strongly-typed enums for API parameters:
|
|
786
|
+
* ``coordinate_type.py`` — ``CoordinateType`` enum for coordinate filtering
|
|
787
|
+
* ``coordinates_prop.py`` — ``CoordinatesProp`` enum for coordinate properties
|
|
788
|
+
* ``direction.py`` — ``Direction`` enum for sort direction
|
|
789
|
+
* ``geosearch_sort.py`` — ``GeoSearchSort`` enum for geographic search sorting
|
|
790
|
+
* ``globe.py`` — ``Globe`` enum for celestial bodies
|
|
791
|
+
* ``namespace.py`` — ``Namespace`` enum for MediaWiki namespaces
|
|
792
|
+
* ``redirect_filter.py`` — ``RedirectFilter`` enum for redirect filtering
|
|
793
|
+
* ``search_info.py`` — ``SearchInfo`` enum for search metadata
|
|
794
|
+
* ``search_prop.py`` — ``SearchProp`` enum for search properties
|
|
795
|
+
* ``search_qi_profile.py`` — ``SearchQiProfile`` enum for query-independent ranking
|
|
796
|
+
* ``search_sort.py`` — ``SearchSort`` enum for search sorting
|
|
797
|
+
* ``search_what.py`` — ``SearchWhat`` enum for search type
|
|
798
|
+
|
|
799
|
+
**Exceptions (``exceptions/`` package)**
|
|
800
|
+
|
|
801
|
+
* ``wikipedia_exception.py`` — ``WikipediaException`` base exception
|
|
802
|
+
* ``wiki_connection_error.py`` — ``WikiConnectionError`` for connection failures
|
|
803
|
+
* ``wiki_http_error.py`` — ``WikiHttpError`` for HTTP errors
|
|
804
|
+
* ``wiki_http_timeout_error.py`` — ``WikiHttpTimeoutError`` for timeouts
|
|
805
|
+
* ``wiki_invalid_json_error.py`` — ``WikiInvalidJsonError`` for JSON parsing errors
|
|
806
|
+
* ``wiki_rate_limit_error.py`` — ``WikiRateLimitError`` for rate limiting
|
|
807
|
+
|
|
715
808
|
**Per-parameter caching**
|
|
716
809
|
|
|
717
810
|
* ``coordinates`` and ``images`` support different parameter sets per
|
|
@@ -747,3 +840,89 @@ preserved when adding new functionality.
|
|
|
747
840
|
* ``geosearch_meta`` and ``search_meta`` are plain ``@property`` in both
|
|
748
841
|
sync and async — they are set by ``geosearch()`` / ``search()`` on
|
|
749
842
|
the wiki client and require no network call on the page itself.
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
Command Line Interface
|
|
846
|
+
---------------------
|
|
847
|
+
|
|
848
|
+
The CLI provides a command-line tool for querying Wikipedia using Wikipedia-API.
|
|
849
|
+
It is organized into a modular structure for better maintainability.
|
|
850
|
+
|
|
851
|
+
**Architecture**
|
|
852
|
+
|
|
853
|
+
The CLI is split into a main entry point and functional command modules::
|
|
854
|
+
|
|
855
|
+
wikipediaapi/
|
|
856
|
+
├── cli.py # Main CLI entry point (54 lines)
|
|
857
|
+
└── commands/ # CLI command modules
|
|
858
|
+
├── __init__.py
|
|
859
|
+
├── base.py # Shared utilities and common options
|
|
860
|
+
├── page_commands.py # Page content commands
|
|
861
|
+
├── link_commands.py # Link-related commands
|
|
862
|
+
├── category_commands.py # Category commands
|
|
863
|
+
├── geo_commands.py # Geographic commands
|
|
864
|
+
└── search_commands.py # Search and discovery commands
|
|
865
|
+
|
|
866
|
+
**Main Entry Point (``cli.py``)**
|
|
867
|
+
|
|
868
|
+
* Sets up the Click command group with version and help options
|
|
869
|
+
* Imports and registers all command modules
|
|
870
|
+
* Provides the ``main()`` function for the console script entry point
|
|
871
|
+
* Reduced from 1481 lines to 54 lines for better maintainability
|
|
872
|
+
|
|
873
|
+
**Base Module (``commands/base.py``)**
|
|
874
|
+
|
|
875
|
+
* Contains shared utilities: TypedDict classes, enum validators, formatters
|
|
876
|
+
* Defines common Click options used across all commands
|
|
877
|
+
* Provides helper functions for Wikipedia instance creation and page fetching
|
|
878
|
+
* Centralizes formatting functions for consistent output
|
|
879
|
+
|
|
880
|
+
**Command Modules**
|
|
881
|
+
|
|
882
|
+
Each command module groups related functionality:
|
|
883
|
+
|
|
884
|
+
* ``page_commands.py`` — ``summary``, ``text``, ``sections``, ``section``, ``page``
|
|
885
|
+
* ``link_commands.py`` — ``links``, ``backlinks``, ``langlinks``
|
|
886
|
+
* ``category_commands.py`` — ``categories``, ``categorymembers``
|
|
887
|
+
* ``geo_commands.py`` — ``coordinates``, ``images``, ``geosearch``
|
|
888
|
+
* ``search_commands.py`` — ``search``, ``random``
|
|
889
|
+
|
|
890
|
+
**Command Pattern**
|
|
891
|
+
|
|
892
|
+
Each command module follows this pattern:
|
|
893
|
+
|
|
894
|
+
1. **Business logic functions** — Pure functions that handle Wikipedia API calls
|
|
895
|
+
2. **Formatting functions** — Convert results to text/JSON output
|
|
896
|
+
3. **Click command decorators** — Define CLI interface with options and arguments
|
|
897
|
+
4. **Register function** — Registers commands with the main CLI group
|
|
898
|
+
|
|
899
|
+
**Benefits of Modular Structure**
|
|
900
|
+
|
|
901
|
+
* **Maintainable file sizes** — Each module 150-430 lines vs one 1481-line file
|
|
902
|
+
* **Logical organization** — Related commands grouped together
|
|
903
|
+
* **Easier development** — Changes to specific functionality isolated to relevant module
|
|
904
|
+
* **Better testing** — Command modules can be tested independently
|
|
905
|
+
* **Perfect backward compatibility** — All CLI commands work identically to before
|
|
906
|
+
|
|
907
|
+
**Usage Examples**
|
|
908
|
+
|
|
909
|
+
The CLI supports all original commands with identical interfaces::
|
|
910
|
+
|
|
911
|
+
wikipedia-api summary "Python (programming language)"
|
|
912
|
+
wikipedia-api links "Python (programming language)" --language cs
|
|
913
|
+
wikipedia-api categories "Python (programming language)" --json
|
|
914
|
+
wikipedia-api coordinates "Mount Everest"
|
|
915
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278"
|
|
916
|
+
wikipedia-api search "Python programming"
|
|
917
|
+
|
|
918
|
+
**Adding New Commands**
|
|
919
|
+
|
|
920
|
+
To add a new CLI command:
|
|
921
|
+
|
|
922
|
+
1. Choose the appropriate command module based on functionality
|
|
923
|
+
2. Add business logic function (following existing patterns)
|
|
924
|
+
3. Add formatting function for output
|
|
925
|
+
4. Add Click command with proper options and documentation
|
|
926
|
+
5. Register the command in the module's ``register_commands()`` function
|
|
927
|
+
|
|
928
|
+
The modular structure makes it easy to extend the CLI while maintaining clean organization.
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
Development
|
|
2
2
|
===========
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
Prerequisites
|
|
5
5
|
--------------
|
|
6
|
+
|
|
6
7
|
* Make
|
|
7
|
-
*
|
|
8
|
+
* Python 3.10+
|
|
8
9
|
* Pip
|
|
9
10
|
|
|
10
11
|
Makefile targets
|
|
11
|
-
|
|
12
|
-
* ``make run-
|
|
12
|
+
-----------------
|
|
13
|
+
* ``make run-type-check`` - type checks source code (runs ``uv run ty check wikipediaapi/``)
|
|
14
|
+
* ``make run-ruff`` - lints and checks formatting (runs ``ruff check`` and ``ruff format --check``)
|
|
13
15
|
* ``make requirements-all`` - install all requirements
|
|
14
16
|
* ``make requirements`` - install package requirements
|
|
15
17
|
* ``make requirements-dev`` - install development requirements
|
|
16
|
-
* ``make run-tests`` - run unit tests
|
|
17
|
-
* ``make run-
|
|
18
|
+
* ``make run-tests`` - run unit tests (pytest)
|
|
19
|
+
* ``make run-tests-integration`` - run VCR integration tests (pytest)
|
|
20
|
+
* ``make run-coverage`` - run code coverage (pytest-cov)
|
|
18
21
|
* ``make pypi-html`` - generates single HTML documentation into ``pypi-doc.html``
|
|
19
22
|
* ``make html`` - generates HTML documentation similar to RTFD into folder ``_build/html/``
|
|
20
23
|
* ``make release`` - creates new release as well as git tag
|