Run SQL queries against Wikidata by translating them to SPARQL
Project description
Wikidata-SQL
Run SQL queries against Wikidata. Instead of writing SPARQL, write familiar SQL using Wikidata Q-IDs as table names.
Install
pip install WikiSQL
Quick Start
wikisql # interactive REPL
wikisql "SELECT * FROM Q845945 LIMIT 10" # single query
wikisql --sparql "SELECT * FROM Q845945 LIMIT 10" # show generated SPARQL
wikisql -l ja "SELECT * FROM Q845945 LIMIT 10" # Japanese labels
How It Works
A Q-ID in the FROM clause creates a virtual table of all entities with that class:
-- All Shinto shrines (instances of Q845945)
SELECT * FROM Q845945 LIMIT 10;
-- Subclasses of Shinto shrine (P279 instead of default P31)
SELECT * FROM P279:Q845945 LIMIT 10;
Selecting Properties
Use Wikidata property IDs as column names. By default, values show human-readable labels:
-- Show country and population of cities
SELECT item, P17, P1082 FROM Q515 LIMIT 5;
| item | P17 | P1082 |
|---|---|---|
| Vianen | Netherlands | 19967 |
| Mysore | India | |
| Belfast | United Kingdom | 345006 |
Append _qid to get the raw Wikidata entity ID instead:
SELECT P17, P17_qid FROM Q515 LIMIT 3;
| P17 | P17_qid |
|---|---|
| United States | Q30 |
| Switzerland | Q39 |
WHERE Filtering
Filter by label (human-readable name):
SELECT item, P17 FROM Q515 WHERE P17 = 'France' LIMIT 5;
Filter by QID (entity ID):
SELECT item, P17 FROM Q515 WHERE P17_qid = 'Q142' LIMIT 5;
JOINs
Join two virtual tables on a shared property:
SELECT * FROM Q845945 s JOIN Q5 p ON s.P17 = p.P27 LIMIT 5;
Column Reference
| Column | Shows | Example output |
|---|---|---|
* |
Entity QID + label | Q60, New York City |
item |
Entity label | New York City |
item_qid |
Entity QID | Q60 |
P17 |
Property value label | Japan |
P17_qid |
Property value QID | Q17 |
REPL Commands
\sparql- Toggle SPARQL display on/off\q/quit/exit- Exit
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wikisql-0.2.0.tar.gz.
File metadata
- Download URL: wikisql-0.2.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2b65887bde03b43af3e67fc73958d7abed67ee71324eca09d2f846780560432
|
|
| MD5 |
c2f199f51248a353f136796b98903bda
|
|
| BLAKE2b-256 |
8132e358ddc3cc50f4190d4f38d0b6f7a7df07b75d35a0b4344aece17fbfb8fd
|
Provenance
The following attestation bundles were made for wikisql-0.2.0.tar.gz:
Publisher:
workflow.yml on Emma-Leonhart/WikiSQL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wikisql-0.2.0.tar.gz -
Subject digest:
c2b65887bde03b43af3e67fc73958d7abed67ee71324eca09d2f846780560432 - Sigstore transparency entry: 1004829122
- Sigstore integration time:
-
Permalink:
Emma-Leonhart/WikiSQL@712902cf85393dfc0970a6efb1fdc3cb81c3b052 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Emma-Leonhart
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@712902cf85393dfc0970a6efb1fdc3cb81c3b052 -
Trigger Event:
release
-
Statement type:
File details
Details for the file wikisql-0.2.0-py3-none-any.whl.
File metadata
- Download URL: wikisql-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b94d4d8119fcb103a62d6612e2989967c62b8794809f34ec4958acbc04810b70
|
|
| MD5 |
6cf5856e1cd5c1ec3485458272ec79f2
|
|
| BLAKE2b-256 |
488cac95b945c4e4d40d98799f1dbae2fa2d0ff5b2492ce166191bf709d95a1c
|
Provenance
The following attestation bundles were made for wikisql-0.2.0-py3-none-any.whl:
Publisher:
workflow.yml on Emma-Leonhart/WikiSQL
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
wikisql-0.2.0-py3-none-any.whl -
Subject digest:
b94d4d8119fcb103a62d6612e2989967c62b8794809f34ec4958acbc04810b70 - Sigstore transparency entry: 1004829123
- Sigstore integration time:
-
Permalink:
Emma-Leonhart/WikiSQL@712902cf85393dfc0970a6efb1fdc3cb81c3b052 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Emma-Leonhart
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@712902cf85393dfc0970a6efb1fdc3cb81c3b052 -
Trigger Event:
release
-
Statement type: