A TypeScript library that simplifies working with Wikidata through an intuitive object-oriented interface. Wikidata is a free knowledge base that anyone can edit, serving as a central storage for structured data used by Wikipedia and other Wikimedia projects.
npm i --save iwf
You can easily request an item from Wikidata and list all the labels. For example, Q42 represents Douglas Adams in Wikidata:
import { requestItem } from 'iwf';
// Request the item for Douglas Adams (Q42)
const item = await requestItem('Q42');
// Prints all available labels in different languages
console.log(item.labels);
Create a new item and upload it to Wikidata. This example creates a new astronomical object:
import { Item, getToken, upload, Label, Statement, WikibaseItemSnak } from 'iwf';
const item = Item.fromNothing();
// Add an English label
item.labels.push(Label.fromString('en', 'new planet'));
// Add a statement: instance of (P31) celestial body (Q634)
item.statements.push(Statement.fromSnak(WikibaseItemSnak.fromID('P31', 'Q634')));
// Authenticate and upload
const token = await getToken('your Wikidata username', 'your Wikidata password');
await upload(item, {
summary: 'Adding new astronomical object',
authToken: token
});
The library supports both authenticated and anonymous operations. For editing operations, you'll need a Wikidata account. Anonymous operations are limited to reading data.
To see all the functionality, extra documentation, and examples, visit the documentation.
You are already helping by using this library, but if you want to do more, there are a few things you can do:
There is a FUTURE.md file that contains ideas for future development. If you want to help, you can look there for ideas.