Wikipedia-API 0.14.0__tar.gz → 0.14.1__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.14.0 → wikipedia_api-0.14.1}/.gitignore +7 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/CHANGES.rst +7 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/DESIGN.rst +24 -13
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/PKG-INFO +2 -2
- wikipedia_api-0.14.1/SKILLS/README.md +69 -0
- wikipedia_api-0.14.1/SKILLS/bash.md +278 -0
- wikipedia_api-0.14.1/SKILLS/python-async.md +385 -0
- wikipedia_api-0.14.1/SKILLS/python-sync.md +389 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1/examples}/example_async.py +30 -7
- wikipedia_api-0.14.1/examples/example_cli.sh +245 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1/examples}/example_sync.py +27 -5
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/pyproject.toml +7 -8
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/__init__.py +7 -7
- wikipedia_api-0.14.1/wikipediaapi/_image/__init__.py +7 -0
- wikipedia_api-0.14.1/wikipediaapi/_image/_base_wikipedia_image.py +34 -0
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_image}/async_wikipedia_image.py +27 -7
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_image}/wikipedia_image.py +25 -24
- wikipedia_api-0.14.1/wikipediaapi/_page/__init__.py +11 -0
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_page}/_base_wikipedia_page.py +3 -3
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_page}/async_wikipedia_page.py +7 -7
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_page}/wikipedia_page.py +7 -7
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_page}/wikipedia_page_section.py +2 -2
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/async_images_dict.py +2 -2
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/async_pages_dict.py +2 -2
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/base_pages_dict.py +5 -5
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/images_dict.py +2 -2
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/pages_dict.py +2 -2
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_resources/async_wikipedia_resource.py +3 -3
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_resources/base_wikipedia_resource.py +4 -4
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_resources/wikipedia_resource.py +6 -6
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_version.py +1 -1
- wikipedia_api-0.14.1/wikipediaapi/_wikipedia/__init__.py +7 -0
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_wikipedia}/async_wikipedia.py +2 -2
- {wikipedia_api-0.14.0/wikipediaapi → wikipedia_api-0.14.1/wikipediaapi/_wikipedia}/wikipedia.py +3 -3
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/SKILL.md +0 -47
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/async.py +0 -47
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/cli.sh +0 -27
- wikipedia_api-0.14.0/SKILLS/category_deep_dive/sync.py +0 -41
- wikipedia_api-0.14.0/SKILLS/custom_page_output/SKILL.md +0 -56
- wikipedia_api-0.14.0/SKILLS/custom_page_output/async.py +0 -93
- wikipedia_api-0.14.0/SKILLS/custom_page_output/cli.sh +0 -70
- wikipedia_api-0.14.0/SKILLS/custom_page_output/sync.py +0 -81
- wikipedia_api-0.14.0/SKILLS/explore_nearby/SKILL.md +0 -46
- wikipedia_api-0.14.0/SKILLS/explore_nearby/async.py +0 -44
- wikipedia_api-0.14.0/SKILLS/explore_nearby/cli.sh +0 -30
- wikipedia_api-0.14.0/SKILLS/explore_nearby/sync.py +0 -37
- wikipedia_api-0.14.0/SKILLS/media_audit/SKILL.md +0 -50
- wikipedia_api-0.14.0/SKILLS/media_audit/async.py +0 -56
- wikipedia_api-0.14.0/SKILLS/media_audit/cli.sh +0 -27
- wikipedia_api-0.14.0/SKILLS/media_audit/sync.py +0 -49
- wikipedia_api-0.14.0/SKILLS/multilingual_content/SKILL.md +0 -47
- wikipedia_api-0.14.0/SKILLS/multilingual_content/async.py +0 -52
- wikipedia_api-0.14.0/SKILLS/multilingual_content/cli.sh +0 -35
- wikipedia_api-0.14.0/SKILLS/multilingual_content/sync.py +0 -43
- wikipedia_api-0.14.0/SKILLS/research_topic/SKILL.md +0 -48
- wikipedia_api-0.14.0/SKILLS/research_topic/async.py +0 -60
- wikipedia_api-0.14.0/SKILLS/research_topic/cli.sh +0 -38
- wikipedia_api-0.14.0/SKILLS/research_topic/sync.py +0 -53
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/API.rst +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/CLI.rst +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/DEVELOPMENT.rst +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/LICENSE +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/README.rst +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/README_processed.rst +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/coordinate_type.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/coordinates_prop.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/direction.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/geosearch_sort.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/globe.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/namespace.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/redirect_filter.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/search_info.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/search_prop.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/search_qi_profile.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/search_sort.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_enums/search_what.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/async_http_client.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/base_http_client.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/retry_after_wait.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/retry_utils.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_http_client/sync_http_client.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_pages_dict/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/base_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/coordinates_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/geo_search_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/imageinfo_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/images_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/protocols.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/random_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_params/search_params.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_resources/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/coordinate.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/geo_box.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/geo_point.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/geo_search_meta.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/image_info.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/search_meta.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/_types/search_results.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/cli.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/base.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/category_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/geo_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/image_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/link_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/page_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/commands/search_commands.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/__init__.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wiki_connection_error.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wiki_http_error.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wiki_http_timeout_error.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wiki_invalid_json_error.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wiki_rate_limit_error.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/exceptions/wikipedia_exception.py +0 -0
- {wikipedia_api-0.14.0 → wikipedia_api-0.14.1}/wikipediaapi/extract_format.py +0 -0
|
@@ -103,14 +103,21 @@ File Layout
|
|
|
103
103
|
│ ├── wiki_http_timeout_error.py # Timeout errors
|
|
104
104
|
│ ├── wiki_invalid_json_error.py # JSON parsing errors
|
|
105
105
|
│ └── wiki_rate_limit_error.py # Rate limiting errors
|
|
106
|
-
├──
|
|
107
|
-
├──
|
|
108
|
-
├──
|
|
109
|
-
|
|
110
|
-
├──
|
|
111
|
-
├──
|
|
112
|
-
├──
|
|
113
|
-
├──
|
|
106
|
+
├── _wikipedia/ # Concrete client package
|
|
107
|
+
│ ├── __init__.py
|
|
108
|
+
│ ├── wikipedia.py # Wikipedia (sync concrete client)
|
|
109
|
+
│ └── async_wikipedia.py # AsyncWikipedia (async concrete client)
|
|
110
|
+
├── _page/ # Page object package
|
|
111
|
+
│ ├── __init__.py
|
|
112
|
+
│ ├── _base_wikipedia_page.py # BaseWikipediaPage (shared page state & methods)
|
|
113
|
+
│ ├── wikipedia_page.py # WikipediaPage (lazy sync page object)
|
|
114
|
+
│ ├── async_wikipedia_page.py # AsyncWikipediaPage (lazy async page object)
|
|
115
|
+
│ └── wikipedia_page_section.py # WikipediaPageSection
|
|
116
|
+
├── _image/ # Image/file page object package
|
|
117
|
+
│ ├── __init__.py
|
|
118
|
+
│ ├── _base_wikipedia_image.py # BaseWikipediaImage (shared image state & methods)
|
|
119
|
+
│ ├── wikipedia_image.py # WikipediaImage (lazy sync file page object)
|
|
120
|
+
│ └── async_wikipedia_image.py # AsyncWikipediaImage (lazy async file page object)
|
|
114
121
|
├── extract_format.py # ExtractFormat enum (WIKI / HTML)
|
|
115
122
|
└── namespace.py # Legacy namespace module (redirects to _enums.namespace)
|
|
116
123
|
|
|
@@ -131,8 +138,9 @@ The inheritance chains are::
|
|
|
131
138
|
BaseWikipediaPage
|
|
132
139
|
├── WikipediaPage
|
|
133
140
|
├── AsyncWikipediaPage
|
|
134
|
-
|
|
135
|
-
|
|
141
|
+
└── BaseWikipediaImage
|
|
142
|
+
├── WikipediaImage
|
|
143
|
+
└── AsyncWikipediaImage
|
|
136
144
|
|
|
137
145
|
Concrete clients compose one transport and one API mixin::
|
|
138
146
|
|
|
@@ -159,6 +167,9 @@ The subclasses are responsible for the fundamentally different parts:
|
|
|
159
167
|
``await page.summary`` first.
|
|
160
168
|
* ``exists()`` — sync auto-fetches via ``self.pageid``; async is a
|
|
161
169
|
coroutine method that lazily fetches ``pageid`` via ``info``.
|
|
170
|
+
**Invariant**: When ``exists()`` returns ``True``, ``pageid`` returns a
|
|
171
|
+
positive integer; when ``exists()`` returns ``False``, ``pageid`` returns a
|
|
172
|
+
negative integer. Both values are deterministic based on ``abs(hash(title))``.
|
|
162
173
|
* All data-fetching surface (``summary``, ``langlinks``, ``pageid``, …)
|
|
163
174
|
— explicit ``@property`` in both; async properties return coroutines
|
|
164
175
|
(``await page.summary``, ``await page.pageid``, etc.).
|
|
@@ -531,7 +542,7 @@ and stores results under ``raw["query"]["pages"][id]["templates"]``.
|
|
|
531
542
|
Step 2 — Add a Return-Type Attribute to BaseWikipediaPage
|
|
532
543
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
533
544
|
|
|
534
|
-
In ``_base_wikipedia_page.py``, add a cache slot in
|
|
545
|
+
In ``_page/_base_wikipedia_page.py``, add a cache slot in
|
|
535
546
|
``BaseWikipediaPage.__init__``::
|
|
536
547
|
|
|
537
548
|
self._templates: dict[str, Any] = {}
|
|
@@ -637,7 +648,7 @@ Step 6 — Add the Async Method to AsyncWikipediaResource
|
|
|
637
648
|
Step 7 — Add a Lazy Property to WikipediaPage
|
|
638
649
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
639
650
|
|
|
640
|
-
In ``wikipedia_page.py``::
|
|
651
|
+
In ``_page/wikipedia_page.py``::
|
|
641
652
|
|
|
642
653
|
@property
|
|
643
654
|
def templates(self) -> PagesDict:
|
|
@@ -649,7 +660,7 @@ In ``wikipedia_page.py``::
|
|
|
649
660
|
Step 8 — Add a Lazy Coroutine Property to AsyncWikipediaPage
|
|
650
661
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
651
662
|
|
|
652
|
-
In ``async_wikipedia_page.py``, the ``@property`` returns a coroutine
|
|
663
|
+
In ``_page/async_wikipedia_page.py``, the ``@property`` returns a coroutine
|
|
653
664
|
created by a nested ``async def``; callers do ``await page.templates``::
|
|
654
665
|
|
|
655
666
|
@property
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: Wikipedia-API
|
|
3
|
-
Version: 0.14.
|
|
3
|
+
Version: 0.14.1
|
|
4
4
|
Summary: Python Wrapper for Wikipedia
|
|
5
5
|
Project-URL: Homepage, https://github.com/martin-majlis/Wikipedia-API
|
|
6
6
|
Project-URL: Repository, https://github.com/martin-majlis/Wikipedia-API
|
|
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
|
26
26
|
Classifier: Topic :: Communications :: Email
|
|
27
27
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
28
28
|
Requires-Python: >=3.10
|
|
29
|
-
Requires-Dist: click==8.3.
|
|
29
|
+
Requires-Dist: click==8.3.2
|
|
30
30
|
Requires-Dist: httpx==0.28.1
|
|
31
31
|
Requires-Dist: tenacity==9.1.4
|
|
32
32
|
Description-Content-Type: text/x-rst
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Wikipedia-API
|
|
2
|
+
|
|
3
|
+
Python wrapper for the [MediaWiki API](https://www.mediawiki.org/wiki/API:Main_page).
|
|
4
|
+
Provides both synchronous (`Wikipedia`) and asynchronous (`AsyncWikipedia`) clients.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install wikipedia-api
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Client Initialization
|
|
13
|
+
|
|
14
|
+
```python
|
|
15
|
+
import wikipediaapi
|
|
16
|
+
|
|
17
|
+
# Basic client — English Wikipedia, plain-text extract format
|
|
18
|
+
wiki = wikipediaapi.Wikipedia(
|
|
19
|
+
user_agent="MyProject/1.0 (contact@example.com)",
|
|
20
|
+
language="en"
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
# HTML extract format (summary and section text returned as HTML fragments)
|
|
24
|
+
wiki_html = wikipediaapi.Wikipedia(
|
|
25
|
+
user_agent="MyProject/1.0 (contact@example.com)",
|
|
26
|
+
language="cs",
|
|
27
|
+
extract_format=wikipediaapi.ExtractFormat.HTML,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
# Forward extra parameters to every API request (e.g. auto-follow redirects)
|
|
31
|
+
wiki_extra = wikipediaapi.Wikipedia(
|
|
32
|
+
user_agent="MyProject/1.0 (contact@example.com)",
|
|
33
|
+
language="en",
|
|
34
|
+
extra_api_params={"redirects": "1"},
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
# Async client — same options, use AsyncWikipedia instead
|
|
38
|
+
wiki_async = wikipediaapi.AsyncWikipedia(
|
|
39
|
+
user_agent="MyProject/1.0 (contact@example.com)",
|
|
40
|
+
language="en"
|
|
41
|
+
)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
> **User-Agent is required.** MediaWiki blocks requests without a descriptive
|
|
45
|
+
> `User-Agent`. Use the format `AppName/Version (contact)`.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import wikipediaapi
|
|
51
|
+
|
|
52
|
+
wiki = wikipediaapi.Wikipedia(
|
|
53
|
+
user_agent="MyProject/1.0 (contact@example.com)",
|
|
54
|
+
language="en"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
page = wiki.page("Python (programming language)")
|
|
58
|
+
if page.exists():
|
|
59
|
+
print(page.title)
|
|
60
|
+
print(page.summary[:200])
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Further Reading
|
|
66
|
+
|
|
67
|
+
- [python-sync.md](python-sync.md) — Full synchronous API reference with examples
|
|
68
|
+
- [python-async.md](python-async.md) — Full asynchronous API reference with examples
|
|
69
|
+
- [bash.md](bash.md) — CLI command reference with examples
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# Wikipedia-API — CLI (Bash)
|
|
2
|
+
|
|
3
|
+
The `wikipedia-api` CLI is installed automatically with the package.
|
|
4
|
+
|
|
5
|
+
Full working example: [`examples/example_cli.sh`](../examples/example_cli.sh)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install wikipedia-api
|
|
13
|
+
wikipedia-api --version
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Global Options
|
|
19
|
+
|
|
20
|
+
Every command accepts these options:
|
|
21
|
+
|
|
22
|
+
| Option | Description | Default |
|
|
23
|
+
| ---------------------- | ----------------------------------------------- | ------- |
|
|
24
|
+
| `-l, --language` | Wikipedia language edition | `en` |
|
|
25
|
+
| `-u, --user-agent` | HTTP User-Agent string | — |
|
|
26
|
+
| `-v, --variant` | Language variant (e.g. `zh-cn`, `zh-tw`) | — |
|
|
27
|
+
| `-f, --extract-format` | Extract format: `wiki` or `html` | `wiki` |
|
|
28
|
+
| `-n, --namespace` | Wikipedia namespace number | `0` |
|
|
29
|
+
| `--max-retries` | Max retry attempts (0 to disable) | `3` |
|
|
30
|
+
| `--retry-wait` | Base wait between retries (exponential backoff) | `1.0` |
|
|
31
|
+
| `--json` | Output as JSON | — |
|
|
32
|
+
| `-h, --help` | Show help | — |
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Show all available commands
|
|
36
|
+
wikipedia-api --help
|
|
37
|
+
|
|
38
|
+
# Show help for a specific command
|
|
39
|
+
wikipedia-api summary --help
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Page Metadata
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Show page info (pageid, fullurl, editurl, length, lastrevid, etc.)
|
|
48
|
+
wikipedia-api page "Python (programming language)"
|
|
49
|
+
|
|
50
|
+
# JSON output — includes all info attributes
|
|
51
|
+
wikipedia-api page "Python (programming language)" --json
|
|
52
|
+
|
|
53
|
+
# Missing page — pageid will be -1 in JSON output
|
|
54
|
+
wikipedia-api page "Wikipedia-API-FooBar-DoesNotExist" --json
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Summary
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
wikipedia-api summary "Python (programming language)"
|
|
63
|
+
|
|
64
|
+
# Summary in Czech
|
|
65
|
+
wikipedia-api summary "Ostrava" --language cs
|
|
66
|
+
|
|
67
|
+
# Summary in Chinese with variant
|
|
68
|
+
wikipedia-api summary "Python" --language zh --variant zh-cn
|
|
69
|
+
|
|
70
|
+
# Summary as HTML
|
|
71
|
+
wikipedia-api summary "Ostrava" --language cs --extract-format html
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Full Text
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
wikipedia-api text "Python (programming language)"
|
|
80
|
+
|
|
81
|
+
# Full text as HTML
|
|
82
|
+
wikipedia-api text "Ostrava" --language cs --extract-format html
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Sections
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# List the full section hierarchy
|
|
91
|
+
wikipedia-api sections "Python (programming language)"
|
|
92
|
+
|
|
93
|
+
wikipedia-api sections "Python (programming language)" --json
|
|
94
|
+
|
|
95
|
+
# Print the text of a specific section
|
|
96
|
+
wikipedia-api section "Python (programming language)" "Features and philosophy"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Language Links
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
wikipedia-api langlinks "Python (programming language)"
|
|
105
|
+
|
|
106
|
+
wikipedia-api langlinks "Python (programming language)" --json
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Links and Backlinks
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
wikipedia-api links "Python (programming language)"
|
|
115
|
+
|
|
116
|
+
wikipedia-api links "Python (programming language)" --json
|
|
117
|
+
|
|
118
|
+
wikipedia-api backlinks "Python (programming language)"
|
|
119
|
+
|
|
120
|
+
wikipedia-api backlinks "Python (programming language)" --json
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## Categories and Category Members
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
wikipedia-api categories "Python (programming language)"
|
|
129
|
+
|
|
130
|
+
wikipedia-api categories "Python (programming language)" --json
|
|
131
|
+
|
|
132
|
+
# List pages in a category
|
|
133
|
+
wikipedia-api categorymembers "Category:Physics"
|
|
134
|
+
|
|
135
|
+
# Recursively include subcategory members (depth 1)
|
|
136
|
+
wikipedia-api categorymembers "Category:Physics" --max-level 1
|
|
137
|
+
|
|
138
|
+
wikipedia-api categorymembers "Category:Physics" --json
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## Language Variants
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
# Default script
|
|
147
|
+
wikipedia-api summary "Python" --language zh
|
|
148
|
+
|
|
149
|
+
# Simplified Chinese
|
|
150
|
+
wikipedia-api summary "Python" --language zh --variant zh-cn
|
|
151
|
+
|
|
152
|
+
# Traditional Chinese
|
|
153
|
+
wikipedia-api summary "Python" --language zh --variant zh-tw
|
|
154
|
+
|
|
155
|
+
# Singapore Simplified Chinese
|
|
156
|
+
wikipedia-api summary "Python" --language zh --variant zh-sg
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## Coordinates
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
# Primary coordinate only (default)
|
|
165
|
+
wikipedia-api coordinates "London"
|
|
166
|
+
|
|
167
|
+
# All coordinates (primary + secondary)
|
|
168
|
+
wikipedia-api coordinates "London" --primary all
|
|
169
|
+
|
|
170
|
+
wikipedia-api coordinates "London" --json
|
|
171
|
+
|
|
172
|
+
wikipedia-api coordinates "Mount Everest"
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## Images and Image Metadata
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# List image titles used on a page
|
|
181
|
+
wikipedia-api images "Python (programming language)"
|
|
182
|
+
|
|
183
|
+
wikipedia-api images "Python (programming language)" --json
|
|
184
|
+
|
|
185
|
+
# Fetch metadata (URL, dimensions, MIME type, uploader, timestamp, etc.)
|
|
186
|
+
wikipedia-api images "Mount Everest" --imageinfo
|
|
187
|
+
|
|
188
|
+
wikipedia-api images "Mount Everest" --imageinfo --json
|
|
189
|
+
|
|
190
|
+
# Limit number of images
|
|
191
|
+
wikipedia-api images "Earth" --limit 20 --imageinfo
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## Geosearch
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Search near a coordinate (London city centre)
|
|
200
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278"
|
|
201
|
+
|
|
202
|
+
# Limit radius and result count
|
|
203
|
+
wikipedia-api geosearch --coord "51.5074|-0.1278" --radius 1000 --limit 5
|
|
204
|
+
|
|
205
|
+
# Search near a named page
|
|
206
|
+
wikipedia-api geosearch --page "Big Ben" --radius 1000
|
|
207
|
+
|
|
208
|
+
wikipedia-api geosearch --coord "48.8566|2.3522" --json
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## Random Pages
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
wikipedia-api random
|
|
217
|
+
|
|
218
|
+
wikipedia-api random --limit 3
|
|
219
|
+
|
|
220
|
+
wikipedia-api random --limit 3 --json
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## Search
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
wikipedia-api search "Python programming"
|
|
229
|
+
|
|
230
|
+
wikipedia-api search "Python programming" --limit 5
|
|
231
|
+
|
|
232
|
+
wikipedia-api search "Python programming" --json
|
|
233
|
+
|
|
234
|
+
# Search in another language
|
|
235
|
+
wikipedia-api search "машинное обучение" --language ru
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
---
|
|
239
|
+
|
|
240
|
+
## Retry Configuration
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Custom retry settings
|
|
244
|
+
wikipedia-api summary "Python (programming language)" --max-retries 5 --retry-wait 2.0
|
|
245
|
+
|
|
246
|
+
# Disable retries entirely (fail fast on first error)
|
|
247
|
+
wikipedia-api search "Python" --max-retries 0
|
|
248
|
+
|
|
249
|
+
# Aggressive retrying for unreliable connections
|
|
250
|
+
wikipedia-api geosearch --coord "27.9881|86.9250" --max-retries 10 --retry-wait 3.0
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Complete Workflow Example
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
UA="MyProject/1.0 (contact@example.com)"
|
|
259
|
+
|
|
260
|
+
# Explore a page from multiple angles
|
|
261
|
+
wikipedia-api summary "Python (programming language)" --user-agent "$UA"
|
|
262
|
+
wikipedia-api sections "Python (programming language)" --user-agent "$UA"
|
|
263
|
+
wikipedia-api section "Python (programming language)" "History" --user-agent "$UA"
|
|
264
|
+
wikipedia-api categories "Python (programming language)" --user-agent "$UA"
|
|
265
|
+
wikipedia-api langlinks "Python (programming language)" --user-agent "$UA"
|
|
266
|
+
|
|
267
|
+
# Follow a language link to German Wikipedia
|
|
268
|
+
wikipedia-api summary "Python (Programmiersprache)" --language de --user-agent "$UA"
|
|
269
|
+
|
|
270
|
+
# Geographic pages
|
|
271
|
+
wikipedia-api coordinates "Mount Everest" --user-agent "$UA"
|
|
272
|
+
wikipedia-api geosearch --coord "27.9881|86.9250" --radius 5000 --user-agent "$UA"
|
|
273
|
+
wikipedia-api images "Mount Everest" --imageinfo --user-agent "$UA"
|
|
274
|
+
|
|
275
|
+
# Discovery
|
|
276
|
+
wikipedia-api random --limit 3 --user-agent "$UA"
|
|
277
|
+
wikipedia-api search "Mount Everest" --limit 5 --user-agent "$UA"
|
|
278
|
+
```
|