Configuration, enums and exceptions#

The global options, the enumerations of the API values, the exceptions, the retries, the WikibaseManifest of an instance and the EditGroups.

Configuration#

Config global options Options can be changed at run time. See test/test_wbi_backoff.py for usage example

Options:

BACKOFF_MAX_TRIES: maximum number of tries of a SPARQL query or a login failing with a transient error (see wbi_backoff).
                   Default: 5
                   Set to None to retry indefinitely, or to 1 to disable the retries
BACKOFF_MAX_VALUE: maximum number of seconds to wait before retrying. The wait doubles after each try (1, 2, 4... seconds)
                   up to this number. Also caps the delay asked by the SPARQL endpoint with an HTTP 429 response.
                   Default: 3600 (one hour)
USER_AGENT:        Complementary user agent string used for http requests. Both to Wikibase api, query service and others.
                   See: https://foundation.wikimedia.org/wiki/Policy:User-Agent_policy
TIMEOUT:           Timeout (in seconds) passed to every HTTP request, either a single value or a (connect, read) tuple.
                   Prevents a silent/unresponsive server from blocking the process indefinitely.
                   Set to None to disable (wait forever). Default: (5, 300)
SPARQL_AUTH:       Default authentication used by wbi_helpers.execute_sparql_query() (and so by the fast run mode) when the
                   SPARQL endpoint is protected. Either a (username, password) tuple for HTTP Basic auth or any
                   requests.auth.AuthBase instance. Default: None (no authentication)
MAX_REQUEST_SIZE:  Maximum size (in bytes) of the entity data sent by a write, once form-encoded. A larger write is
                   split into several edits: the first one with everything but the statements and as many statements as
                   fit, then the remaining statements. Use it with a Wikibase instance rejecting large requests with an
                   HTTP 413 error (e.g. Wikibase.cloud), with a margin for the other parameters of the request.
                   Default: None (never split)

Enums#

ActionIfExists

Action to take if a statement with a property already exists on the entity.

EntityField

The different fields of an entity.

WikibaseDatatype

The datatypes of the properties, as named by the Wikibase API.

WikibaseRank

The rank of a statement.

WikibaseSnakType

The snak type of the Wikibase data snak, three values possible, depending if the value is a known (value), not existent (novalue) or unknown (somevalue).

WikibaseTimePrecision

The precision of a time value.

Exceptions#

MWApiError

Base class for MediaWiki API error handling

ModificationFailed

When the API return a 'modification-failed' error

SaveFailed

When the API return a 'save-failed' error

NonExistentEntityError

MissingExtensionError

Raised when a request needs a MediaWiki extension the Wikibase instance doesn't provide, e.g. the lexemes of the WikibaseLexeme extension.

MissingEntityException

EmptyValueError

Raised before a write when a claim, a qualifier or a reference has no value, while its snak type states that it has one.

UnknownDatatypeError

Raised when no data type class handles a datatype, like one added to the Wikibase instance by an extension that WikibaseIntegrator doesn't support.

AnonymousEditNotAllowedError

Raised when an anonymous edit is attempted while it is not explicitly allowed.

MaxRetriesReachedException

SearchError

WCQSAuthenticationError

Raised when the Wikimedia Commons Query Service doesn't accept the wcqsOauth cookie given to wbi_login.WCQSAuth: it answers with the HTML login page of Wikimedia Commons instead of the query results.

Retries#

wbi_backoff

Decorator retrying the call on the transient errors: the wbi_backoff_exceptions for which wbi_backoff_giveup() is False.

RetryAfterError

An HTTP 429 (Too Many Requests) response.

wbi_backoff_wait

The number of seconds to wait after the given number of failed tries: 1, 2, 4, 8.

wbi_backoff_giveup

Give up immediately on permanent errors: a real JSON decode error, or a client error (HTTP 4xx) other than RETRIED_CLIENT_ERRORS, like a malformed query (400) or an authentication failure (401/403), which retrying the same request cannot fix.

WikibaseManifest#

Support of the WikibaseManifest extension (https://www.mediawiki.org/wiki/Extension:WikibaseManifest), which describes a Wikibase instance for the tools: its API endpoints, query service, RDF namespaces, entity types and the local IDs of some Wikidata entities. It is installed on the instances of Wikibase.cloud, for example.

Configure WikibaseIntegrator for an instance from its manifest:

from wikibaseintegrator import wbi_manifest

manifest = wbi_manifest.get_manifest('https://wikibase.world/w/rest.php')
manifest.apply()  # sets wbi_config['MEDIAWIKI_API_URL'], ['SPARQL_ENDPOINT_URL'], ['WIKIBASE_URL']...

instance_of = manifest.local_id('P31')  # the local property equivalent to P31 on Wikidata, e.g. 'P3'

get_manifest

Download the manifest of a Wikibase instance with the WikibaseManifest extension.

WikibaseManifest

The manifest of a Wikibase instance, as returned by get_manifest().

manifest_url

The URL of the manifest, from the MediaWiki REST API of the instance (rest.php) or the URL of the manifest itself.

EditGroups#

EditGroup

An EditGroups batch of a custom bot. Add the batch link to the summary of every edit of the batch::.