Skip to content

gquery

Generator-based query methods which can be used to fetch a limited number of results

GQuery

Collection of queries which fetch and yield results via Generator.

all_users(wiki, groups=[], limit=1) staticmethod

Lists all users on a wiki. Can filter users by right(s) they have been assigned.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
groups Union[list[str], str]

The group(s) to filter by (e.g. sysop, bot). Optional, leave empty to disable. Defaults to [].

[]
limit Union[int, str]

The maximum number of elements to return per iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing users (without the User: prefix) that match the specified crteria.

categories_on_page(wiki, title, limit=1) staticmethod

Fetch the categories used on a page.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
title str

The title to query.

required
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing the categories contained on title.

category_members(wiki, title, ns=[], limit=1) staticmethod

Fetches the elements in a category.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
title str

The title of the category to fetch elements from. Must include Category: prefix.

required
ns list[Union[NS, str]]

Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].

[]
limit Union[int, str]

The maximum number of elements to return per iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing the category's category members.

contribs(wiki, user, older_first=False, ns=[], limit=1) staticmethod

Fetches contributions of a user.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
user str

The username to query, excluding the User: prefix.

required
older_first bool

Set True to fetch older elements first. Defaults to False.

False
ns list[Union[NS, str]]

Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].

[]
limit Union[int, str]

The maximum number of elements to return per iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[Contrib], None, None]

Generator[list[Contrib], None, None]: A Generator which yields a list of Contrib as specified.

deleted_revisions(wiki, title, limit=1, older_first=False, include_text=False) staticmethod

Fetches all the deleted revisions of title. PRECONDITION: You must be logged in and have admin rights in order for this to work.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use.

required
title str

The title to get deleted revisions for.

required
limit Union[int, str]

The maxmimum number of revisions to fetch each iteration. Defaults to 1.

1
older_first bool

Set to True to fetch older revisions first. Defaults to False.

False
include_text bool

If True, then also fetch the wikitext of each revision. Will populate the Revision.text field. Defaults to False.

False

Returns:

Type Description
Generator[list[Revision], None, None]

Generator[list[Revision], None, None]: A Generator which yields a list containing the (deleted) Revision objects of title.

list_duplicate_files(wiki, limit=1) staticmethod

List files on a wiki which have duplicates by querying the Special page Special:ListDuplicatedFiles.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
limit Union[int, str]

The maximum number of elements to return per iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing files that have duplicates on the wiki.

logs(wiki, title=None, log_type=None, log_action=None, user=None, ns=None, tag=None, start=None, end=None, older_first=False, limit=1) staticmethod

Fetches Special:Log entries from a wiki. PRECONDITION: if start and end are both set, then start must occur before end.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
title str

The title of the page to get logs for, if applicable. Defaults to None.

None
log_type str

The type of log to fetch (e.g. "delete"). Defaults to None.

None
log_action str

The type and sub-action of the log to fetch (e.g. "delete/restore"). Overrides log_type. Defaults to None.

None
user str

The user associated with the log action, if applicable. Do not include User: prefix. Defaults to None.

None
ns Union[NS, str]

Only return results that are in this namespace. Defaults to None.

None
tag str

Only return results that are tagged with this tag. Defaults to None.

None
start datetime

Set to filter out revisions older than this date. If no timezone is specified in the datetime, then UTC is assumed. Defaults to None.

None
end datetime

Set to filter out revisions newer than this date. If no timezone is specified in the datetime, then UTC is assumed. Defaults to None.

None
older_first bool

Set to True to fetch older log entries first. Defaults to False.

False
limit Union[int, str]

The maximum number of elements to return per iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[Log], None, None]

Generator[list[Log], None, None]: A Generator which yields a list of Log as specified.

prefix_index(wiki, ns, prefix, limit=1) staticmethod

Performs a prefix index query and returns all matching titles.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
ns Union[NS, str]

The namespace to search in.

required
prefix str

Fetches all titles in the specified namespace that start with this str. To return subpages only, append a / character to this param.

required
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing files that match the specified prefix index.

random(wiki, ns=[], limit=1) staticmethod

Fetches a list of random pages from the wiki.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
ns list[Union[NS, str]]

Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].

[]
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing random elements that match specified parameters.

revisions(wiki, title, limit=1, older_first=False, start=None, end=None, include_text=False) staticmethod

Gets the revisions of a page. Fetches newer revisions first by default. PRECONDITION: if start and end are both set, then start must occur before end.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use.

required
title str

The title to get revisions of.

required
limit Union[int, str]

The maxmimum number of revisions to fetch each iteration. Defaults to 1.

1
older_first bool

Set to True to fetch older revisions first. Defaults to False.

False
start datetime

Set to filter out revisions older than this date. If no timezone is specified in the datetime, then UTC is assumed. Defaults to None.

None
end datetime

Set to filter out revisions newer than this date. If no timezone is specified in the datetime, then UTC is assumed. Defaults to None.

None
include_text bool

If True, then also fetch the wikitext of each revision. Will populate the Revision.text field. Defaults to False.

False

Returns:

Type Description
Generator[list[Revision], None, None]

Generator[list[Revision], None, None]: A Generator which yields a list containing the Revision objects of title.

search(wiki, phrase, ns=[], limit=1) staticmethod

Perform a search on the wiki.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
phrase str

The phrase to query with

required
ns list[Union[NS, str]]

Only return results that are in these namespaces. Optional, set empty list to disable. Defaults to [].

[]
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing the results of the search.

stashed_files(wiki, limit=1) staticmethod

Fetch the user's stashed files. PRECONDITION: You must be logged in for this to work

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[tuple[str, int, str]], None, None]

Generator[list[tuple[str, int]], None, None]: A Generator which yields a list of 3-tuple where each tuple is of the form (file key, file size, status). Known values for status: "finished", "chunks"

user_uploads(wiki, user, limit=1) staticmethod

Gets the uploads of a user.

Parameters:

Name Type Description Default
wiki Wiki

The Wiki object to use

required
user str

The username to query, without the User: prefix.

required
limit Union[int, str]

The maxmimum number of elements to fetch each iteration. Defaults to 1.

1

Returns:

Type Description
Generator[list[str], None, None]

Generator[list[str], None, None]: A Generator which yields a list containing the files uploaded by user.