aiowiki package

Submodules

aiowiki.exceptions module

exception aiowiki.exceptions.PageNotFound[source]

Bases: Exception

Exception raised when a page does not exist

exception aiowiki.exceptions.LoginFailure[source]

Bases: Exception

Exception raised when a login() fails

exception aiowiki.exceptions.BadWikiUrl[source]

Bases: Exception

Exception raised when the URL of the Wiki() is not in the standard Wikimedia API format

exception aiowiki.exceptions.TokenGetError[source]

Bases: Exception

Exception raised when the internal acquiring for a token fails

exception aiowiki.exceptions.CreateAccountError[source]

Bases: Exception

Exception raised when create_account() fails

exception aiowiki.exceptions.EditError[source]

Bases: Exception

Exception raised when edit() fails

exception aiowiki.exceptions.NoSuchUserError[source]

Bases: Exception

Exception raised when userrights() fails because the target user does not exist

exception aiowiki.exceptions.InvalidGroupError[source]

Bases: Exception

Exception raised when userrights() fails because the selected group for adding to does not exist

exception aiowiki.exceptions.UserRightsNotChangedError[source]

Bases: Exception

Exception raised when userrights() fails for several reasons

aiowiki.http module

class aiowiki.http.HTTPClient(url, session, logged_in)[source]

Bases: object

A Proxy object for all API actions

coroutine close()[source]

Closes the aiohttp Session

coroutine get_token(type)[source]

Gets an API token

coroutine get_random_pages(num, namespace)[source]

Gets random page names

coroutine create_account(json)[source]

Creates an account

coroutine userrights(json)[source]

Manage user rights

coroutine login(json)[source]

Logs in to the wiki

coroutine get_html(page)[source]

Gets Page html

coroutine get_markdown(page)[source]

Gets Page markdown

coroutine get_summary(page)[source]

Gets Page summary

coroutine edit_page(json)[source]

Edits a page’s content

coroutine opensearch(title, limit, namespace)[source]

Searches for a page title and returns limit results as a list

coroutine get_urls(title)[source]

Searches for URLs matching a title and returns edit URL and page URL in a list

coroutine get_media(title)[source]

Searches for media on a specific page and returns a list of URLs

aiowiki.page module

class aiowiki.page.Page(page_title, wiki)[source]

Bases: object

Represents a Page in the Wiki(). This is usually acquired by get_page() or other methods, and not created directly.

Parameters
  • page_title (str) – The title of the page.

  • wiki (Wiki) – The Wiki() object this page belongs to.

Variables
  • title – The page title

  • wiki – The Wiki() it belongs to

coroutine html()[source]

The pure page HTML.

coroutine markdown()[source]

The Markdown version of the page content.

coroutine text()[source]

The text of the page without HTML tags.

coroutine summary()[source]

The summary of the page, usually the first paragraph.

coroutine urls()[source]

A namedtuple representing the view and edit URL for the page.

coroutine media()[source]

Returns a list of all media used on the page.

coroutine edit(content: str)[source]

Edits the page.

aiowiki.wiki module

class aiowiki.wiki.Wiki(base_url: str, session: Optional[aiohttp.client.ClientSession] = None)[source]

Bases: object

Represents a Mediawiki and is the main entry class to the library.

Parameters
  • base_url (str) – The api.php endpoint of your Wiki

  • session (aiohttp.ClientSession or None) – An opional aiohttp.ClientSession to use for the internal Wiki HTTP operations. Leaving this empty will automatically create one.

Variables
classmethod wikipedia(language='en', *args, **kwargs)[source]
coroutine close()[source]

Close the aiohttp Session

coroutine get_token(type: str = 'csrf')[source]

Get an API token for a login attempt.

coroutine get_random_pages(num: int = 1, namespace: str = '*')[source]

Gets a list of random Page objects

coroutine create_account(username: str, password: str, email: Optional[str] = None, real_name: Optional[str] = None)[source]

Creates an account in the wiki. May fail if captchas are required.

coroutine userrights(username: str, action: str, group: str)[source]

Update user rights of ‘username’, action: add or remove. Can add or remove many groups with sep groups name by ‘|’. ex: username: ‘my_id’, action: ‘add’, group: ‘bureaucrat|bot’

coroutine login(username: str, password: str)[source]

Logs in to the wiki.

get_page(page_title: str)[source]

Retrieves a page from the wiki. Returns a Page object.

coroutine opensearch(search_query: str, limit: int = 10, namespace: str = '0')[source]

Returns limit Page objects matching the query

Module contents