PHPackages                             wikibase/data-model-serialization - 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. wikibase/data-model-serialization

ActiveLibrary

wikibase/data-model-serialization
=================================

Serializers and deserializers for the Wikibase DataModel

2.9.1(7y ago)10196.3k↓12.5%11[2 PRs](https://github.com/wmde/WikibaseDataModelSerialization/pulls)7GPL-2.0-or-laterPHPPHP &gt;=5.5.9CI failing

Since Feb 22Pushed 10mo ago25 watchersCompare

[ Source](https://github.com/wmde/WikibaseDataModelSerialization)[ Packagist](https://packagist.org/packages/wikibase/data-model-serialization)[ Docs](https://github.com/wmde/WikibaseDataModelSerialization)[ RSS](/packages/wikibase-data-model-serialization/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (34)Used By (7)

Wikibase DataModel Serialization
================================

[](#wikibase-datamodel-serialization)

[![Build Status](https://github.com/wmde/WikibaseDataModelSerialization/actions/workflows/lint-and-test.yaml/badge.svg?branch=master)](https://github.com/wmde/WikibaseDataModelSerialization/actions/workflows/lint-and-test.yaml)[![Download count](https://camo.githubusercontent.com/eaf5373a6ef991129ad598fd43d124708ccdb95c0fbcd83c0e660c40a0a83348/68747470733a2f2f706f7365722e707567782e6f72672f77696b69626173652f646174612d6d6f64656c2d73657269616c697a6174696f6e2f642f746f74616c2e706e67)](https://packagist.org/packages/wikibase/data-model-serialization)[![License](https://camo.githubusercontent.com/adc13a5fe55facb7a6fb3d945ca9809190c618e25dc2f1e11effb72ade8a86ed/68747470733a2f2f706f7365722e707567782e6f72672f77696b69626173652f646174612d6d6f64656c2d73657269616c697a6174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/wikibase/data-model-serialization)

[![Latest Stable Version](https://camo.githubusercontent.com/0cccb1fda0e4d33e41fb81b8c427f7006bc4f6cfa32b0e0edf39af3af1d947c6/68747470733a2f2f706f7365722e707567782e6f72672f77696b69626173652f646174612d6d6f64656c2d73657269616c697a6174696f6e2f76657273696f6e2e706e67)](https://packagist.org/packages/wikibase/data-model-serialization)[![Latest Unstable Version](https://camo.githubusercontent.com/f4da39e51559f518c2f70df594095f220ef5e42b0478032a9f4999017ba66e10/68747470733a2f2f706f7365722e707567782e6f72672f77696b69626173652f646174612d6d6f64656c2d73657269616c697a6174696f6e2f762f756e737461626c652e737667)](//packagist.org/packages/wikibase/data-model-serialization)

Library containing serializers and deserializers for the basic [Wikibase DataModel](https://github.com/wmde/WikibaseDataModel) entity types and components they are made of. The supported formats are limited to public ones, ie those used by a web API. Serialization code for private formats, such as the format used by the Wikibase Repo data access layer, belongs in other components.

Recent changes can be found in the [release notes](RELEASE-NOTES.md).

Note that this repository is a mirror of part of the upstream [Wikibase project](https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase/+/refs/heads/master/lib/packages/wikibase/data-model-serialization/) on gerrit. Contributions should be made to the directories there using MediaWiki's [Gerrit process](https://www.mediawiki.org/wiki/Gerrit).

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

[](#installation)

The recommended way to use this library is via [Composer](http://getcomposer.org/).

### Composer

[](#composer)

To add this package as a local, per-project dependency to your project, simply add a dependency on `wikibase/data-model-serialization` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on version 2.0 of this package:

```
{
	"require": {
		"wikibase/data-model-serialization": "~2.0"
	}
}
```

### Manual

[](#manual)

Get the code of this package, either via git, or some other means. Also get all dependencies. You can find a list of the dependencies in the "require" section of the composer.json file. Then take care of autoloading the classes defined in the src directory.

Library usage
-------------

[](#library-usage)

Construct an instance of the specific deserializer or serializer you need via the appropriate factory.

```
use Wikibase\DataModel\DeserializerFactory;

$deserializerFactory = new DeserializerFactory( /* ... */ );
$itemDeserializer = $deserializerFactory->newItemDeserializer();
```

Then use the `deserialize` or `serialize` method.

```
$item = $itemDeserializer->deserialize( $myItemSerialization );
```

In case of deserialization, guarding against failures is good practice. So it is typically better to use the slightly more verbose try-catch approach.

```
try {
	$item = $itemDeserializer->deserialize( $myItemSerialization );
} catch ( DeserializationException $ex ) {
	// Handling of the exception
}
```

All access to services provided by this library should happen through the SerializerFactory and DeserializerFactory. The rest of the code is an implementation detail which users should not know about.

Library structure
-----------------

[](#library-structure)

The Wikibase DataModel objects can all be serialized to a generic format from which the objects can later be reconstructed. This is done via a set of `Serializers\Serializer` implementing objects. These objects turn for instance a `Statement` object into a data structure containing only primitive types and arrays. This data structure can thus be readily fed to `json_encode`, `serialize`, or the like. The process of reconstructing the objects from such a serialization is provided by objects implementing the `Deserializers\Deserializer` interface.

Serializers can be obtained via an instance of `SerializerFactory` and deserializers can be obtained via an instance of `DeserializerFactory`. You are not allowed to construct these serializers and deserializers directly yourself or to have any kind of knowledge of them (ie type hinting). These objects are internal to this component and might change name or structure at any time. All you are allowed to know when calling `$serializerFactory->newItemDeserializer()` is that you get back an instance of `Serializers\Serializer`.

Running the tests
-----------------

[](#running-the-tests)

For tests only

```
composer test

```

For style checks only

```
composer cs

```

For a full CI run

```
composer ci

```

Contributing
------------

[](#contributing)

This repository is a mirror of part of the upstream [Wikibase project](https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/Wikibase/+/refs/heads/master/lib/packages/wikibase/data-model-serialization/) on Gerrit. Contributions should be made to the directories there using MediaWiki's [Gerrit process](https://www.mediawiki.org/wiki/Gerrit).

Authors
-------

[](#authors)

Wikibase DataModel Serialization has been written by [Thomas PT](https://github.com/Tpt) as volunteer and by [Jeroen De Dauw](https://www.EntropyWins.wtf) as [Wikimedia Germany](https://wikimedia.de) employee for the [Wikidata project](https://wikidata.org/).

Links
-----

[](#links)

- [Wikibase DataModel Serialization on Packagist](https://packagist.org/packages/wikibase/data-model-serialization)
- [Wikibase DataModel Serialization on OpenHub](https://www.openhub.net/p/WikibaseDataModelSerialization)

See also
--------

[](#see-also)

- [Wikibase DataModel](https://github.com/wmde/WikibaseDataModel)
- [Wikibase Internal Serialization](https://github.com/wmde/WikibaseInternalSerialization) (For the "internal" serialization format)

Bugs on Phabricator
===================

[](#bugs-on-phabricator)

###  Health Score

48

—

FairBetter than 95% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community40

Growing community involvement

Maturity69

Established project with proven stability

 Bus Factor3

3 contributors hold 50%+ of commits

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

Every ~67 days

Recently: every ~113 days

Total

27

Last Release

2712d ago

Major Versions

0.1 → 1.02014-05-27

1.9.1 → 2.0.02015-08-30

PHP version history (3 changes)0.1PHP &gt;=5.3.0

2.3.0PHP &gt;=5.5.0

2.5.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/451bd4039d530fed8f9c3da91bfa519233a397d2182cdfdcad700f6cfea19b7f?d=identicon)[Jeroen De Dauw](/maintainers/Jeroen%20De%20Dauw)

![](https://www.gravatar.com/avatar/054adb441e7ee248ec924bc45fa793835c284710eb31627587fa5de21bab9e96?d=identicon)[wmde](/maintainers/wmde)

![](https://www.gravatar.com/avatar/5406ed1d40d50ffc61d67e9f5149914dbfe0b8a52bdf297299f5ccfab0a73d91?d=identicon)[thiemowmde](/maintainers/thiemowmde)

![](https://www.gravatar.com/avatar/fe4220e5a109212ea1a84969fbcb0795ceaf975145c1f0577bd758d0500e6428?d=identicon)[manicki](/maintainers/manicki)

![](https://www.gravatar.com/avatar/8cc7ef1a982b9520bbe19e7699556cda12f528e2fcece72d0d18e79b6457794c?d=identicon)[mariushoch](/maintainers/mariushoch)

---

Top Contributors

[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (195 commits)")[![thiemowmde](https://avatars.githubusercontent.com/u/6576639?v=4)](https://github.com/thiemowmde "thiemowmde (98 commits)")[![Tpt](https://avatars.githubusercontent.com/u/458123?v=4)](https://github.com/Tpt "Tpt (83 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (69 commits)")[![Benestar](https://avatars.githubusercontent.com/u/2998254?v=4)](https://github.com/Benestar "Benestar (45 commits)")[![mariushoch](https://avatars.githubusercontent.com/u/2446964?v=4)](https://github.com/mariushoch "mariushoch (24 commits)")[![JanZerebecki](https://avatars.githubusercontent.com/u/7452727?v=4)](https://github.com/JanZerebecki "JanZerebecki (16 commits)")[![jakobw](https://avatars.githubusercontent.com/u/453024?v=4)](https://github.com/jakobw "jakobw (14 commits)")[![manicki](https://avatars.githubusercontent.com/u/3524114?v=4)](https://github.com/manicki "manicki (13 commits)")[![Ladsgroup](https://avatars.githubusercontent.com/u/5351225?v=4)](https://github.com/Ladsgroup "Ladsgroup (10 commits)")[![lucaswerkmeister](https://avatars.githubusercontent.com/u/2346599?v=4)](https://github.com/lucaswerkmeister "lucaswerkmeister (9 commits)")[![codders](https://avatars.githubusercontent.com/u/17782?v=4)](https://github.com/codders "codders (8 commits)")[![umherirrender](https://avatars.githubusercontent.com/u/1174884?v=4)](https://github.com/umherirrender "umherirrender (7 commits)")[![Silvan-WMDE](https://avatars.githubusercontent.com/u/59574251?v=4)](https://github.com/Silvan-WMDE "Silvan-WMDE (4 commits)")[![rosalieper](https://avatars.githubusercontent.com/u/15235452?v=4)](https://github.com/rosalieper "rosalieper (3 commits)")[![ZabeMath](https://avatars.githubusercontent.com/u/35405030?v=4)](https://github.com/ZabeMath "ZabeMath (2 commits)")[![JonasKress](https://avatars.githubusercontent.com/u/13198391?v=4)](https://github.com/JonasKress "JonasKress (2 commits)")[![filbertkm](https://avatars.githubusercontent.com/u/135401?v=4)](https://github.com/filbertkm "filbertkm (2 commits)")[![Daimona](https://avatars.githubusercontent.com/u/38216014?v=4)](https://github.com/Daimona "Daimona (2 commits)")[![outdooracorn](https://avatars.githubusercontent.com/u/43674967?v=4)](https://github.com/outdooracorn "outdooracorn (2 commits)")

---

Tags

serializationserializerswikidatawikibasedeserializersDataModel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wikibase-data-model-serialization/health.svg)

```
[![Health](https://phpackages.com/badges/wikibase-data-model-serialization/health.svg)](https://phpackages.com/packages/wikibase-data-model-serialization)
```

###  Alternatives

[wikibase/data-model

PHP implementation of the Wikibase DataModel

37243.3k23](/packages/wikibase-data-model)[data-values/data-values

Defines the DataValue interface and some trivial implementations

171.0M22](/packages/data-values-data-values)[addwiki/wikibase-api

Wikibase API library

254.7k3](/packages/addwiki-wikibase-api)[jeroen/json-dump-reader

Provides line-by-line readers and iterators for Wikibase/Wikidata JSON dumps

7412.3k](/packages/jeroen-json-dump-reader)[professional-wiki/wikibase-local-media

Adds the local media data type to Wikibase

127.0k](/packages/professional-wiki-wikibase-local-media)

PHPackages © 2026

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