PHPackages                             thoth-pub/thoth-client-php - 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. thoth-pub/thoth-client-php

ActiveLibrary[API Development](/categories/api)

thoth-pub/thoth-client-php
==========================

PHP client for Thoth's GraphQL and REST APIs.

2.0.1(2d ago)18352Apache-2.0PHPPHP &gt;=7.4CI passing

Since Dec 11Pushed 2w ago4 watchersCompare

[ Source](https://github.com/thoth-pub/thoth-client-php)[ Packagist](https://packagist.org/packages/thoth-pub/thoth-client-php)[ RSS](/packages/thoth-pub-thoth-client-php/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (10)Versions (17)Used By (0)

**English** | [Español](/docs/README-es.md) | [Português Brasileiro](/docs/README-pt_BR.md)

Thoth Client PHP
================

[](#thoth-client-php)

PHP client for the Thoth GraphQL and REST APIs.

Install
-------

[](#install)

This library is installable via Composer:

```
composer require thoth-pub/thoth-client-php
```

Usage
-----

[](#usage)

### GraphQL

[](#graphql)

API Documentation:

```
$client = new \ThothApi\GraphQL\Client();
```

#### Queries

[](#queries)

Query, mutation, schema, input, enum and scalar classes are generated from the Thoth GraphQL introspection schema. The most convenient API is the dynamic client method named after the GraphQL operation.

```
$works = $client->works(5, [
    'workId',
    'fullTitle',
]);

echo $works[0]->getWorkId();
echo $works[0]->getFullTitle();
```

Arguments can be passed positionally or by name. Enum values can be passed directly using generated enum constants. `OperationRequest::enum()` is still supported for custom operations.

```
use ThothApi\GraphQL\Enums\Direction;
use ThothApi\GraphQL\Enums\WorkField;

$works = $client->works([
    'publishers' => ['71faf1c3-900a-4b8c-bca7-4f927699fb90'],
    'limit' => 5,
    'order' => [
        'field' => WorkField::PUBLICATION_DATE,
        'direction' => Direction::DESC,
    ],
], [
    'workId',
    'fullTitle',
    'doi',
]);
```

Selections can include nested fields. Returned object fields and lists are hydrated into generated schema classes.

```
$work = $client->work('5a5b0fe3-03a9-444b-b221-ecae5370ff30', [
    'workId',
    'fullTitle',
    'titles' => [
        'titleId',
        'fullTitle',
    ],
    'imprint' => [
        'imprintId',
        'publisher' => [
            'publisherId',
            'publisherName',
        ],
    ],
]);

echo $work->getImprint()->getPublisher()->getPublisherName();
echo $work->getTitles()[0]->getFullTitle();
```

The generic executor is still available when you want to use the generated operation classes directly. It returns raw arrays instead of hydrated schema objects.

```
use ThothApi\GraphQL\Queries\WorksQuery;

$works = $client->execute(WorksQuery::operation([
    'limit' => 5,
], [
    'workId',
    'fullTitle',
]));
```

Raw GraphQL queries are supported and use the configured token.

```
$data = $client->rawQuery('query { workCount }');
```

#### Mutations

[](#mutations)

To execute mutations, provide a valid personal access token to the client.

```
$client->setToken($token);
```

Inputs are generated from the schema. They can be created from arrays, from DTOs that expose `getAllData()`, or from `JsonSerializable` objects.

```
use ThothApi\GraphQL\Enums\SubjectType;
use ThothApi\GraphQL\Inputs\NewSubject;

$newSubject = new NewSubject([
    'workId' => '5a5b0fe3-03a9-444b-b221-ecae5370ff30',
    'subjectType' => SubjectType::BIC,
    'subjectCode' => '1D',
    'subjectOrdinal' => 3,
]);

$subjectId = $client->createSubject($newSubject);
```

By default, mutations returning objects select the first `*Id` field and return that scalar value, so existing calls stay short.

```
$subjectId = $client->createSubject($newSubject);
```

Pass an explicit selection when you want a hydrated schema object with getters, setters and `toArray()`.

```
$subject = $client->createSubject($newSubject, [
    'subjectId',
    'subjectCode',
]);

echo $subject->getSubjectId();
echo $subject->getSubjectCode();
print_r($subject->toArray());
```

Schema objects can also be instantiated and populated manually.

```
use ThothApi\GraphQL\Schemas\Work;

$work = (new Work())
    ->setWorkId('5a5b0fe3-03a9-444b-b221-ecae5370ff30')
    ->setFullTitle('Example title');

echo $work->getFullTitle();
print_r($work->toArray());
```

Regenerate the GraphQL classes from the current Thoth GraphQL schema:

```
composer generate-graphql-client
```

#### Exceptions

[](#exceptions)

A QueryException is thrown in case of an error in the request to the GraphQL API. It's possible to retrieve the error message and a more detailed description from the exception.

```
try {
    $client->execute(\ThothApi\GraphQL\Mutations\CreateWorkMutation::operation([
        'data' => [
            'doi' => 'https://doi.org/10.00000/00000000',
        ],
    ], ['workId']));
} catch (\ThothApi\Exception\QueryException $exception) {
    echo $exception->getMessage();
    /**
     * Invalid value for argument "data", reason:
     * "NewWork" is missing fields: "imprintId", "workStatus", "workType"
    */
    echo print_r($exception->getDetails());
    /**
     *  Array (
     *      [message] => Invalid value for argument "data", reason: "NewWork" is missing fields: "imprintId", "workStatus", "workType"
     *      [locations] => Array (
     *          [0] => Array (
     *              [line] => 3
     *              [column] => 15
     *          )
     *      )
     * )
    */
    echo $exception->getQuery();
    echo print_r($exception->getVariables(), true);
}
```

### REST

[](#rest)

API Documentation:

```
$client = new \ThothApi\Rest\Client();
```

The REST client exports metadata in the formats exposed by the Thoth export API.

```
$formats = $client->formats();

$metadata = $client->work(
    'doideposit::crossref',
    'e0f748b2-984f-45cc-8b9e-13989c31dda4'
);
```

#### Exceptions

[](#exceptions-1)

```
try {
    $result = $client->publisher('foo', '42b3315e-07e9-4e23-92ae-86932e4ef0e3');
} catch (\ThothApi\Exception\RestException $exception) {
    echo $exception->getMessage(); // "foo is not a valid metadata specification"
}
```

### Client Construction

[](#client-construction)

The constructor of both Clients can receive an optional array to add custom [Guzzle HTTP Client request options](https://docs.guzzlephp.org/en/latest/request-options.html).

```
$client = new Client([
    'allow_redirects' => false,
    'connect_timeout' => 3.14,
    'timeout' => 3.14,
    'proxy' => [
        'http' => 'http://localhost:8125',
        'https' => 'http://localhost:9124',
        'no' => ['.mit.edu', 'foo.com'],
    ],
    'debug' => true,
]);
```

Clients make requests to the default addresses of the Thoth APIs:  for the GraphQL API and  for the REST API. If you want to use a different address (such as "localhost" for testing), just add the "base\_uri" option with the new address in the client's constructor.

```
$client = new Client(['base_uri' => 'localhost:8000']);
```

Credits
-------

[](#credits)

Idealized and sponsored by [Thoth](https://thoth.pub/).

Developed by [Lepidus Tecnologia](https://github.com/lepidus).

License
-------

[](#license)

Licensed under the Apache License, Version 2.0 - [See the License file.](/LICENSE)

Copyright (c) 2024-2026 Lepidus Tecnologia

Copyright (c) 2024-2026 Thoth Open Metadata

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance98

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.1% 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

Every ~47 days

Recently: every ~98 days

Total

13

Last Release

2d ago

Major Versions

1.4.1 → 2.0.02026-06-16

### Community

Maintainers

![](https://www.gravatar.com/avatar/468954953a2effa1f2311a6ea9300f8632d12ab1687d392dd0c05ddac216fcb7?d=identicon)[thoth](/maintainers/thoth)

![](https://www.gravatar.com/avatar/9d520c8c94da6b7149de6d33490f3ba06dd92ef0fb3a18d6d5b539a5296c3087?d=identicon)[thiagolepidus](/maintainers/thiagolepidus)

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

---

Top Contributors

[![thiagolepidus](https://avatars.githubusercontent.com/u/79112589?v=4)](https://github.com/thiagolepidus "thiagolepidus (170 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![pablovp86](https://avatars.githubusercontent.com/u/26493682?v=4)](https://github.com/pablovp86 "pablovp86 (1 commits)")[![SteelWagstaff](https://avatars.githubusercontent.com/u/13485451?v=4)](https://github.com/SteelWagstaff "SteelWagstaff (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/thoth-pub-thoth-client-php/health.svg)

```
[![Health](https://phpackages.com/badges/thoth-pub-thoth-client-php/health.svg)](https://phpackages.com/packages/thoth-pub-thoth-client-php)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M986](/packages/statamic-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M47](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[eslazarev/wildberries-sdk

Wildberries OpenAPI clients (generated).

273.0k](/packages/eslazarev-wildberries-sdk)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)

PHPackages © 2026

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