### Install MediaWikiAPI with pip Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Instructions to install the MediaWikiAPI library using pip, compatible with Python > 3.9. This is the quickest way to get started. ```Shell $ pip install mediawikiapi ``` -------------------------------- ### Configure MediaWikiAPI for custom MediaWiki installs Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Illustrates how to initialize MediaWikiAPI to connect to a custom MediaWiki installation or site with a compatible API. This is achieved by providing a `Config` object with a custom `mediawiki_url`. ```Python import mediawikiapi mediawiki = mediawikiapi.MediaWikiAPI(config=Config(mediawiki_url="https://{}.wiktionary.org/w/api.php")) ``` -------------------------------- ### Install MediaWikiAPI Python Package Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md This command installs the MediaWikiAPI library using pip, the Python package installer. It ensures the library and its dependencies are available in your Python environment. ```bash pip install mediawikiapi ``` -------------------------------- ### Build MediaWikiAPI Documentation Locally with Sphinx Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md This sequence of commands demonstrates how to build the project's documentation locally using Sphinx. It involves installing Sphinx, navigating to the documentation directory, and running the make command to generate HTML documentation. ```bash pip install sphinx cd docs/ make html ``` -------------------------------- ### Run MediaWikiAPI Tests with Poetry Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md These commands outline the process for setting up the development environment and running tests for the MediaWikiAPI project using Poetry. It includes installing dependencies, building the project, and executing pytest with coverage reports. ```bash poetry install poetry build poetry run pytest --junitxml=pytest.xml --cov-report=term-missing:skip_covered --cov=mediawikiapi ``` -------------------------------- ### Basic Usage of MediaWikiAPI in Python Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md This snippet demonstrates how to initialize the MediaWikiAPI, perform searches, get article summaries, retrieve page details like title, URL, content, and links, and change the default language for queries. ```python >>> from mediawikiapi import MediaWikiAPI >>> mediawikiapi = MediaWikiAPI() >>> print(mediawikiapi.summary("Wikipedia")) # Wikipedia (/ˌwɪkɨˈpiːdiə/ or /ˌwɪkiˈpiːdiə/ WIK-i-PEE-dee-ə) is a collaboratively edited, multilingual, free Internet encyclopedia supported by the non-profit Wikimedia Foundation... >>> mediawikiapi.search("Barack") # [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama'] >>> ny = mediawikiapi.page("New York (state)") >>> ny.title # u'New York (state)' >>> ny.url # u'http://en.wikipedia.org/wiki/New_York_(state)' >>> ny.content # u'New York is a state in the northeastern United States. New York was one of the original thir'... >>> ny.links[0] # u'1790 United States Census' >>> mediawikiapi.config.language = "fr" >>> mediawikiapi.summary("Facebook", sentences=1) # Facebook est un service de réseautage social en ligne sur Internet permettant d'y publier des informations (photographies, liens, textes, etc.) en contrôlant leur visibilité par différentes catégories de personnes. ``` -------------------------------- ### Handle PageError exceptions in MediaWikiAPI Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Provides an example of how to use a `try-except` block to gracefully handle `mediawikiapi.exceptions.PageError`. This error occurs when attempting to access a Wikipedia page that does not exist. ```Python import mediawikiapi mediawiki = mediawikiapi.MediaWikiAPI() try: print("Getting page") page = mediawiki.page("!!!123123 page title") except mediawikiapi.exceptions.PageError: print("Got page error, skipping") ``` -------------------------------- ### Get article summary with MediaWikiAPI Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Illustrates how to retrieve a summary of a Wikipedia article using `mediawikiapi.summary`. It also shows how to limit the summary to a specific number of sentences using the `sentences` keyword argument. ```Python mediawikiapi.summary("GitHub") '2011, GitHub was the most popular open source code repository site.\nGitHub Inc. was founded in 2008 and is based in San Francisco, California.\nIn July 2012, the company received $100 million in Series A funding, primarily from Andreessen Horowitz.' mediawikiapi.summary("Apple III", sentences=1) u'The Apple III (often rendered as Apple ///) is a business-oriented personal computer produced and released by Apple Computer that was intended as the successor to the Apple II series, but largely considered a failure in the market. ' ``` -------------------------------- ### Run Code Quality Checks (Mypy, Flake8, Black) Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md These commands execute various code quality tools to ensure code consistency and correctness. Mypy performs static type checking, Flake8 checks for style guide violations, and Black formats the code automatically. ```bash poetry run mypy --strict . poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics poetry run black --diff --check . ``` -------------------------------- ### Search and suggest Wikipedia titles Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Demonstrates how to use the `search` method to find articles based on a query and the `suggest` method to get suggested Wikipedia titles. The `search` method returns a list of matching titles, while `suggest` returns a single best suggestion or None. ```Python mediawikiapi.search("Barack") [u'Barak (given name)', u'Barack Obama', u'Barack (brandy)', u'Presidency of Barack Obama', u'Family of Barack Obama', u'First inauguration of Barack Obama', u'Barack Obama presidential campaign, 2008', u'Barack Obama, Sr.', u'Barack Obama citizenship conspiracy theories', u'Presidential transition of Barack Obama'] mediawikiapi.suggest("Barak Obama") # returns the suggested Wikipedia title for a query or None u'Barack Obama' ``` -------------------------------- ### Initialize MediaWikiAPI class Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Import the MediaWikiAPI package and create an instance of the MediaWikiAPI class. This is the first step to begin interacting with the MediaWiki API. ```Python from mediawikiapi import MediaWikiAPI mediawikiapi = MediaWikiAPI() ``` -------------------------------- ### Build MediaWikiAPI Documentation using Poetry and Sphinx Source: https://github.com/lehinevych/mediawikiapi/blob/master/README.md This command builds the project's documentation using Sphinx, managed through Poetry. It compiles the source files in `docs/source` into the `docs/build` directory. ```bash poetry run sphinx-build docs/source docs/build ``` -------------------------------- ### MediaWikiAPI Project API Reference Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/api.rst Detailed API documentation for the MediaWikiAPI project, covering core classes, their initializers, and the exceptions module. This documentation outlines the structure and available components for developers interacting with the MediaWikiAPI library. ```APIDOC Module: mediawikiapi Class: mediawikiapi.MediaWikiAPI Method: __init__() Class: mediawikiapi.WikipediaPage Method: __init__() Class: mediawikiapi.Language Method: __init__() Class: mediawikiapi.RequestSession Method: __init__() Class: mediawikiapi.Config Method: __init__() Module: mediawikiapi.exceptions Exceptions: (All members of the mediawikiapi.exceptions module) ``` -------------------------------- ### List all available MediaWikiAPI languages Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Shows how to retrieve a list of all possible language prefixes supported by MediaWikiAPI. This method can be used to discover which languages are available for configuration. ```Python mediawikiapi.languages() ``` -------------------------------- ### Load and access full Wikipedia page data Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Explains how to use `mediawikiapi.page` to load a full Wikipedia page by its title. Once loaded, you can access various properties of the page object, such as its title, URL, content, images, and links. ```Python ny = mediawikiapi.page("New York (state)") ny.title u'New York (state)' ny.url u'http://en.wikipedia.org/wiki/New_York_(state)' ny.content u'New York is a state in the northeastern United States. New York was one of the original thir'... ny.images[0] u'http://upload.wikimedia.org/wikipedia/commons/9/91/New_York_quarter%2C_reverse_side%2C_2001.jpg' ny.links[0] u'1790 United States Census' ``` -------------------------------- ### Change MediaWikiAPI language configuration Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Demonstrates how to change the language for Wikipedia access using `mediawikiapi.config.language`. It's important to search for page titles in the language that you have set, not English. ```Python mediawikiapi.config.language = "fr" print mediawikiapi.summary("Francois Hollande") François Hollande, né le 12 août 1954 à Rouen, en Seine-Maritime, est un homme d'État français. Il est président de la République française depuis le 15 mai 2012... ``` -------------------------------- ### Limit search results using kwarg Source: https://github.com/lehinevych/mediawikiapi/blob/master/docs/source/index.rst Shows how to control the number of search results returned by the `search` method. The `results` keyword argument allows you to specify the maximum number of titles to retrieve. ```Python mediawikiapi.search("Ford", results=3) [u'Ford Motor Company', u'Gerald Ford', u'Henry Ford'] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.