Wikidata:Dataåtkomst

This page is a translated version of the page Wikidata:Data access and the translation is 8% complete.
Outdated translations are marked like this.

Wikidata innehåller för närvarande mer än 100 miljoner objekt och 650 000 lexem och dessa siffror växer ständigt. Det finns flera tillgängliga metoder för att komma åt all denna data -- detta dokument beskriver dem och hjälper potentiella användare välja den metod som bäst passar deras behov.

Det är viktigt att välja en åtkomstmetod som snabbast ger dig den data du behöver och på effektivaste möjliga sätt samtidigt som du inte belastar Wikidata i onödan; den här sidan finns här för att hjälpa dig med det.

Innan vi börjar

Använda Wikidatas data

 
Vår logotyp

Wikidata erbjuder ett brett utbud av allmänna data om vårt universum samt länkar till andra databaser. Uppgifterna publiceras under CC0 "Public domain dedication" -licensen. Data kan redigeras av vem som helst och underhålls av Wikidata-gemenskapens redaktörer.

Ändringar av API och dataformat som används för att komma åt Wikidata omfattas av Policy för Stabila gränssnitt. Ändringar i stabila gränssnitt kommer att meddelas i enlighet med detta. Observera att inte alla datakällor som nämns på denna sida betraktas som stabila gränssnitt.

Wikimedia projects

This document is about accessing data from outside Wikimedia projects. If you need to present data from Wikidata in another Wikimedia project, where you can employ parser functions, Lua and/or other internal-only methods, refer to How to use data on Wikimedia projects.

Data best practices

 
Frivilliga som dessa människor - och du - gör Wikidata möjligt

Vi erbjuder datan på Wikidata gratis och och utan krav på attribution under CC-0. I gengäld skulle vi dock verkligen uppskatta om du i ditt projekt anger Wikidata som ursprunget för din data. Detta ser till att Wikidata upprätthålls på lång sikt och kan fortsätta ge dig aktuell och högkvalitativ data. Vi främjar också de bästa projekten som använder data från Wikidata.

Några exempel för att tillskriva Wikidata: "Drivs av Wikidata", "Drivs av Wikidata taggar", "Drivs av Wikidata data", "Drivs av Wikidata magi", "Använder Wikidata data", "Med data från Wikidata", "Data från Wikidata","Källa: Wikidata","Inkluderar data från Wikidata", osv. Du kan också använda en färdig fil från oss.

Du får använda Wikidata-logotypen (se ovan), men inte på något sätt som antyder relation eller godkännande av Wikidata eller Wikimedia Foundation.

Vänligen ge dina användare ett sätt att rapportera problem i data och återkoppla detta till Wikidatas redaktörsgemenskap. Vi arbetar för närvarande med att effektivisera denna process. Fram till dess vänligen använd Bybrunnen.

Access best practices

When accessing Wikidata's data, observe the following best practices:

  • Follow the User-Agent policy – send a good User-Agent header.
  • Follow the robot policy: send Accept-Encoding: gzip,deflate and don’t make too many requests at once.
  • If you get a 429 Too Many Requests response, stop sending further requests for a while (see the Retry-After response header)
  • When available (such as with the Wikidata Query Service), set the lowest timeout that makes sense for your data.
  • When using the MediaWiki Action API, make liberal use of the maxlag parameter and consult the rest of the guidelines laid out in API:Etiquette.

Search

What is it?

Wikidata offers an Elasticsearch index for traditional searches through its data: Special:Search

When to use it?

Use search when you need to look for a text string, or when you know the names of the entities you're looking for but not the exact entities themselves. It's also suitable for cases in which you can specify your search based on some very simple relations in the data.

Don't use search when the relations in your data are better described as complex.

Details

You can make your search more powerful with these additional keywords specific to Wikidata: haswbstatement, inlabel, wbstatementquantity, hasdescription, haslabel. This search functionality is documented on the CirrusSearch extension page. It also has its own API action.

Linked Data Interface (URI)

What is it?

The Linked Data Interface provides access to individual entities via URI: http://www.wikidata.org/entity/Q???

When to use it?

Use the Linked Data Interface when you need to obtain individual, complete entities that are already known to you.

Don't use it when you're not clear on which entities you need – first try searching or querying. It's also not suitable for requesting large quantities of data.

Details

 
Meet Q42

Varje objekt och egenskap har en URI som erhålls genom att bifoga dess ID-nummer (t ex Q42 eller P12) till Wikidata namnrymden:

The namespace for Wikidata's data about entities is https://wikidata.org/wiki/Special:EntityData.

Lägga till en entitets ID till detta prefix skapar den "abstrakta" (formatneutrala) formen av dataadressen till entiteten. När du anropar en Special:EntityData-URL tillämpar specialsidan content negotiation för att bestämma formatet för Wikidata-utdata. Det mest sannolika är att du öppnade webbadressen i en vanlig webbläsare, och en HTML-sida av Wikidatas data om entiteten kommer att visas, eftersom en webbläsare föredrar HTML över andra format. Länkade dataklienter kan få Wikidata data om entiteten i ett annat format som JSON eller RDF, beroende på HTTP $accept-field rubrik för deras begäran.

For example, take this concept URI for Douglas Adams – that's a reference to the real-world person, not to Wikidata's concrete description:
http://www.wikidata.org/entity/Q42
As a human being with eyes and a browser, you will likely want to access data about Douglas Adams by using the concept URI as a URL. Doing so triggers an HTTP redirect and forwards the client to the data URL that contains Wikidata's data about Douglas Adams: https://www.wikidata.org/wiki/Special:EntityData/Q42.

För fall där det är obekvämt att använda innehållsförhandlingar (t.ex. för att visa icke-HTML-innehåll i en webbläsare) kan du också få tillgång till data om en enhet i ett visst format genom att utvidga dataadressen med ett tilläggs suffix för att ange innehållet format som du vill ha, till exempel .json, .rdf, .code, .nt eller .jsonld. Till exempel leder $url1 till en JSON-export för artikel Q42. Specifika revisioner kan erhållas genom att lägga till en revision sökparameter som så $url2.

Less verbose RDF output

By default, the RDF data that the Linked Data interface returns is meant to be complete in itself, so it includes descriptions of other entities it refers to. If you want to exclude that information, you can append the query parameter ?flavor=dump to the URL(s) you request.

By appending &flavor to the URL, you can control exactly what kind of data gets returned.

  • ?flavor=dump: Excludes descriptions of entities referred to in the data.
  • ?flavor=simple: Provides only truthy statements (best-ranked statements without qualifiers or references), along with sitelinks and version information.
  • ?flavor=full (default): An argument of "full" returns all data. (You don't need to specify this because it's the default.)

If you want a deeper insight into exactly what each option entails, you can take a peek into the source code.

Revisions and caching

You can request specific revisions of an entity with the revision query parameter: https://www.wikidata.org/wiki/Special:EntityData/Q42.json?revision=112.

The following URL formats are used by the user interface and by the query service updater, respectively, so if you use one of the same URL formats there’s a good chance you’ll get faster (cached) responses:

Wikidata Query Service

What is it?

The Wikidata Query Service (WDQS) is Wikidata's own SPARQL endpoint. It returns the results of queries made in the SPARQL query language: https://query.wikidata.org

When to use it?

Use WDQS when you know only the characteristics of your desired data.

Don't use WDQS for performing text or fuzzy search – FILTER(REGEX(...)) is an antipattern. (Use search in such cases.)

WDQS is also not suitable when your desired data is likely to be large, a substantial percentage of all Wikidata's data. (Consider using a dump in such cases.)

Details

Du kan ställa datafrågor till data i Wikidata via vår SPARQL-ändpunkt, Wikidata Query Service. Tjänsten kan användas både som ett interaktivt webbgränssnitt, eller programmatiskt genom att skicka GET eller POST-förfrågningar till https://query.wikidata.org/sparql. RDF-data kan alternativt kommas åt via ett gränssnitt för länkade datafragment [1] vid https://query.wikidata.org/bigdata/ldf. Se användarhandboken och lokala gemenskapssidor för mer information.

The query service is best used when your intended result set is scoped narrowly, i.e., when you have a query you're pretty sure already specifies your resulting data set accurately. If your idea of the result set is less well defined, then the kind of work you'll be doing against the query service will more resemble a search; frequently you'll first need to do this kind of search-related work to sharpen up your query. See the Search section.

Linked Data Fragments endpoint

What is it?

The Linked Data Fragments (LDF) endpoint is a more experimental method of accessing Wikidata's data by specifying patterns in triples: https://query.wikidata.org/bigdata/ldf. Computation occurs primarily on the client side.

When to use it?

Use the LDF endpoint when you can define the data you're looking for using triple patterns, and when your result set is likely to be fairly large. The endpoint is good to use when you have significant computational power at your disposal.

Since it's experimental, don't use the LDF endpoint if you need an absolutely stable endpoint or a rigorously complete result set. And as mentioned before, only use it if you have sufficient computational power, as the LDF endpoint offloads computation to the client side.

Details

If you have partial information about what you're looking for, such as when you have two out of three components of your triple(s), you may find what you're looking for by using the Linked Data Fragments interface at https://query.wikidata.org/bigdata/ldf. See the user manual and community pages for more information.

Wikibase REST API

What is it?

The Wikibase REST API is an OpenAPI-based interface that allows users to interact with, retrieve and edit items and statements on Wikibase instances – including of course Wikidata: Wikidata REST API

When to use it?

The Wikibase REST API is still under development, but for Wikidata it's intended to functionally replace the Action API as it's a dedicated interface made just for Wikibase/Wikidata.

The use cases for the Action API apply to the Wikibase REST API as well. Use it when your work involves:

  • Editing Wikidata
  • Getting direct data about entities themselves

Don't use the Wikibase REST API when your result set is likely to be large. (Consider using a dump in such cases.)

It's better not to use the Wikibase REST API when you'll need to further narrow the result of your API request. In such cases it's better to frame your work as a search (for Elasticsearch) or a query (for WDQS).

Details

The Wikibase REST API has OpenAPI documentation using Swagger. You can also review the developer documentation.

MediaWiki Action API

What is it?

The Wikidata API is MediaWiki's own Action API, extended to include some Wikibase-specific actions: https://wikidata.org/w/api.php

When to use it?

Use the API when your work involves:

  • Editing Wikidata
  • Getting data about entities themselves such as their revision history
  • Getting all of the data of an entity in JSON format, in small groups of entities (up to 50 entities per request).

Don't use the API when your result set is likely to be large. (Consider using a dump in such cases.)

The API is also poorly suited to situations in which you want to request the current state of entities in JSON. (For such cases consider using the Linked Data Interface, which is likelier to provide faster responses.)

Finally, it's probably a bad idea to use the API when you'll need to further narrow the result of your API request. In such cases it's better to frame your work as a search (for Elasticsearch) or a query (for WDQS).

Details

The MediaWiki Action API used for Wikidata is meticulously documented on Wikidata's API page. You can explore and experiment with it using the API Sandbox.

Bots

 
Vi välkomnar bottar som uppför sig väl.

Du kan också komma åt API:n med hjälp av en bot. Se Wikidata:Bots för mer om bottar.

Recent Changes stream

What is it?

[[https://stream.wikimedia.org|Wikimedias hädelseström för senaste ändringarna]] kan användas för att se ändringar av entiteter i realtid. API:n för senaste ändringarna finns också tillgänglig men rekommenderas inte för nya verktyg då den inte publicerar själva ändringarna och åsamkar mer belastning på servrarna då varje entitet måste låsas var för sig.

When to use it?

Use the Recent Changes stream when your project requires you to react to changes in real time or when you need all the latest changes coming from Wikidata – for example, when running your own query service.

Details

The Recent Changes stream contains all updates from all wikis using the server-sent events protocol. You'll need to filter Wikidata's updates out on the client side.

You can find the web interface at stream.wikimedia.org and read all about it on the EventStreams page.

Dumps

What are they?

Wikidata dumps are complete exports of all the Entities in Wikidata: https://dumps.wikimedia.org

When to use them?

Use a dump when your result set is likely to be very large. You'll also find a dump important when setting up your own query service.

Don't use a dump if you need current data: the dumps take a very long time to export and even longer to sync to your own query service. Dumps are also unsuitable when you have significant limits on your available bandwidth, storage space and/or computing power.

Details

If the records you need to traverse are many, or if your result set is likely to be very large, it's time to consider working with a database dump: (link to the latest complete dump).

You'll find detailed documentation about all Wikimedia dumps on the "Data dumps" page on Meta and about Wikidata dumps in particular on the database download page. See also Flavored dumps above.

Tools

  • JsonDumpReader is a PHP library for reading dumps.
  • At [2] you'll find a Go library for processing Wikipedia and Wikidata dumps.
  • You can use wdumper to get partial custom RDF dumps.

Local query service

It's no small task to procure a Wikidata dump and implement the above tools for working with it, but you can take a further step. If you have the capacity and resources to do so, you can host your own instance of the Wikidata Query Service and query it as much as you like, out of contention with any others.

To set up your own query service, follow these instructions from the query service team, which include procuring your own local copy of the data. You may also find useful information in Adam Shorland's blog post on the topic.