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
Built Distribution
Hashes for batch_ingestion_client_py-1.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a64cfdec109175f9a56726e331d7d10ff199a94529ac50fe5efd6dd469dd5e1 |
|
MD5 | 76d2ca0ca246c55b2cb1cefe56ca0496 |
|
BLAKE2b-256 | 5561547a26055ee7ee4c77067ec445bc2e8976a0df0cfc3a8914f615c9b3b0f4 |
Hashes for batch_ingestion_client_py-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6499ec57adb91b840c71c47b63e4e429e7105f0f815eff761e7ee3496ed4d9ac |
|
MD5 | f494c301df505ac352b25c6a7b7b8f15 |
|
BLAKE2b-256 | 712d3fe98b78945c7db9a9c9fed0a130abc3bb43a286b2e9336c91bcd9801a8e |