Skip to content

Give each WikibaseIntegrator its own configuration - #1227

Merged
LeMyst merged 1 commit into
masterfrom
instance-config
Nov 15, 2026
Merged

LeMyst merged 1 commit into
masterfrom
instance-config

Conversation

@LeMyst

@LeMyst LeMyst commented Nov 15, 2026

Copy link
Copy Markdown
Owner

Part 1 of #1193, with your answers: a config= dict overlay, and the entities plus fast run use it. Part 2, the datatype IRIs resolved when they're serialized, comes in a separate PR on top of this one. It touches every get_json() and the equality checks, so it's easier to review on its own. #1193 stays open until part 2 merges.

WikibaseIntegrator(config=...)

world = WikibaseIntegrator(login=login, config=wbi_manifest.get_manifest('https://wikibase.world/w/rest.php').config())
world = WikibaseIntegrator(config={'MEDIAWIKI_API_URL': ..., 'SPARQL_ENDPOINT_URL': ..., 'WIKIBASE_URL': ...})
  • Keys: the same as wbi_config. An unknown key raises ValueError, so a typo doesn't pass silently.
  • The other options: read from wbi_config when they're used, so changing wbi_config still applies to them. WikibaseIntegrator() without config behaves exactly as before.
  • wbi.config: read-only, typed Mapping[str, Any]. Making it writable in 1.x wouldn't break anything.
  • Copies: the configuration is shared by the copies of an entity, deepcopy included. A MappingProxyType can't be deep-copied, which broke Claims.add, so it's a small private Mapping.

What uses it

Option Used by the entities of the instance for
MEDIAWIKI_API_URL, USER_AGENT every request: get(), get(revision=), get_claims(), write(), delete(), the lexeme form and sense methods, mediainfo.get_by_title()
MAX_REQUEST_SIZE write()
WIKIBASE_URL get_entity_url(), fast run
SPARQL_ENDPOINT_URL fast run (write_required())
DEFAULT_LEXEME_LANGUAGE new lexemes

An argument given to a method (mediawiki_api_url=...) still takes precedence. An argument passed as None takes the configuration.

What still reads wbi_config (documented):

  • the wbi_helpers functions, as you chose;
  • retries and timeouts;
  • the default language of labels;
  • the datatypes, until part 2.

MEDIAWIKI_REST_URL and MEDIAWIKI_INDEX_URL are accepted, since manifest.config() has them, but the entities don't use them. A login has its own URLs.

Fast run

  • New arguments: get_fastrun_container() and FastRunContainer take wikibase_url, mediawiki_api_url and user_agent, all optional. The property types (for a graph without the properties) are read from the MediaWiki API of the container. Its SPARQL queries send its user agent.
  • Store: containers are also told apart by Wikibase URL and MediaWiki API URL, so two instances never share one.
  • Fix: the value key of a claim now uses the container's Wikibase URL. It used to use the global one, which was the same until now.
  • New wbi_fastrun.clear_fastrun_store(): empties the store, which otherwise keeps every container for the whole process.

Not breaking

No signature loses anything, and the defaults are unchanged. Label: enhancement.

Docs

  • installation.md: a "Several instances in one process" section, with what uses the instance configuration and what doesn't.
  • fastrun.md: the new defaults, and clear_fastrun_store().
  • API reference: updated.

Tests

  • test/test_instance_config.py: 24 tests with two MockWikibase instances side by side.
    • Each request (get, revision, get_claims, write, split write, delete, lexeme forms, MediaInfo title, fast run SPARQL and property types) reaches the right instance, with its user agent.
    • The default instance still follows wbi_config.
    • Explicit arguments take precedence.
    • It also covers unknown keys, the read-only view, copies, one container per instance, and clear_fastrun_store().
  • Integration (test_instance_configuration): wbi_config points to an unreachable host, and an instance configured for the real Wikibase reads, runs fast run against its query service, writes, and deletes.
  • Results:
    • 1573 passed, coverage still 100 %.
    • isort, mypy, pylint (E/W), codespell and flynt pass, and so does the nitpicky docs build.

🤖 Generated with Claude Code

#1193, as decided on 2026-11-15: WikibaseIntegrator(config=...) takes
the options of wbi_config that differ for this instance, and reads the
others from wbi_config when they're used. wbi.config is read-only.

The entities of an instance use its MEDIAWIKI_API_URL, USER_AGENT and
MAX_REQUEST_SIZE for their requests, its WIKIBASE_URL for
get_entity_url(), its DEFAULT_LEXEME_LANGUAGE for new lexemes, and its
SPARQL_ENDPOINT_URL and WIKIBASE_URL for write_required(). The fast run
containers are told apart by their Wikibase URL and MediaWiki API URL
too, and wbi_fastrun.clear_fastrun_store() empties the store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeMyst LeMyst added this to the v1.0 milestone Nov 15, 2026
@LeMyst LeMyst added the enhancement New feature or request label Nov 15, 2026
@LeMyst
LeMyst merged commit 069d0f2 into master Nov 15, 2026
20 checks passed
@LeMyst
LeMyst deleted the instance-config branch November 15, 2026 22:28
@LeMyst LeMyst mentioned this pull request Nov 15, 2026
19 of 23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant