pythonmediawikiwikidatapywikibot

how to work with custom wikibase using pywikibot


I have my family file, user-config.py and user-password.py in the directory that i am running the following script from

import os, sys
import pywikibot as pwb
pwb.config.register_families_folder(os.getcwd())
pwb.login.ClientLoginManager().login()
os.environ['PYWIKIBOT_DIR'] = os.getcwd()
site = pwb.Site()
repo = site.data_repository()
pg = pwb.ItemPage(repo, 'Q1')
pg.get()

But i get the following error

AttributeError: DataSite instance has no attribute 'entity_sources'

How do i resolve this ?


Solution

  • In Pywikibot 8 federated Wikibase was implemented. The DataSite.get_repo_for_entity_type() method expects a entity_sources() method in your wikibase family file. To solve this issue with your data repository you can do the following:

    Pywikibot release 7.7.3 and below

    Since the extension federated Wikibase is not available here, a release downgrade could solve it but it is not recommended because Pywikibot 8 comes with a lot of improvements and bugfixes. See the changelog for more information.

    Pywikibot release 8.0 and 8.1

    All you have to do is to add the following lines into your wikibase family file:

    def entity_sources(self, code: str) -> Dict[str, Tuple[str, str]]:
    """Provide repository site information for entity types."""
        return {}
    

    For more information refer the manual.

    Pywikibot release 8.2

    If all entity types are handled by your wikibase repository given by your wikibase family file you can just inherit your family (maybe additionally) from family.WikibaseFamily. If you have different repositories for different entity types (i.e. federated Wikibase), you have to define your own entity_sources method in your wikibase family file like described in the Pywikibot release 8.0 and 8.1 section.

    Hint

    For a federated Wikibase setting you can use commons_family and its code as a sample.