PHPackages                             menoci/wikidata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. menoci/wikidata

ActiveLibrary[API Development](/categories/api)

menoci/wikidata
===============

A PHP client for working with Wikidata API.

1.0(2y ago)0517MITPHP

Since May 14Pushed 1mo agoCompare

[ Source](https://github.com/menociGoettingen/wikidata)[ Packagist](https://packagist.org/packages/menoci/wikidata)[ Docs](https://github.com/menociGoettingen/wikidata)[ Fund](https://www.buymeacoffee.com/arhey)[ Fund](https://www.paypal.me/arhey)[ RSS](/packages/menoci-wikidata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

[![wikidata](https://raw.githubusercontent.com/maxlath/wikidata-cli/master/assets/wikidata_logo_alone.jpg)](https://wikidata.org)

Wikidata [![Build Status](https://camo.githubusercontent.com/7c420fb596222e3e75f5c2ae763571657e1743420709cb163a66921a46a08835/68747470733a2f2f7472617669732d63692e6f72672f6672656561726865792f77696b69646174612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/freearhey/wikidata)
==============================================================================================================================================================================================================================================================================================

[](#wikidata-)

Wikidata provides a API for searching and retrieving data from [wikidata.org](https://www.wikidata.org).

Installation
------------

[](#installation)

```
composer require menoci/wikidata
```

Usage
-----

[](#usage)

First we need to create an instance of `Wikidata` class and save it to some variable, like this:

```
require_once('vendor/autoload.php');

use Wikidata\Wikidata;

$wikidata = new Wikidata();
```

after that we can use one of the available methods to access the Wikidata database.

Available Methods
-----------------

[](#available-methods)

### `search()`

[](#search)

The `search()` method give you a way to find Wikidata entity by it label.

```
$results = $wikidata->search($query, $lang, $limit);
```

Arguments:

- `$query`: term to search (required)
- `$lang`: specify the results language (default: 'en')
- `$limit`: set a custom limit (default: 10)

Example:

```
$results = $wikidata->search('car', 'fr', 5);

/*
  Collection {
    #items: array:5 [
      0 => SearchResult {
        id: "Q1759802"
        lang: "fr"
        label: "autocar"
        wiki_url: "https://fr.wikipedia.org/wiki/autocar"
        description: "transport routier pouvant accueillir plusieurs voyageurs pour de longues distances"
        aliases: array:1 [
          0 => "car"
        ]
      }
      1 => SearchResult {
        id: "Q224743"
        lang: "fr"
        label: "Car"
        wiki_url: "https://fr.wikipedia.org/wiki/Car"
        description: "page d'homonymie d'un projet Wikimédia"
        aliases: []
      }
      ...
    ]
  }
*/
```

The `search()` method always returns `Illuminate\Support\Collection` class with results. This means you can use all the [methods available](https://laravel.com/docs/5.6/collections#available-methods) in Laravel's Collections.

### `searchBy()`

[](#searchby)

The `searchBy` help you to find Wikidata entities by it properties value.

```
$results = $wikidata->searchBy($propId, $entityId, $lang, $limit);
```

Arguments:

- `$propId`: id of the property by which to search (required)
- `$entityId`: id of the entity (required)
- `$lang`: specify the results language (default: 'en')
- `$limit`: set a custom limit (default: 10)

Example:

```
// List of people who born in city Pomona, US
$results = $wikidata->searchBy('P19', 'Q486868');

/*
  Collection {
    #items: array:10 [
      0 => SearchResult {
        id: "Q92638"
        lang: "en"
        label: "Robert Tarjan"
        wiki_url: "https://en.wikipedia.org/wiki/Robert_Tarjan"
        description: "American computer scientist"
        aliases: array:2 [
          0 => "Robert E. Tarjan"
          1 => "Robert Endre Tarjan"
        ]
      }
      1 => SearchResult {
        id: "Q184805"
        lang: "en"
        label: "Tom Waits"
        wiki_url: "https://en.wikipedia.org/wiki/Tom_Waits"
        description: "American singer-songwriter and actor"
        aliases: []
      }
      ...
    ]
  }
*/
```

The `searchBy()` method always returns `Illuminate\Support\Collection` class with results. This means you can use all the [methods available](https://laravel.com/docs/5.6/collections#available-methods) in Laravel's Collections.

### `get()`

[](#get)

The `get()` returns Wikidata entity by specified ID.

```
$entity = $wikidata->get($entityId, $lang);
```

Arguments:

- `$entityId`: id of the entity (required)
- `$lang`: specify the results language (default: 'en')

Example:

```
// Get all data about Steve Jobs
$entity = $wikidata->get('Q19837');

/*
  Entity {
    id: "Q19837"
    lang: "en"
    label: "Steve Jobs"
    wiki_url: "https://en.wikipedia.org/wiki/Steve_Jobs"
    aliases: array:2 [
      0 => "Steven Jobs",
      1 => "Steven Paul Jobs"
    ]
    description: "American entrepreneur and co-founder of Apple Inc."
    properties: Collection { ... }
  }
*/

// List of all properties as an array
$properties = $entity->properties->toArray();

/*
  [
    "P1006" => Property {
      id: "P1006"
      label: "NTA ID"
      values: Collection {
        #items: array:6 [
          0 => Value {
            id: "Q5593916"
            label: "Grammy Trustees Award"
            qualifiers: Collection {
              #items: array:1 [
                0 => Qualifier {
                  id: "P585"
                  label: "point in time"
                  value: "2012-01-01T00:00:00Z"
                }
              ]
            }
          },
          ...
        ]
      }
    },
    ...
  ]
 */
```

### Upgrade Guide

[](#upgrade-guide)

#### Upgrade to 3.2.\_ from 3.1.\_

[](#upgrade-to-32_-from-31_)

The main changes in the new version have occurred in the way property values are stored. Now each property can have more than one value. In this regard, the attribute `value` in the `Property` object was replaced with the attribute `values`.

Also, values are now presented not as a string, but as an `Value` object. This allowed us to save along with each value not only its string representation but also a list of its `qualifiers`. Detailed information on what `qualifiers` is can be found [here](https://www.wikidata.org/wiki/Help:Qualifiers).

### Testing

[](#testing)

```
vendor/bin/phpunit
```

### Contribution

[](#contribution)

If you find a bug or want to contribute to the code or documentation, you can help by submitting an [issue](https://github.com/freearhey/wikidata/issues) or a [pull request](https://github.com/freearhey/wikidata/pulls).

### License

[](#license)

Wikidata is licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance59

Moderate activity, may be stable

Popularity16

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

732d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/141842851?v=4)[menoci](/maintainers/menoci)[@Menoci](https://github.com/Menoci)

---

Top Contributors

[![freearhey](https://avatars.githubusercontent.com/u/7253922?v=4)](https://github.com/freearhey "freearhey (127 commits)")[![GenieTim](https://avatars.githubusercontent.com/u/8596965?v=4)](https://github.com/GenieTim "GenieTim (4 commits)")[![pat-o](https://avatars.githubusercontent.com/u/6193393?v=4)](https://github.com/pat-o "pat-o (4 commits)")[![Tes5e](https://avatars.githubusercontent.com/u/52450660?v=4)](https://github.com/Tes5e "Tes5e (3 commits)")[![jeremytubbs](https://avatars.githubusercontent.com/u/548888?v=4)](https://github.com/jeremytubbs "jeremytubbs (3 commits)")[![mpipet](https://avatars.githubusercontent.com/u/8471706?v=4)](https://github.com/mpipet "mpipet (2 commits)")[![MrKrisKrisu](https://avatars.githubusercontent.com/u/4103693?v=4)](https://github.com/MrKrisKrisu "MrKrisKrisu (2 commits)")[![andrei-i-gavrila](https://avatars.githubusercontent.com/u/3754526?v=4)](https://github.com/andrei-i-gavrila "andrei-i-gavrila (1 commits)")[![menociGoettingen](https://avatars.githubusercontent.com/u/166111391?v=4)](https://github.com/menociGoettingen "menociGoettingen (1 commits)")[![christian-hen](https://avatars.githubusercontent.com/u/236581970?v=4)](https://github.com/christian-hen "christian-hen (1 commits)")[![JamesFrost](https://avatars.githubusercontent.com/u/6696197?v=4)](https://github.com/JamesFrost "JamesFrost (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/menoci-wikidata/health.svg)

```
[![Health](https://phpackages.com/badges/menoci-wikidata/health.svg)](https://phpackages.com/packages/menoci-wikidata)
```

###  Alternatives

[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3731.2M42](/packages/tencentcloud-tencentcloud-sdk-php)[mvdnbrk/dhlparcel-php-api

DHL Parcel API client for PHP

3957.9k5](/packages/mvdnbrk-dhlparcel-php-api)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)[mapado/rest-client-sdk

Rest Client SDK for hydra API

1125.9k2](/packages/mapado-rest-client-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
