Skip to main content

enabling users to perform a variety of operations such as searching entities, retrieving claims, performing SPARQL queries, and even visualizing knowledge graphs.

Project description

WikidataPy

WikidataPy is a Python library designed for seamless interaction with Wikidata's knowledgebase, enabling users to perform a variety of operations such as searching entities, retrieving claims, performing SPARQL queries, and even visualizing knowledge graphs.


Features

  • Entity Search and Retrieval: Search for entities using labels, descriptions, or aliases.
  • Read and Write Operations:
    • Retrieve claims and other entity details.
    • Add or edit claims and entities.
    • Perform bulk operations using CSV files.
  • SPARQL Query Execution: Execute custom SPARQL queries for advanced data retrieval.
  • Knowledge Graph Visualization: Visualize the relationships between entities and their properties.
  • Test Environment Support: Perform operations on test.wikidata.org to avoid affecting production data.

Installation

pip install WikiDataPy

Usage

for Usage refer to usage scripts in github repository
each method has docstring writter for ease of understanding parameters, accepted CSV format and other things

There are 4 modules and classes in which functionality is divided and some methods provided are

  1. WikiReader: searchEntities , getEntitiesByIds , getClaims , getEntitiesRelatedToGiven

  2. WikiWriter: (Requires wikidata account's username, password )

    • methods: login , getCSRFtoken , logout, addClaim, removeClaims, createOrEditEntity, delete_entity(admins,moderators), setLabel, setDescription, setAliases, addRemoveAliases

      usage

      • create object : w = WikiWriter(your_username,your_password)
      • login : w.login()
      • get token: w.getCSRFtoken()
      • perform operations : w.getClaims(), w.createOrEditEntity() etc
      • logout : w.logout()
  3. BulkWriter: (Requires wikidata account's username, password )

    • methods and accepted CSV format with / without header:

      • addClaimsFromCSV : <entity_id, property_id, value_id>
      • addClaimsFromNamesCSV : <entity_name, property_id, value_name>
      • createEntitiesFromCSV : <language_code_1,label_1,description_1,alias1,language_code2,label_2,description2,alias2,...>
      • editEntitiesFromCSV : <entity_id,language_code,label,description,aliases>

      usage

      • create object : w = BulkWriter(your_username,your_password)
      • login : w.login()
      • get token: w.getCSRFtoken()
      • perform operations : w.addClaimsFromNamesCSV(), w.createEntitiesFromCSV() etc
      • logout : w.logout()
  4. WikiGraph: buildGraph , plotGraph (with IDs), plotNamedGraph (with names )

    • usage
      • create object : w = WikiGraph("Q42") or WikiGraph("Ronaldo")
      • call w.buildGraph(radius,out_degree) : default are (3,3)
      • call w.plotGraph() or w.plotNamedGraph() with save file name optionally
  5. WikiSparql: Execute custom SPARQL queries for advanced data retrieval.

    • methods
      • execute(query) : execute single query
      • execute_many(source_text,...) : execute many queries from a text file that are delimited (default "---")
      • find_entities_by_property(pname,ename) : Fetches entities based on a specified property and entity type.

Contributing

Contributions are welcome! Feel free to submit issues or pull requests for new features or bug fixes.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wikidatapy-0.0.1.tar.gz (19.1 kB view details)

Uploaded Source

File details

Details for the file wikidatapy-0.0.1.tar.gz.

File metadata

  • Download URL: wikidatapy-0.0.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for wikidatapy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 2dafae59c5d8ca395a2f8011236f04817892ebb24efb8a0540d7878e934cc7b5
MD5 dd71c39682cb8601794947e8d4a77dff
BLAKE2b-256 a5459bf43b8d778d06a5139dd781bc704067acacaa0fd8452b68c0294f11fe9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page