Jump to content

Wikidata:Accesso ai dati

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

Wikidata per gli sviluppatori: Accesso ai dati




Wikidata attualmente contiene oltre 110 milioni di Elementi e oltre 1,3 milioni di Lessemi, e questi numeri continueranno a crescere. Esistono molti metodi per accedere a tutti questi dati: questo documento li presenta e aiuta gli utenti potenziali a scegliere il metodo migliore per soddisfare le loro esigenze.

È fondamentale scegliere un metodo di accesso che fornisca i dati necessari nel modo più veloce ed efficiente senza caricare inutilmente Wikidata; questa pagina è pensata per aiutare a farlo.

Prima di iniziare

Utilizzare i dati di Wikidata

Il nostro logo

Wikidata offre un ampia gamma di dati su tutto ciò che esiste. Tutti i dati sono fruibili con la licenza CC0, "Nessun diritto riservato", per il dominio pubblico.

Cambiamenti alle API e agli altri metodi per accedere a Wikidata sono soggetti alla Politica sulla stabilità dell'interfaccia. Le sorgenti dati menzionate in questa pagina non sono tutte garantite come interfacce stabili.

Progetti Wikimedia

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.

Buone norme sui dati

I volontari, come queste persone - e te - fanno Wikidata

We offer the data in Wikidata freely and with no requirement for attribution under CC-0. In return, we would greatly appreciate it if, in your project, you mention Wikidata as the origin of your data. In so doing you help ensure that Wikidata will stay around for a long time to provide up-to-date and high-quality data. We also promote the best projects that use Wikidata's data.

Some examples for attributing Wikidata: "Powered by Wikidata", "Powered by Wikidata data", "Powered by the magic of Wikidata", "Using Wikidata data", "With data from Wikidata", "Data from Wikidata", "Source: Wikidata", "Including data from Wikidata" and so forth. You can also use one of our ready-made files.

Puoi usare il logo di Wikidata mostrato sopra, ma facendolo non dovresti in alcun modo far intendere un sostegno da parte di Wikidata o dalla Wikimedia Foundation.

Per favore, offri ai tuoi utenti un modo per segnalare problemi nei dati, e trova il modo per segnalarli alla comunità di editori di Wikidata, per esempio con il Mismatch Finder. Per favore condividi il posto dove segnali i problemi nel bar del progetto.

Buone norme sull'accesso

Quando si accede ai dati di Wikidata, si devono osservare le seguenti buone norme:

  • Segui la politica User-Agent - invia un header User-Agent corretto.
  • Segui la politica per robot: manda Accept-Encoding: gzip,deflate e non fare troppe richieste alla volta.
  • Se ricevi una risposta 429 Too Many Requests, non inviare ulteriori richieste per un po' (vedere l'header di risposta Retry-After)
  • Quando è possibile (come fa anche il servizio di query di Wikidata), imposta il timeout minimo che abbia senso per i dati.
  • 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.


Ricerca

Che cos'è?

Wikidata offre un indice Elasticsearch per le ricerche tradizionali attraverso i suoi dati: Special:Search

Quando usarlo?

Usa la ricerca quando devi cercare una stringa di testo o quando conosci i nomi delle entità che stai cercando, ma non le entità esatte. È anche adatta ai casi in cui è possibile specificare la ricerca in base ad alcune relazioni molto semplici nei dati.

Non usare la ricerca quando le relazioni nei tuoi dati sono meglio descritte come complesse.

Dettagli

È possibile rendere la ricerca ancora più potente con queste parole chiave aggiuntive specifiche di Wikidata: haswbstatement, inlabel, wbstatementquantity, hasdescription, haslabel. Questa funzionalità di ricerca è documentata nella pagina dell'estensione CirrusSearch. Ha anche una propria API.

Interfaccia dati collegati (URI)

Che cos'è?

L'interfaccia dati collegati fornisce l'accesso a singole entità tramite URI: http://www.wikidata.org/entity/Q???. Tali URI sono chiamati URI concettuali. Nota che gli URI concettuali usano HTTP, non HTTPS.

Quando usarla?

Utilizza l'interfaccia dati collegati quando desideri ottenere entità individuali e complete già conosciute.

Non usarla quando non hai chiaro quali entità ti servono: prima prova a cercare o a fare query. Non è adatto anche per richiedere grandi quantità di dati.

Dettagli

Scopri Q42

Ogni Elemento o Proprietà possiede un URI persistente costituito dal namespace dei concetti Wikidata e da un ID elemento o proprietà (es., Q42, P31) ma anche dati concreti che possono essere acceduti dall'URL dell'Elemento o della Proprietà.

Il namespace Wikidata per i dati sulle entità è https://wikidata.org/wiki/Special:EntityData.

Aggiungendo l'ID di un'entità a questo prefisso si crea la forma "astratta" (formato neutrale) dell'URL dei dati dell'entità. Quando fai la richiesta di un URL con Special:EntityData, la pagina speciale applica la negoziazione del contenuto per determinare il formato dell'output di Wikidata. Molto probabilmente hai aperto l'URL in un normale browser e una pagina HTML dei dati di Wikidata sull'entità si è aperta, poiché un browser preferisce l'HTML ad altri formati. I client di linked data riceverebbero i dati di Wikidata sull'entità in un differente formato, come JSON o RDF, a seconda dell'header HTTP Accept: della richiesta.

Per esempio, prendiamo questo URI concettuale su Douglas Adams – è un riferimento alla persona nel mondo reale, non alla descrizione concreta su Wikidata:
http://www.wikidata.org/entity/Q42
Come essere umano dotato di occhi e di un browser, è probabile che si voglia accedere ai dati su Douglas Adams usando l'URI concettuale come URL. In questo modo, avviene un reindirizzamento HTTP e si inoltra il client all'URL concreto che contiene i dati di Wikidata riguardanti Douglas Adams: https://www.wikidata.org/wiki/Special:EntityData/Q42.

Quando è necessario bypassare la negoziazione dei contenuti, ad esempio per visualizzare contenuti non HTML in un browser web, puoi specificare il formato dei dati dell'entità aggiungendo l'estensione corrispondente all'URL dei dati; come per esempio .json, .rdf, .ttl, .nt o .jsonld. Ad esempio, https://www.wikidata.org/wiki/Special:EntityData/Q42.json fornisce l'elemento Q42 in formato JSON.

Output RDF meno verboso

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.

Aggiungendo &flavor= all'URL, è possibile controllare esattamente il tipo di dati restituiti.

  • ?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.

Revisioni e cache

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:

Servizio di query Wikidata

Che cos'è?

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

Quando usarlo?

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.)

Dettagli

You can query the data in Wikidata through our SPARQL endpoint, the Wikidata Query Service. The service can be used both as an interactive web interface, or programmatically by submitting GET or POST requests to https://query.wikidata.org/sparql.

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.

The query service at query.wikidata.org only contains the main graph of Wikidata. The Items related to scholarly articles are in a separate query service at query-scholarly.wikidata.org. For more details see Wikidata:SPARQL query service/WDQS graph split.

Linked Data Fragments endpoint

Che cos'è?

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.

Quando usarlo?

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.

Dettagli

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.

API REST di Wikibase

Che cos'è?

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

Quando usarla?

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:

  • Modificare 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).

Dettagli

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

MediaWiki Action API

Che cos'è?

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

Quando usarlo?

Use the API when your work involves:

  • Modificare 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).

Dettagli

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.

There are multiple Wikibase specific endpoints. Here is an example request:

Bot

I bot che si comportano bene sono benvenuti

Puoi anche accedere alle API usando un bot. Per saperne di più sui bot, vedi Wikidata:Bots.

Flusso di cambi recenti

Che cos'è?

Il flusso delle Modifiche recenti fornisce uno strem continuo di modifiche da tutti i wiki di Wikimedia, compreso Wikidata: https://stream.wikimedia.org

Quando usarlo?

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.

Dettagli

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.

Wikidata Vector Database

What it is?

The Wikidata Vector Database stores high-dimensional vector representations of Wikidata entities. It enables semantic search based on meaning and context rather than keyword matching, and supports natural-language queries against entities.

When to use it?

Use vector search for exploration purposes, for example, when you want to uncover entities without explicitly knowing their labels, or when you need to narrow a search down to a smaller, more relevant subgraph of Wikidata as a starting point for further research before moving on to more structured tools.

The vector database can also be used in AI/ML pipelines, such as enabling semantic search in RAG workflows or applying vector distances to tasks like classification and other types of analysis.

Details

You can find more information on the Wikidata Vector Database page. The Wikidata Vector Database is available at wd-vectordb.wmcloud.org, and the API documentation can be found at wd-vectordb.wmcloud.org/docs.


Wikidata MCP

Main page: Wikidata:MCP

What it is?

The Wikidata MCP (Model Context Protocol) provides a set of standardized tools that allow large language models (LLMs) to explore and query Wikidata programmatically. It is designed for agentic AI or AI workflows that need to search, inspect, and query Wikidata, without relying on hardcoded assumptions about its structure or content.

When to use it?

Use the Wikidata MCP when you want to integrate Wikidata directly into a GenAI model or into AI/ML workflows. The MCP provides a set of tools for exploring and accessing Wikidata, but it is limited to read-only use and does not include editing functionality.

Details

The Wikidata MCP is implemented as an HTTP service available at wd-mcp.wmcloud.org. To use it, add https://wd-mcp.wmcloud.org/mcp/ as a connector in your AI client.

Dump

Che cosa sono?

I dump di Wikidata sono esportazioni complete di tutte le Entità di Wikidata: https://dumps.wikimedia.org

Quando usarli?

Utilizza un dump quando il tuo set di risultati è probabilmente molto grande. Troverai importanti i dump quando devi creare un tuo servizio di query.

Non utilizzare un dump se hai bisogno di dati aggiornati: i dump richiedono molto tempo per l'esportazione e ancor di più per sincronizzarsi con il proprio servizio di query. I dump sono anche inadatti quando si dispone di limiti significativi sulla larghezza di banda, sullo spazio di archiviazione e/o sulla potenza di calcolo.

Dettagli

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.

Strumenti

Servizio di query locale

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.