{"id":15017691,"url":"https://github.com/lemyst/wikibaseintegrator","last_synced_at":"2025-09-08T18:31:05.254Z","repository":{"id":36998528,"uuid":"233309030","full_name":"LeMyst/WikibaseIntegrator","owner":"LeMyst","description":"A Python module to manipulate data on a Wikibase instance (like Wikidata) through the MediaWiki Wikibase API and the Wikibase SPARQL endpoint.","archived":false,"fork":false,"pushed_at":"2025-09-04T22:33:38.000Z","size":2784,"stargazers_count":78,"open_issues_count":58,"forks_count":19,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-05T00:10:56.765Z","etag":null,"topics":["mediawiki","sparql","wikibase","wikidata","wikidata-api","wikidata-toolkit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeMyst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-01-11T22:59:59.000Z","updated_at":"2025-09-04T22:33:40.000Z","dependencies_parsed_at":"2023-10-03T13:51:58.584Z","dependency_job_id":"d9d71f88-62b9-41d9-8e4e-99ca63848241","html_url":"https://github.com/LeMyst/WikibaseIntegrator","commit_stats":{"total_commits":1434,"total_committers":33,"mean_commits":43.45454545454545,"dds":0.6652719665271967,"last_synced_commit":"9bd1b30ac3f0fba7b6d147b401687392c76c3c71"},"previous_names":[],"tags_count":81,"template":false,"template_full_name":null,"purl":"pkg:github/LeMyst/WikibaseIntegrator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeMyst%2FWikibaseIntegrator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeMyst%2FWikibaseIntegrator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeMyst%2FWikibaseIntegrator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeMyst%2FWikibaseIntegrator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeMyst","download_url":"https://codeload.github.com/LeMyst/WikibaseIntegrator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeMyst%2FWikibaseIntegrator/sbom","scorecard":{"id":82737,"data":{"date":"2025-08-11","repo":{"name":"github.com/LeMyst/WikibaseIntegrator","commit":"89d23812e37eec9b1dda1cfb84a1a4ef25ad747b"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":6.1,"checks":[{"name":"Code-Review","score":2,"reason":"Found 1/4 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Maintained","score":10,"reason":"17 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 10","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/auto-assign-issue.yaml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/auto-assign-issue.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:40: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/codeql.yml:58: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/codeql.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:60: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:65: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:86: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:91: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:108: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/publish-to-pypi.yaml:113: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/publish-to-pypi.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-lint.yaml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/python-lint.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-lint.yaml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/python-lint.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-pytest.yaml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/python-pytest.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/python-pytest.yaml:53: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/python-pytest.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/trivy-scan.yaml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/trivy-scan.yaml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/trivy-scan.yaml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/trivy-scan.yaml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/trivy-scan.yaml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/LeMyst/WikibaseIntegrator/trivy-scan.yaml/master?enable=pin","Warn: pipCommand not pinned by hash: .github/workflows/publish-to-pypi.yaml:31","Warn: pipCommand not pinned by hash: .github/workflows/python-lint.yaml:34","Warn: pipCommand not pinned by hash: .github/workflows/python-pytest.yaml:61","Info:   0 out of  15 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   5 third-party GitHubAction dependencies pinned","Info:   0 out of   3 pipCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Info: jobLevel 'packages' permission set to 'read': .github/workflows/codeql.yml:21","Info: jobLevel 'actions' permission set to 'read': .github/workflows/codeql.yml:24","Info: jobLevel 'contents' permission set to 'read': .github/workflows/codeql.yml:25","Warn: jobLevel 'contents' permission set to 'write': .github/workflows/publish-to-pypi.yaml:103","Warn: no topLevel permission defined: .github/workflows/auto-assign-issue.yaml:1","Warn: no topLevel permission defined: .github/workflows/codeql.yml:1","Warn: no topLevel permission defined: .github/workflows/publish-to-pypi.yaml:1","Warn: no topLevel permission defined: .github/workflows/python-lint.yaml:1","Warn: no topLevel permission defined: .github/workflows/python-pytest.yaml:1","Warn: no topLevel permission defined: .github/workflows/trivy-scan.yaml:1"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":8,"reason":"5 out of the last 5 releases have a total of 5 signed artifacts.","details":["Info: signed release artifact: wikibaseintegrator-0.12.12-py3-none-any.whl.sigstore.json: https://github.com/LeMyst/WikibaseIntegrator/releases/tag/v0.12.12","Info: signed release artifact: wikibaseintegrator-0.12.11-py3-none-any.whl.sigstore.json: https://github.com/LeMyst/WikibaseIntegrator/releases/tag/v0.12.11","Info: signed release artifact: wikibaseintegrator-0.12.10-py3-none-any.whl.sigstore.json: https://github.com/LeMyst/WikibaseIntegrator/releases/tag/v0.12.10","Info: signed release artifact: wikibaseintegrator-0.12.9-py3-none-any.whl.sigstore.json: https://github.com/LeMyst/WikibaseIntegrator/releases/tag/v0.12.9","Info: signed release artifact: wikibaseintegrator-0.12.8-py3-none-any.whl.sigstore.json: https://github.com/LeMyst/WikibaseIntegrator/releases/tag/v0.12.8","Warn: release artifact v0.12.12 does not have provenance: https://api.github.com/repos/LeMyst/WikibaseIntegrator/releases/192807344","Warn: release artifact v0.12.11 does not have provenance: https://api.github.com/repos/LeMyst/WikibaseIntegrator/releases/188259694","Warn: release artifact v0.12.10 does not have provenance: https://api.github.com/repos/LeMyst/WikibaseIntegrator/releases/185573160","Warn: release artifact v0.12.9 does not have provenance: https://api.github.com/repos/LeMyst/WikibaseIntegrator/releases/185526447","Warn: release artifact v0.12.8 does not have provenance: https://api.github.com/repos/LeMyst/WikibaseIntegrator/releases/173941363"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during GetBranch(rewrite-wbi): error during branchesHandler.query: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Packaging","score":10,"reason":"packaging workflow detected","details":["Info: Project packages its releases by way of GitHub Actions.: .github/workflows/publish-to-pypi.yaml:69"],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Vulnerabilities","score":9,"reason":"1 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-33p9-3p43-82vq"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":10,"reason":"SAST tool is run on all commits","details":["Info: SAST configuration detected: CodeQL","Info: all commits (30) are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T06:14:43.391Z","repository_id":36998528,"created_at":"2025-08-15T06:14:43.391Z","updated_at":"2025-08-15T06:14:43.391Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274229367,"owners_count":25245187,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-08T02:00:09.813Z","response_time":121,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mediawiki","sparql","wikibase","wikidata","wikidata-api","wikidata-toolkit"],"created_at":"2024-09-24T19:50:51.855Z","updated_at":"2025-09-08T18:31:05.230Z","avatar_url":"https://github.com/LeMyst.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Wikibase Integrator #\n\n[![PyPi](https://img.shields.io/pypi/v/wikibaseintegrator.svg)](https://pypi.python.org/pypi/wikibaseintegrator)\n[![Python pytest](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/python-pytest.yaml/badge.svg)](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/python-pytest.yaml)\n[![Python Code Quality and Lint](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/python-lint.yaml/badge.svg)](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/python-lint.yaml)\n[![CodeQL](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/codeql.yml/badge.svg)](https://github.com/LeMyst/WikibaseIntegrator/actions/workflows/codeql.yml)\n[![Pyversions](https://img.shields.io/pypi/implementation/wikibaseintegrator.svg)](https://pypi.python.org/pypi/wikibaseintegrator)\n[![Read the Docs](https://readthedocs.org/projects/wikibaseintegrator/badge/?version=latest\u0026style=flat)](https://wikibaseintegrator.readthedocs.io)\n\nWikibase Integrator is a python package whose purpose is to manipulate data present on a Wikibase instance (like\nWikidata).\n\n# Breaking changes in v0.12 #\n\nA complete rewrite of the WikibaseIntegrator core has been done in v0.12 which has led to some important changes.\n\nIt offers a new object-oriented approach, better code readability and support for Property, Lexeme and MediaInfo\nentities (in addition to Item).\n\nIf you want to stay on v0.11.x, you can put this line in your requirements.txt:\n\n```\nwikibaseintegrator~=0.11.3\n```\n\n---\n\n\u003c!-- ToC generator: https://luciopaiva.com/markdown-toc/ --\u003e\n\n- [WikibaseIntegrator / WikidataIntegrator](#wikibaseintegrator--wikidataintegrator)\n- [Documentation](#documentation)\n    - [Jupyter notebooks](#jupyter-notebooks)\n        - [Common use cases](#common-use-cases)\n            - [Read an existing entity](#read-an-existing-entity)\n            - [Start a new entity](#start-a-new-entity)\n            - [Write an entity to instance](#write-an-entity-to-instance)\n            - [Add labels](#add-labels)\n            - [Get label value](#get-label-value)\n            - [Add aliases](#add-aliases)\n            - [Add descriptions](#add-descriptions)\n            - [Add a simple claim](#add-a-simple-claim)\n            - [Get claim value](#get-claim-value)\n            - [Manipulate claim, add a qualifier](#manipulate-claim-add-a-qualifier)\n            - [Manipulate claim, add references](#manipulate-claim-add-references)\n            - [Remove a specific claim](#remove-a-specific-claim)\n            - [Get lemma on lexeme](#get-lemma-on-lexeme)\n            - [Set lemma on lexeme](#set-lemma-on-lexeme)\n            - [Add gloss to a sense on lexeme](#add-gloss-to-a-sense-on-lexeme)\n            - [Add form to a lexeme](#add-form-to-a-lexeme)\n    - [Other projects](#other-projects)\n- [Installation](#installation)\n- [Installation of the development environment](#installation-of-the-development-environment)\n- [Using a Wikibase instance](#using-a-wikibase-instance)\n    - [Wikimedia Foundation User-Agent policy](#wikimedia-foundation-user-agent-policy)\n- [The Core Parts](#the-core-parts)\n    - [Entity manipulation](#entity-manipulation)\n    - [wbi_login](#wbi_login)\n        - [Login using OAuth1 or OAuth2](#login-using-oauth1-or-oauth2)\n            - [As a bot](#as-a-bot)\n            - [To impersonate a user (OAuth 1.0a)](#to-impersonate-a-user-oauth-10a)\n        - [Login with a bot password](#login-with-a-bot-password)\n        - [Login with a username and a password](#login-with-a-username-and-a-password)\n    - [Wikibase Data Types](#wikibase-data-types)\n    - [Structured Data on Commons](#structured-data-on-commons)\n        - [Retrieve data](#retrieve-data)\n        - [Write data](#write-data)\n- [More than Wikibase](#more-than-wikibase)\n- [Helper Methods](#helper-methods)\n    - [Use MediaWiki API](#use-mediawiki-api)\n    - [Execute SPARQL queries](#execute-sparql-queries)\n    - [Wikibase search entities](#wikibase-search-entities)\n    - [Merge Wikibase items](#merge-wikibase-items)\n- [Examples (in \"normal\" mode)](#examples-in-normal-mode)\n    - [Create a new Item](#create-a-new-item)\n    - [Modify an existing item](#modify-an-existing-item)\n    - [A bot for Mass Import](#a-bot-for-mass-import)\n- [Examples (in \"fast run\" mode)](#examples-in-fast-run-mode)\n- [Debugging](#debugging)\n\n# WikibaseIntegrator / WikidataIntegrator #\n\nWikibaseIntegrator (wbi) is a fork of [WikidataIntegrator](https://github.com/SuLab/WikidataIntegrator) (wdi) whose\npurpose is to focus on an improved compatibility with Wikibase and adding missing functionalities.\nThe main differences between these two libraries are :\n\n* A complete rewrite of the library with a more object-oriented architecture allowing for easy interaction, data\n  validation and extended functionality\n* Add support for reading and writing Lexeme, MediaInfo and Property entities\n* Python 3.9 to 3.13 support, validated with unit tests\n* Type hints implementation for arguments and return, checked with mypy static type checker\n* Add OAuth 2.0 login method\n* Add logging module support\n\nBut WikibaseIntegrator lack the \"fastrun\" functionality implemented in WikidataIntegrator.\n\n# Documentation #\n\nA (basic) documentation generated from the python source code is available on\nthe [Read the Docs website](https://wikibaseintegrator.readthedocs.io/).\n\n## Jupyter notebooks ##\n\nYou can find some sample code (adding an entity, a lexeme, etc.) in\nthe [Jupyter notebook directory](https://github.com/LeMyst/WikibaseIntegrator/tree/master/notebooks) of the repository.\n\n### Common use cases\n\n#### Read an existing entity\n\nGet the entity with the QID Q582 from the instance.\n\nFrom [import_entity.ipynb](notebooks/import_entity.ipynb)\n\n```python\nentity = wbi.item.get('Q582')\n```\n\n#### Start a new entity\n\nStart a new local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nentity = wbi.item.new()\n```\n\n#### Write an entity to instance\n\nWrite a local entity to the instance.\n\nFrom [import_entity.ipynb](notebooks/import_entity.ipynb)\n\n```python\nentity.write()\n```\n\n#### Add labels\n\nAdd an English and a French label to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nentity.labels.set('en', 'New item')\nentity.labels.set('fr', 'Nouvel élément')\n```\n\n#### Get label value\n\nGet the english label value of the local entity.\n\nFrom [item_get.ipynb](notebooks/item_get.ipynb)\n\n```python\nentity.labels.get('en').value\n```\n\n#### Add aliases\n\nAdd an English and a French alias to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nentity.aliases.set('en', 'Item')\nentity.aliases.set('fr', 'Élément')\n```\n\n#### Add descriptions\n\nAdd an English and a French description to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nentity.descriptions.set('en', 'A freshly created element')\nentity.descriptions.set('fr', 'Un élément fraichement créé')\n```\n\n#### Add a simple claim\n\nAdd a Time claim with the property P74 and the current time to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nclaim_time = datatypes.Time(prop_nr='P74', time='now')\n\nentity.claims.add(claim_time)\n```\n\n#### Get claim value\n\nGet the value of the first claim with the property P2048 of the local entity.\n\nFrom [item_get.ipynb](notebooks/item_get.ipynb)\n\n```python\nentity.claims.get('P2048')[0].mainsnak.datavalue['value']['amount']\n```\n\n#### Manipulate claim, add a qualifier\n\n* Initialize a new Qualifiers object, add a String qualifier with the property P828 and the value 'Item qualifier' to the Qualifiers object.\n* Create a String claim with the property P31533 and the value 'A String property' with the previously created Qualifiers object as qualifiers.\n* Add the newly created claim to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nqualifiers = Qualifiers()\nqualifiers.add(datatypes.String(prop_nr='P828', value='Item qualifier'))\n\nclaim_string = datatypes.String(prop_nr='P31533', value='A String property', qualifiers=qualifiers)\nentity.claims.add(claim_string)\n```\n\n#### Manipulate claim, add references\n\n* Initialize a new References object.\n* Initialize a new Reference object, add a String reference with the property P828 and the value 'Item string reference' to the Reference object.\n* Initialize a new Reference object, add a String reference with the property P828 and the value 'Another item string reference' to the Reference object.\n* Add the newly created Reference objects to the References object.\n* Create a String claim with the property P31533 and the value 'A String property' with the previously created References object as references.\n* Add the newly created claim to the local entity.\n\nFrom [item_create_new.ipynb](notebooks/item_create_new.ipynb)\n\n```python\nreferences = References()\nreference1 = Reference()\nreference1.add(datatypes.String(prop_nr='P828', value='Item string reference'))\n\nreference2 = Reference()\nreference2.add(datatypes.String(prop_nr='P828', value='Another item string reference'))\n\nreferences.add(reference1)\nreferences.add(reference2)\n\nnew_claim_string = datatypes.String(prop_nr='P31533', value='A String property', references=references)\nentity.claims.add(claim_string)\n```\n\n#### Remove a specific claim\n\nRemove all claims with the property P31533 and the value Q123 from the local entity.\n\n```python\nclaims = entity.claims.get('P31533')\nfor claim in claims:\n    if claim.mainsnak.datavalue['value']['id'] == 'Q123':\n        claim.remove()\n```\n\n#### Get lemma on lexeme\n\nGet all French lemmas of the lexeme.\n\n```python\nlexeme.lemmas.get(language='fr')\n```\n\n#### Set lemma on lexeme\n\nAdd a French lemma with the value 'réponse' to the lexeme.\n\nFrom [lexeme_update.ipynb](notebooks/lexeme_update.ipynb)\n\n```python\nlexeme.lemmas.set(language='fr', value='réponse')\n```\n\n#### Add gloss to a sense on lexeme\n\n* Create a new Sense object.\n* Add an English gloss with the value 'English gloss' to the Sense object.\n* Add a French gloss with the value 'French gloss' to the Sense object.\n* Create a String claim with the property P828 and the value 'Create a string claim for sense'.\n* Add the newly created claim to the Sense object.\n* Add the newly created Sense object to the lexeme.\n\nFrom [lexeme_write.ipynb](notebooks/lexeme_write.ipynb)\n\n```python\nsense = Sense()\nsense.glosses.set(language='en', value='English gloss')\nsense.glosses.set(language='fr', value='French gloss')\nclaim = datatypes.String(prop_nr='P828', value=\"Create a string claim for sense\")\nsense.claims.add(claim)\nlexeme.senses.add(sense)\n```\n\n#### Add form to a lexeme\n\n* Create a new Form object.\n* Add an English form representation with the value 'English form representation' to the Form object.\n* Add a French form representation with the value 'French form representation' to the Form object.\n* Create a String claim with the property P828 and the value 'Create a string claim for form'.\n* Add the newly created claim to the Form object.\n* Add the newly created Form object to the lexeme.\n\nFrom [lexeme_write.ipynb](notebooks/lexeme_write.ipynb)\n\n```python\nform = Form()\nform.representations.set(language='en', value='English form representation')\nform.representations.set(language='fr', value='French form representation')\nclaim = datatypes.String(prop_nr='P828', value=\"Create a string claim for form\")\nform.claims.add(claim)\nlexeme.forms.add(form)\n```\n\n## Other projects ##\n\nHere is a list of different projects that use the library:\n\n* https://github.com/ACMILabs/acmi-wikidata-bot - A synchronisation robot to push ACMI API Wikidata links to Wikidata.\n* https://github.com/LeMyst/wd-population - Update French population on Wikidata\n* https://github.com/SisonkeBiotik-Africa/AfriBioML - Resources for developing a bibliometric study on machine learning for healthcare in Africa\n* https://github.com/SisonkeBiotik-Africa/Relational-NER - A Python code for enhancing the output of multilingual named entity recognition based on Wikidata relations\n* https://github.com/SoftwareUnderstanding/SALTbot - Software and Article Linker Toolbot\n* https://github.com/dpriskorn/ItemSubjector - CLI-tool to easily add \"main subject\" aka topics in bulk to groups of items on Wikidata\n* https://github.com/dpriskorn/hiking_trail_matcher - Script that helps link together hiking trails in Wikidata and OpenStreetMap\n* https://github.com/eoan-ermine/wikidata_statistik_population - Update German population on Wikidata\n* https://github.com/internetarchive/cgraphbot - Wikibase bot for updating identifiers and citation relationships\n* https://github.com/lubianat/ibge_2021_to_wikidata - Update Population of Brazilian Cities\n* https://github.com/lcnetdev/lccn-wikidata-bot - Adding LCCNs (Library of Congress Control Number) from NACO (Name Authority Cooperative Program) to Wikidata\n* https://github.com/dpriskorn/WikidataEurLexScraper - Improve all Eur-Lex items in Wikidata based on information scraped from Eur-Lex\n* https://github.com/dpriskorn/LexDanNet - Help link DanNet 2.2 word ID with Danish Wikidata lexemes\n* https://github.com/lubianat/kudos_wikibase\n* https://github.com/dlindem/wikibase\n\n# Installation #\n\nThe easiest way to install WikibaseIntegrator is to use the `pip` package manager. WikibaseIntegrator supports Python\n3.9 and above. If Python 2 is installed, `pip` will lead to an error indicating missing dependencies.\n\n```bash\npython -m pip install wikibaseintegrator\n```\n\nYou can also clone the repo and run it with administrator rights or install it in a virtualenv.\n\n```bash\ngit clone https://github.com/LeMyst/WikibaseIntegrator.git\n\ncd WikibaseIntegrator\n\npython -m pip install --upgrade pip setuptools\n\npython -m pip install .\n```\n\nIf you want to install a specific branch or tag from the repository, you can use the following command:\n\n```bash\npython -m pip install git+https://github.com/LeMyst/WikibaseIntegrator.git@v0.12.14\n```\n\nwhere `v0.12.14` is the tag or branch you want to install.\n\nYou can also use Poetry:\n\n```bash\npython -m pip install --upgrade poetry\n\npython -m poetry install\n```\n\nTo check that the installation is correct, launch a Python console and run the following code (which will retrieve the\nWikidata element for [Human](https://www.wikidata.org/entity/Q5)):\n\n```python\nfrom wikibaseintegrator import WikibaseIntegrator\n\nwbi = WikibaseIntegrator()\nmy_first_wikidata_item = wbi.item.get(entity_id='Q5')\n\n# to check successful installation and retrieval of the data, you can print the json representation of the item\nprint(my_first_wikidata_item.get_json())\n```\n\n# Installation of the development environment #\n\nThe following commands will install the development environment with the necessary dependencies:\n\n```bash\npython -m poetry install --with dev,coverage\n```\n\n# Using a Wikibase instance #\n\nWikibaseIntegrator uses Wikidata as default endpoint. To use another instance of Wikibase instead, you can override the\nwbi_config module.\n\nAn example for a Wikibase instance installed\nwith [wikibase-docker](https://github.com/wmde/wikibase-release-pipeline/tree/main/example), add this to the top of your\nscript:\n\n```python\nfrom wikibaseintegrator.wbi_config import config as wbi_config\n\nwbi_config['MEDIAWIKI_API_URL'] = 'http://localhost/api.php'\nwbi_config['SPARQL_ENDPOINT_URL'] = 'http://localhost:8834/proxy/wdqs/bigdata/namespace/wdq/sparql'\nwbi_config['WIKIBASE_URL'] = 'http://wikibase.svc'\n```\n\nYou can find more default settings in the file wbi_config.py\n\n## Wikimedia Foundation User-Agent policy ##\n\nIf you interact with a Wikibase instance hosted by the Wikimedia Foundation (like Wikidata, Wikimedia Commons, etc.),\nit's highly advised to follow the User-Agent policy that you can find on the\npage [User-Agent policy](https://foundation.wikimedia.org/wiki/Policy:User-Agent_policy)\nof the Wikimedia Meta-Wiki.\n\nYou can set a complementary User-Agent by modifying the variable `wbi_config['USER_AGENT']` in wbi_config.\n\nFor example, with your library name and contact information:\n\n```python\nfrom wikibaseintegrator.wbi_config import config as wbi_config\n\nwbi_config['USER_AGENT'] = 'MyWikibaseBot/1.0 (https://www.wikidata.org/wiki/User:MyUsername)'\n```\n\n# The Core Parts #\n\nWikibaseIntegrator supports two modes in which it can be used, a normal mode, updating each item at a time, and a fast\nrun mode, which preloads some data locally and then just updates items if the new data provided differs from Wikidata.\nThe latter mode allows for great speedups when tens of thousands of Wikidata elements need to be checked for updates,\nbut only a small number will eventually be updated, a situation typically encountered when synchronising Wikidata with\nan external resource.\n\n## Entity manipulation ##\n\nWikibaseIntegrator supports the manipulation of Item, Property, Lexeme and MediaInfo entities through these classes:\n\n* wikibaseintegrator.entities.item.Item\n* wikibaseintegrator.entities.property.Property\n* wikibaseintegrator.entities.lexeme.Lexeme\n* wikibaseintegrator.entities.mediainfo.MediaInfo\n\nFeatures:\n\n* Loading a Wikibase entity based on its Wikibase entity ID.\n* All Wikibase data types are implemented (and some data types implemented by extensions).\n* Full access to the entire Wikibase entity in the form of a JSON dict representation.\n\n## wbi_login ##\n\n`wbi_login` provides the login functionality and also stores the cookies and edit tokens required (For security reasons,\nevery MediaWiki edit requires an edit token). There are multiple methods to login:\n\n* `wbi_login.OAuth2(consumer_token, consumer_secret)` (recommended)\n* `wbi_login.OAuth1(consumer_token, consumer_secret, access_token, access_secret)`\n* `wbi_login.Clientlogin(user, password)`\n* `wbi_login.Login(user, password)`\n\nThere is more parameters available. If you want to authenticate on another instance than Wikidata, you can set the\nmediawiki_api_url, mediawiki_rest_url or mediawiki_index_url. Read the documentation for more information.\n\n### Login using OAuth1 or OAuth2 ###\n\nOAuth is the authentication method recommended by the MediaWiki developers. It can be used to authenticate a bot or to\nuse WBI as a backend for an application.\n\n#### As a bot ####\n\nIf you want to use WBI with a bot account, you should use OAuth as\nan [Owner-only consumer](https://www.mediawiki.org/wiki/OAuth/Owner-only_consumers). This allows to use the\nauthentication without the \"continue oauth\" step.\n\nThe first step is to request a new OAuth consumer on your MediaWiki instance on the page\n\"Special:OAuthConsumerRegistration\", the \"Owner-only\" (or \"This consumer is for use only by ...\") has to be checked and\nthe correct version of the OAuth protocol must be set (OAuth 2.0). You will get a consumer token and consumer secret\n(and an access token and access secret if you chose OAuth 1.0a). For a Wikimedia instance (like Wikidata), you need to\nuse the [Meta-Wiki website](https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration).\n\nExample if you use OAuth 2.0:\n\n```python\nfrom wikibaseintegrator import wbi_login\n\nlogin_instance = wbi_login.OAuth2(consumer_token='\u003cyour_client_app_key\u003e', consumer_secret='\u003cyour_client_app_secret\u003e')\n```\n\nExample if you use OAuth 1.0a:\n\n```python\nfrom wikibaseintegrator import wbi_login\n\nlogin_instance = wbi_login.OAuth1(consumer_token='\u003cyour_consumer_key\u003e', consumer_secret='\u003cyour_consumer_secret\u003e',\n                                  access_token='\u003cyour_access_token\u003e', access_secret='\u003cyour_access_secret\u003e')\n```\n\n#### To impersonate a user (OAuth 1.0a) ####\n\nIf WBI is to be used as a backend for a web application, the script must use OAuth for authentication, WBI supports\nthis, you just need to specify consumer key and consumer secret when instantiating `wbi_login.Login`. Unlike login by\nusername and password, OAuth is a 2-step process, as manual confirmation of the user for the OAuth login is required.\nThis means that the `wbi_login.OAuth1.continue_oauth()` method must be called after creating the `wbi_login.Login`\ninstance.\n\nExample:\n\n```python\nfrom wikibaseintegrator import wbi_login\n\nlogin_instance = wbi_login.OAuth1(consumer_token='\u003cyour_consumer_key\u003e', consumer_secret='\u003cyour_consumer_secret\u003e')\nlogin_instance.continue_oauth(oauth_callback_data='\u003cthe_callback_url_returned\u003e')\n```\n\nThe `wbi_login.OAuth1.continue_oauth()` method will either ask the user for a callback URL (normal bot execution) or\ntake a parameter. Thus, in the case where WBI is used as a backend for a web application for example, the callback will\nprovide the authentication information directly to the backend and thus no copy and paste of the callback URL is needed.\n\n### Login with a bot password ###\n\nIt's a good practice to use [Bot password](https://www.mediawiki.org/wiki/Manual:Bot_passwords) instead of simple\nusername and password, this allows limiting the permissions given to the bot.\n\n```python\nfrom wikibaseintegrator import wbi_login\n\nlogin_instance = wbi_login.Login(user='\u003cbot user name\u003e', password='\u003cbot password\u003e')\n```\n\n### Login with a username and a password ###\n\nIf you want to log in with your user account, you can use the \"clientlogin\" authentication method. This method is not\nrecommended.\n\n```python\nfrom wikibaseintegrator import wbi_login\n\nlogin_instance = wbi_login.Clientlogin(user='\u003cuser name\u003e', password='\u003cpassword\u003e')\n```\n\n## Wikibase Data Types ##\n\nCurrently, Wikibase supports 17 different data types. The data types are represented as their own classes in\nwikibaseintegrator.datatypes. Each datatype has its own peculiarities, which means that some of them require special\nparameters (e.g. Globe Coordinates). They are available under the namespace `wikibase.datatypes`.\n\nThe data types currently implemented:\n\n* CommonsMedia\n* ExternalID\n* Form\n* GeoShape\n* GlobeCoordinate\n* Item\n* Lexeme\n* Math\n* MonolingualText\n* MusicalNotation\n* Property\n* Quantity\n* Sense\n* String\n* TabularData\n* Time\n* URL\n\nTwo additional data types are also implemented but require the installation of the MediaWiki extension to work properly:\n\n* extra.EDTF ([Wikibase EDTF](https://www.mediawiki.org/wiki/Extension:Wikibase_EDTF))\n* extra.LocalMedia ([Wikibase Local Media](https://www.mediawiki.org/wiki/Extension:Wikibase_Local_Media))\n\nFor details of how to create values (=instances) with these data types, please (for now) consult the docstrings in the\nsource code or the documentation website. Of note, these data type instances hold the values and, if specified, data\ntype instances for references and qualifiers.\n\n## Structured Data on Commons ##\n\nWikibaseIntegrator supports SDC (Structured Data on Commons) to update a media file hosted on Wikimedia Commons.\n\n\u003e [!IMPORTANT]\n\u003e To ease the compatibility between Wikidata and Wikimedia Commons, the MediaInfo entity use the \"claims\" field instead of the \"statements\" from the API.\n\u003e When you read a MediaInfo entity, the \"claims\" field will be filled with the data from the \"statements\" field.\n\u003e When you write a MediaInfo entity, the \"claims\" field will be replaced by the \"statements\" field.\n\n### Retrieve data ###\n\n```python\nfrom wikibaseintegrator import WikibaseIntegrator\n\nwbi = WikibaseIntegrator()\nmedia = wbi.mediainfo.get('M16431477')\n\n# Retrieve the first \"depicts\" (P180) claim\nprint(media.claims.get('P180')[0].mainsnak.datavalue['value']['id'])\n```\n\n### Write data ###\n\n```python\nfrom wikibaseintegrator import WikibaseIntegrator\nfrom wikibaseintegrator.datatypes import Item\n\nwbi = WikibaseIntegrator()\nmedia = wbi.mediainfo.get('M16431477')\n\n# Add the \"depicts\" (P180) claim\nmedia.claims.add(Item(prop_nr='P180', value='Q3146211'))\n\nmedia.write()\n```\n\n# More than Wikibase #\n\nWikibaseIntegrator natively supports some extensions:\n\n* MediaInfo entity - [WikibaseMediaInfo](https://www.mediawiki.org/wiki/Extension:WikibaseMediaInfo)\n* EDTF datatype - [Wikibase EDTF](https://www.mediawiki.org/wiki/Extension:Wikibase_EDTF)\n* LocalMedia datatype - [Wikibase Local Media](https://www.mediawiki.org/wiki/Extension:Wikibase_Local_Media)\n* Lexeme entity and datatype - [WikibaseLexeme](https://www.mediawiki.org/wiki/Extension:WikibaseLexeme)\n\n# Helper Methods #\n\n## Use MediaWiki API ##\n\nThe method `wbi_helpers.mediawiki_api_call_helper()` allows you to execute MediaWiki API POST call. It takes a mandatory\ndata array (data) and multiple optionals parameters like a login object of type wbi_login.Login, a mediawiki_api_url\nstring if the MediaWiki is not Wikidata, a user_agent string to set a custom HTTP User Agent header, and an\nallow_anonymous boolean to force authentication.\n\nExample:\n\nRetrieve last 10 revisions from Wikidata element Q2 (Earth):\n\n```python\nfrom wikibaseintegrator import wbi_helpers\n\ndata = {\n    'action': 'query',\n    'prop': 'revisions',\n    'titles': 'Q2',\n    'rvlimit': 10\n}\n\nprint(wbi_helpers.mediawiki_api_call_helper(data=data, allow_anonymous=True))\n```\n\n## Execute SPARQL queries ##\n\nThe method `wbi_helpers.execute_sparql_query()` allows you to execute SPARQL queries without a hassle. It takes the\nactual query string (query), optional prefixes (prefix) if you do not want to use the standard prefixes of Wikidata, the\nactual endpoint URL (endpoint), and you can also specify a user agent for the http header sent to the SPARQL server (\nuser_agent). The latter is very useful to let the operators of the endpoint know who you are, especially if you execute\nmany queries on the endpoint. This allows the operators of the endpoint to contact you (e.g. specify an email address,\nor the URL to your bot code repository.)\n\n## Wikibase search entities ##\n\nThe method `wbi_helpers.search_entities()` allows for string search in a Wikibase instance. This means that labels,\ndescriptions and aliases can be searched for a string of interest. The method takes five arguments: The actual search\nstring (search_string), an optional server (mediawiki_api_url, in case the Wikibase instance used is not Wikidata), an\noptional user_agent, an optional max_results (default 500), an optional language (default 'en'), and an option\ndict_id_label to return a dict of item id and label as a result.\n\n## Merge Wikibase items ##\n\nSometimes, Wikibase items need to be merged. An API call exists for that, and wbi_core implements a method accordingly.\n`wbi_helpers.merge_items()` takes five arguments:\n\n* the QID of the item which should be merged into another item (from_id)\n* the QID of the item the first item should be merged into (to_id)\n* a login object of type wbi_login.Login to provide the API call with the required authentication information\n* a boolean if the changes need to be marked as made by a bot (is_bot)\n* a flag for ignoring merge conflicts (ignore_conflicts), will do a partial merge for all statements which do not\n  conflict. This should generally be avoided because it leaves a crippled item in Wikibase. Before a merge, any\n  potential conflicts should be resolved first.\n\n# Examples (in \"normal\" mode) #\n\nIn order to create a minimal bot based on wbi_core, two things are required:\n\n* A datatype object containing a value.\n* An entity object (Item/Property/Lexeme/...) which takes the data, does the checks and performs write.\n\nAn optional Login object can be used to be authenticated on the Wikibase instance.\n\n## Create a new Item ##\n\n```python\nfrom wikibaseintegrator import wbi_login, WikibaseIntegrator\nfrom wikibaseintegrator.datatypes import ExternalID\nfrom wikibaseintegrator.wbi_config import config as wbi_config\n\nwbi_config['USER_AGENT'] = 'MyWikibaseBot/1.0 (https://www.wikidata.org/wiki/User:MyUsername)'\n\n# login object\nlogin_instance = wbi_login.OAuth2(consumer_token='\u003cconsumer_token\u003e', consumer_secret='\u003cconsumer_secret\u003e')\n\nwbi = WikibaseIntegrator(login=login_instance)\n\n# data type object, e.g. for a NCBI gene entrez ID\nentrez_gene_id = ExternalID(value='\u003csome_entrez_id\u003e', prop_nr='P351')\n\n# data goes into a list, because many data objects can be provided to\ndata = [entrez_gene_id]\n\n# Create a new item\nitem = wbi.item.new()\n\n# Set an english label\nitem.labels.set(language='en', value='Newly created item')\n\n# Set a French description\nitem.descriptions.set(language='fr', value='Une description un peu longue')\n\nitem.claims.add(data)\nitem.write()\n```\n\n## Modify an existing item ##\n\n```python\nfrom wikibaseintegrator import wbi_login, WikibaseIntegrator\nfrom wikibaseintegrator.datatypes import ExternalID\nfrom wikibaseintegrator.wbi_enums import ActionIfExists\nfrom wikibaseintegrator.wbi_config import config as wbi_config\n\nwbi_config['USER_AGENT'] = 'MyWikibaseBot/1.0 (https://www.wikidata.org/wiki/User:MyUsername)'\n\n# login object\nlogin_instance = wbi_login.OAuth2(consumer_token='\u003cconsumer_token\u003e', consumer_secret='\u003cconsumer_secret\u003e')\n\nwbi = WikibaseIntegrator(login=login_instance)\n\n# data type object, e.g. for a NCBI gene entrez ID\nentrez_gene_id = ExternalID(value='\u003csome_entrez_id\u003e', prop_nr='P351')\n\n# data goes into a list, because many data objects can be provided to\ndata = [entrez_gene_id]\n\n# Search and then edit an Item\nitem = wbi.item.get(entity_id='Q141806')\n\n# Set an english label but don't modify it if there is already an entry\nitem.labels.set(language='en', value='An updated item', action_if_exists=ActionIfExists.KEEP)\n\n# Set a French description and replace the existing one\nitem.descriptions.set(language='fr', value='Une description un peu longue', action_if_exists=ActionIfExists.REPLACE_ALL)\n\nitem.claims.add(data)\nitem.write()\n```\n\n## A bot for Mass Import ##\n\nAn enhanced example of the previous bot just puts two of the three things into a 'for loop' and so allows mass creation,\nor modification of items.\n\n```python\nfrom wikibaseintegrator import WikibaseIntegrator, wbi_login\nfrom wikibaseintegrator.datatypes import ExternalID, Item, String, Time\nfrom wikibaseintegrator.wbi_config import config as wbi_config\nfrom wikibaseintegrator.wbi_enums import WikibaseTimePrecision\n\nwbi_config['USER_AGENT'] = 'MyWikibaseBot/1.0 (https://www.wikidata.org/wiki/User:MyUsername)'\n\n# login object\nlogin_instance = wbi_login.OAuth2(consumer_token='\u003cconsumer_token\u003e', consumer_secret='\u003cconsumer_secret\u003e')\n\n# We have raw data, which should be written to Wikidata, namely two human NCBI entrez gene IDs mapped to two Ensembl Gene IDs\nraw_data = {\n    '50943': 'ENST00000376197',\n    '1029': 'ENST00000498124'\n}\n\nwbi = WikibaseIntegrator(login=login_instance)\n\nfor entrez_id, ensembl in raw_data.items():\n    # add some references\n    references = [\n        [\n            Item(value='Q20641742', prop_nr='P248'),\n            Time(time='+2020-02-08T00:00:00Z', prop_nr='P813', precision=WikibaseTimePrecision.DAY),\n            ExternalID(value='1017', prop_nr='P351')\n        ]\n    ]\n\n    # data type object\n    entrez_gene_id = String(value=entrez_id, prop_nr='P351', references=references)\n    ensembl_transcript_id = String(value=ensembl, prop_nr='P704', references=references)\n\n    # data goes into a list, because many data objects can be provided to\n    data = [entrez_gene_id, ensembl_transcript_id]\n\n    # Search for and then edit/create new item\n    item = wbi.item.new()\n    item.claims.add(data)\n    item.write()\n```\n\n# Examples (in \"fast run\" mode) #\n\nIn order to use the fast run mode, you need to know the property/value combination which determines the data corpus you\nwould like to operate on. E.g. for operating on human genes, you need to know\nthat [P351](https://www.wikidata.org/entity/P351) is the NCBI Entrez Gene ID and you also need to know that you are\ndealing with humans, best represented by the [found in taxon property (P703)](https://www.wikidata.org/entity/P703) with\nthe value [Q15978631](https://www.wikidata.org/entity/Q15978631) for Homo sapiens.\n\nIMPORTANT: In order for the fast run mode to work, the data you provide in the constructor must contain at least one\nunique value/id only present on one Wikidata element, e.g. an NCBI entrez gene ID, Uniprot ID, etc. Usually, these would\nbe the same unique core properties used for defining domains in wbi_core, e.g. for genes, proteins, drugs or your custom\ndomains.\n\nBelow, the normal mode run example from above, slightly modified, to meet the requirements for the fast run mode. To\nenable it, ItemEngine requires two parameters, fast_run=True/False and fast_run_base_filter which is a dictionary\nholding the properties to filter for as keys, and the item QIDs as dict values. If the value is not a QID but a literal,\njust provide an empty string. For the above example, the dictionary looks like this:\n\n```python\nfrom wikibaseintegrator.datatypes import ExternalID, Item\n\nfast_run_base_filter = [ExternalID(prop_nr='P351'), Item(prop_nr='P703', value='Q15978631')]\n```\n\nThe full example:\n\n```python\nfrom wikibaseintegrator import WikibaseIntegrator, wbi_login\nfrom wikibaseintegrator.datatypes import ExternalID, Item, String, Time\nfrom wikibaseintegrator.wbi_enums import WikibaseTimePrecision\n\n# login object\nlogin = wbi_login.OAuth2(consumer_token='\u003cconsumer_token\u003e', consumer_secret='\u003cconsumer_secret\u003e')\n\nfast_run_base_filter = [ExternalID(prop_nr='P351'), Item(prop_nr='P703', value='Q15978631')]\nfast_run = True\n\n# We have raw data, which should be written to Wikidata, namely two human NCBI entrez gene IDs mapped to two Ensembl Gene IDs\n# You can iterate over any data source as long as you can map the values to Wikidata properties.\nraw_data = {\n    '50943': 'ENST00000376197',\n    '1029': 'ENST00000498124'\n}\n\nfor entrez_id, ensembl in raw_data.items():\n    # add some references\n    references = [\n        [\n            Item(value='Q20641742', prop_nr='P248')\n        ],\n        [\n            Time(time='+2020-02-08T00:00:00Z', prop_nr='P813', precision=WikibaseTimePrecision.DAY),\n            ExternalID(value='1017', prop_nr='P351')\n        ]\n    ]\n\n    # data type object\n    entrez_gene_id = String(value=entrez_id, prop_nr='P351', references=references)\n    ensembl_transcript_id = String(value=ensembl, prop_nr='P704', references=references)\n\n    # data goes into a list, because many data objects can be provided to\n    data = [entrez_gene_id, ensembl_transcript_id]\n\n    # Search for and then edit/create new item\n    wb_item = WikibaseIntegrator(login=login).item.new()\n    wb_item.add_claims(claims=data)\n    wb_item.init_fastrun(base_filter=fast_run_base_filter)\n    wb_item.write()\n```\n\nNote: Fastrun mode checks for equality of property/value pairs, qualifiers (not including qualifier attributes), labels,\naliases and description, but it ignores references by default!\nReferences can be checked in fast run mode by setting `use_refs` to `True`.\n\n# Debugging #\n\nYou can enable debugging by adding this piece of code to the top of your project:\n\n```python\nimport logging\n\nlogging.basicConfig(level=logging.DEBUG)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemyst%2Fwikibaseintegrator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flemyst%2Fwikibaseintegrator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flemyst%2Fwikibaseintegrator/lists"}