Skip to main content

pywikiapi: A Tiny Python MediaWiki API Lib

GitHub Coverage Issues Pull Requests CI build

This is a minimalistic library that handles some of the core MediaWiki API complexities like handling continuations, login, errors, and warnings, but does not impose any additional abstraction layers, allowing you to use every single feature of the MW API directly in the most optimal way.

The library was written by the original author of the MediaWiki API itself, and tries to address some of the mistakes of the original API design... Some things should have been done differently. :)

from pywikiapi import wikipedia
# Connect to English Wikipedia
site = wikipedia('en')

# Iterate over all query results as they are returned
# from the server, handling continuations automatically.
# (pages whose title begins with "New York-New Jersey")
for r in site.query(list='allpages', apprefix='New York-New Jersey'):
  for page in r.allpages:
    print(page.title)

# Iterate over two pages, getting the page info and the list of links for each of the two pages. Each page will be yielded as a separate result.
for page in site.query_pages(titles=['Test', 'API'], prop=['links', 'info'], pllimit=10):
    print(page.title)
    print(', '.join([l.title for l in page.links]))
    print()

site.login('username', 'password')
site('edit', text=...)

Installation

You can install the library from PyPI:

pip install pywikiapi

or

python3 -m pip install pywikiapi

The library requires Python 3.6+

How to use

  • Create a Site object, either directly or with the wikipedia helper function.
  • Use site.query(...) or site.iterate(action, ...) for all iteration-related API calls. The API will handle all the continuation logic internally.
  • Use site.query_pages(...) to get one page object at a time from the action=query.
  • Use site('query', meta='siteinfo') to access any API action, passing any additional params as keys.

Data formats

The library will properly handle all of the basic parameter types:

  • Numbers and strings will be passed as is
  • Boolean True will be passed as "1".
  • None and boolean False will not be included.
  • Datetimes will be formatted with isoformat(). Warning: make sure datetime is in UTC timezone.
  • Lists will be converted into a pipe | -separated string of values.

Development

To test, run python3 setup.py test -q or use ./test.sh

Metadata

Release files for pywikiapi 5.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pywikiapi 5.0.0
File Size Uploaded
pywikiapi-5.0.0.tar.gz 13.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pywikiapi 5.0.0
File Interpreter ABI Platform
pywikiapi-5.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.7 kB

Release files / pywikiapi-5.0.0.tar.gz

Download URL pywikiapi-5.0.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8f5441d5e732587b2807daf2072a26a6a6318aee7c89b8d425bed3a0e26c15e9
BLAKE2b-256 checksum
How to use checksums
c818329eb73ad8f84b90915178478a1c598cd1ef243402e50cbadb6083f119f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release files / pywikiapi-5.0.0-py3-none-any.whl

Download URL pywikiapi-5.0.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
209d209ecd96bfdd5845c228c929d5a430c5aa98b266b86c6a544fe0b90fb229
BLAKE2b-256 checksum
How to use checksums
7b9dbdaf407c2d559ed51fc1bdd1836c04321635c0c078499532564c01ba92f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.10.12

Release history Release notifications | RSS feed

This release

5.0.0 This release

2 release files

4.3.0

2 release files

4.2.0

2 release files

4.1.1

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.1.0

2 release files

3.0.0

2 release files

2.0.0

2 release files

1.4.0

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

1 release file

1.1.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page