Giter Club home page Giter Club logo

wikibase-api's Introduction

wikibase-api

wikibase-api is a Python library for simple access to the Wikibase API.

It simplifies the authentication process and can be used to query and edit information on Wikidata or any other Wikibase instance.

For a simpler, object-oriented abstraction of the Wikibase API, have a look at python-wikibase.

Installation

pip install wikibase-api

Usage

Simple example for fetching all information about a Wikidata page:

from wikibase_api import Wikibase

wb = Wikibase()
r = wb.entity.get("Q1")
print(r)

Output:

{
  "entities": {
    "Q1": {
      # ...
    }
  },
  "success": 1,
}

See the documentation for descriptions and examples of all commands.

Development

Contributing

Suggestions and contributions are always welcome! Please discuss larger changes via issue before submitting a pull request.

Setup

See this guide on how to set up a development environment for this package.

Related

wikibase-api's People

Contributors

samuelmeuli avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

wikibase-api's Issues

Sitelink support

Functions could be added that allow users to create/update/remove sitelinks. See the API docs for details.

Changed snak dictionary variable in reference.py file

In order to get the reference.py file to work with my claim reference, I changed the snak dictionary on line 82 from:

` snak = {property_id: [{"snaktype": snak_type, "property": property_id, "datavalue": value}]}

to

snak = {property_id: [{"snaktype": snak_type, "property": property_id,"datavalue":{"type":"string","value": value}}]}

Impossible to create new property

It seems that it is not possible to create a new property...
I tried:

wb.entity.add(entity_type="property")

But got this error:

ApiError: {"code": "param-illegal", "info": "A datatype was expected, but either missing or not recognized.", "messages": [{"name": "wikibase-api-not-recognized-datatype", "parameters": [], "html": {"": "A datatype was expected, but either missing or not recognized."}}], "": "See http://localhost:8466/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes."}

Claim object has no attribute 'get'

It seems not yet implemented although it is used as example in the documentation. This code below should fix it

    def get(self, entity_id, property_id=None, rank=None):
        """Get claims for the specified entity

        :param entity_id: Entity identifier (e.g. ``"Q1"``)
        :type entity_id: str
        :param property_id: Property identifier (e.g. ``"P1"``)
        :type property_id: str
        :param rank: Optional filter to return only the claims that have the specified rank
            (one of ``["deprecated", "normal", "preferred"]``)
        :type rank: str
        :return: Response
        :rtype: dict
        """
        params = {
            "action": "wbgetclaims",
            "entity": entity_id,
        }
        if property_id is not None: params['property'] = property_id
        if rank is not None: params['rank'] = rank
        return self.api.get(params)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.