Skip to main content

A client for the BatchIngestion mediawiki API

Project description

BatchIngestion Python Client

This is a Python client library for the BatchIngestion MediaWiki extension, which provides an API to ingest many entities at once. This library allows you to easily ingest entities in bulk, either by parsing them from JSON or by creating them using Python objects.

Installation

You can install this library using pip:

pip install batch-ingestion-client

Usage

You first need to instantiate a BatchIngestor object, passing in the URL of the MediaWiki instance you want to use:

ingestor = BatchIngestor("http://default.mediawiki.mwdd.localhost:8080")

You can then use the ingest() method to ingest entities:

response = ingestor.ingest(entities)
print(response)

How to define data to ingest

Example with parsing

You can use the Data.parse() method to parse entities from a JSON string:

data = Data.parse({
    "key": "<your-api-key>",
    "entities": [
        {
            "id": "Q22",
            "mode": "add",
            "type": "item",
            "labels": {
                "en": {
                    "language": "en",
                    "value": "some new name",
                },
            },
            "claims": {
                "P1": [
                    {
                        "mainsnak": {
                            "snaktype": "value",
                            "property": "P1",
                            "datatype": "external-id",
                            "datavalue": {
                                "value": "some claim value",
                                "type": "string",
                            },
                        },
                        "type": "statement",
                        "rank": "normal",
                    },
                ],
            },
            "descriptions": {
                "en": {
                    "language": "en",
                    "value": "some description",
                },
            },
        },
    ],
})

Example using Python objects

Alternatively, you can create entities using Python objects:

data = Data(
    key="<your-api-key>",
    entities=[
        Entity(
            id="Q22",
            mode="add",
            type="item",
            labels={
                "en": ValueInLanguage(
                    language="en",
                    value="some new name",
                ),
            },
            claims={
                "P1": [
                    Claim(
                        mainsnak=MainSnak(
                            snaktype="value",
                            property="P1",
                            datatype="external-id",
                            datavalue=DataValue(
                                value="some claim value",
                                type="string",
                            ),
                        ),
                        type="statement",
                        rank="normal",
                    ),
                ],
            },
            descriptions={
                "en": ValueInLanguage(
                    language="en",
                    value="some description",
                ),
            },
        ),
    ],
)

Contributing

If you'd like to contribute to this library, please feel free to submit a pull request.

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

batch_ingestion_client_py-1.0.1.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

batch_ingestion_client_py-1.0.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

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