PHPackages                             alantiller/directus-php-sdk - 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. alantiller/directus-php-sdk

ActiveLibrary[API Development](/categories/api)

alantiller/directus-php-sdk
===========================

A PHP SDK for interacting with the Directus API

v2.0.0(11mo ago)3631.5k↓29.6%81MITPHPPHP ^8.0

Since Feb 13Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/alantiller/directus-php-sdk)[ Packagist](https://packagist.org/packages/alantiller/directus-php-sdk)[ RSS](/packages/alantiller-directus-php-sdk/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (9)Dependencies (2)Versions (7)Used By (1)

Directus PHP SDK
================

[](#directus-php-sdk)

[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

A PHP SDK for interacting with the Directus API. This SDK provides a convenient and object-oriented way to access Directus endpoints and perform common operations.

Table of Contents
-----------------

[](#table-of-contents)

- [Directus PHP SDK](#directus-php-sdk)
    - [Table of Contents](#table-of-contents)
    - [Features](#features)
    - [Requirements](#requirements)
    - [Installation](#installation)
    - [Configuration](#configuration)
    - [Usage](#usage)
        - [Authentication](#authentication)
            - [API Key Authentication](#api-key-authentication)
            - [User/Password Authentication](#userpassword-authentication)
        - [Items](#items)
        - [Users](#users)
        - [Files](#files)
        - [Other Endpoints](#other-endpoints)
        - [Custom Calls](#custom-calls)
    - [Storage](#storage)
        - [Session Storage](#session-storage)
        - [Cookie Storage](#cookie-storage)
        - [Custom Storage](#custom-storage)
    - [Error Handling](#error-handling)
    - [Testing](#testing)
    - [Contributing](#contributing)
    - [License](#license)

Features
--------

[](#features)

- Object-oriented interface for interacting with the Directus API
- Supports all Directus endpoints (Items, Files, Users, etc.)
- Supports multiple authentication methods (API Key, User/Password)
- Customizable storage for authentication tokens (Session, Cookie, Custom)
- Easy-to-use methods for common CRUD operations (Create, Read, Update, Delete)
- Comprehensive error handling

Requirements
------------

[](#requirements)

- PHP 8.0 or higher
- Composer
- Guzzle HTTP client (`guzzlehttp/guzzle`)

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

[](#installation)

1. Install the SDK using Composer:

    ```
    composer require alantiller/directus-php-sdk
    ```

Configuration
-------------

[](#configuration)

Before using the SDK, you need to configure it with your Directus base URL and authentication details.

1. **Base URL:** The base URL of your Directus instance (e.g., `https://your-directus-instance.com`).
2. **Storage:** Choose a storage mechanism for authentication tokens (Session, Cookie, or Custom).
3. **Authentication:** Choose an authentication method and provide the necessary credentials.

Usage
-----

[](#usage)

### Authentication

[](#authentication)

The SDK supports multiple authentication methods:

#### API Key Authentication

[](#api-key-authentication)

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Auth\ApiKeyAuth;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$apiKey = 'YOUR_API_KEY';

$storage = new SessionStorage('directus_'); // Optional prefix
$auth = new ApiKeyAuth($apiKey);

$directus = new Directus(
    $baseUrl,
    $storage,
    $auth
);
```

#### User/Password Authentication

[](#userpassword-authentication)

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Auth\UserPasswordAuth;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$username = 'your_email@example.com';
$password = 'your_password';

$storage = new SessionStorage('directus_'); // Optional prefix
$auth = new UserPasswordAuth($baseUrl, $username, $password);

$directus = new Directus(
    $baseUrl,
    $storage,
    $auth
);

// Authenticate the user
try {
    $directus->authenticate();
} catch (\Exception $e) {
    echo "Authentication failed: " . $e->getMessage() . PHP_EOL;
}
```

### Items

[](#items)

The `items` endpoint allows you to manage items in a specific collection.

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$storage = new SessionStorage('directus_');

$directus = new Directus(
    $baseUrl,
    $storage
);

$collection = 'your_collection';
$items = $directus->items($collection);

// Get all items
$all_items = $items->get();
print_r($all_items);

// Get a specific item
$item = $items->get(1);
print_r($item);

// Create a new item
$new_item = $items->create(['name' => 'New Item', 'status' => 'published']);
print_r($new_item);

// Update an existing item
$updated_item = $items->update(['name' => 'Updated Item'], 1);
print_r($updated_item);

// Delete an item
$deleted_item = $items->delete(1);
print_r($deleted_item);
```

### Users

[](#users)

The `users` endpoint allows you to manage users in your Directus instance.

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$storage = new SessionStorage('directus_');

$directus = new Directus(
    $baseUrl,
    $storage
);

$users = $directus->users();

// Get all users
$all_users = $users->get();
print_r($all_users);

// Get a specific user
$user = $users->get('user_id');
print_r($user);

// Create a new user
$new_user = $users->create([
    'first_name' => 'John',
    'last_name' => 'Doe',
    'email' => 'john.doe@example.com',
    'password' => 'password123',
    'role' => 'administrator'
]);
print_r($new_user);

// Update an existing user
$updated_user = $users->update([
    'first_name' => 'Jane',
    'last_name' => 'Doe'
], 'user_id');
print_r($updated_user);

// Delete a user
$deleted_user = $users->delete('user_id');
print_r($deleted_user);
```

### Files

[](#files)

The `files` endpoint allows you to manage files in your Directus instance.

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$storage = new SessionStorage('directus_');

$directus = new Directus(
    $baseUrl,
    $storage
);

$files = $directus->files();

// Get all files
$all_files = $files->get();
print_r($all_files);

// Get a specific file
$file = $files->get('file_id');
print_r($file);

// Create a new file
$file_path = '/path/to/your/file.jpg';
$new_file = $files->create([
    'name' => basename($file_path),
    'tmp_name' => $file_path,
]);
print_r($new_file);

// Update an existing file
$updated_file = $files->update('file_id', ['title' => 'New Title']);
print_r($updated_file);

// Delete a file
$deleted_file = $files->delete('file_id');
print_r($deleted_file);

// Update complete file (uses custom call)
$file_path = '/path/to/your/file.jpg';
$this->directus->makeCustomCall(
    sprintf('/files/%s', $fileId),
    [
        'name' => basename($file_path),
        'tmp_name' => $file_path,
    ],
    'PATCH_MULTIPART'
);
```

### Other Endpoints

[](#other-endpoints)

The SDK provides access to all Directus endpoints, including:

- `activity()`
- `collections()`
- `comments()`
- `contentVersions()`
- `dashboards()`
- `extensions()`
- `fields(string $collection)`
- `flows()`
- `folders()`
- `notifications()`
- `operations()`
- `panels()`
- `permissions()`
- `policies()`
- `presets()`
- `relations()`
- `revisions()`
- `roles()`
- `schema()`
- `server()`
- `settings()`
- `shares()`
- `translations()`
- `utilities()`

Each endpoint provides methods for performing common operations, such as `get`, `create`, `update`, and `delete`. Refer to the Directus API documentation for more information on each endpoint and its available methods.

### Custom Calls

[](#custom-calls)

You can make custom API calls using the `makeCustomCall` method:

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$baseUrl = 'https://your-directus-instance.com';
$storage = new SessionStorage('directus_');

$directus = new Directus(
    $baseUrl,
    $storage
);

$uri = '/your/custom/endpoint';
$data = ['param1' => 'value1', 'param2' => 'value2'];
$method = 'GET';

$response = $directus->makeCustomCall($uri, $data, $method);
print_r($response);
```

Storage
-------

[](#storage)

The SDK uses a `StorageInterface` to store authentication tokens. You can choose between session storage, cookie storage, or implement your own custom storage mechanism.

### Session Storage

[](#session-storage)

Session storage uses PHP sessions to store authentication tokens. This is the default storage mechanism.

```
use AlanTiller\DirectusSdk\Storage\SessionStorage;

$storage = new SessionStorage('directus_'); // Optional prefix
```

### Cookie Storage

[](#cookie-storage)

Cookie storage uses cookies to store authentication tokens.

```
use AlanTiller\DirectusSdk\Storage\CookieStorage;

$storage = new CookieStorage('directus_', '/'); // Optional prefix and domain
```

### Custom Storage

[](#custom-storage)

You can implement your own custom storage mechanism by creating a class that implements the `StorageInterface`.

```
use AlanTiller\DirectusSdk\Storage\StorageInterface;

class MyCustomStorage implements StorageInterface
{
    public function set(string $key, $value): void
    {
        // Store the value
    }

    public function get(string $key)
    {
        // Retrieve the value
    }

    public function delete(string $key): void
    {
        // Delete the value
    }
}

$storage = new MyCustomStorage();
```

Error Handling
--------------

[](#error-handling)

The SDK throws exceptions for API errors. You can catch these exceptions and handle them appropriately.

```
use AlanTiller\DirectusSdk\Directus;
use AlanTiller\DirectusSdk\Storage\SessionStorage;
use AlanTiller\DirectusSdk\Exceptions\DirectusException;

$baseUrl = 'https://your-directus-instance.com';
$storage = new SessionStorage('directus_');

$directus = new Directus(
    $baseUrl,
    $storage
);

try {
    $items = $directus->items('your_collection')->get();
    print_r($items);
} catch (DirectusException $e) {
    echo "API error: " . $e->getMessage() . PHP_EOL;
}
```

Testing
-------

[](#testing)

The SDK includes a set of Pest PHP tests to ensure that it functions correctly. To run the tests, follow these steps:

1. Install Pest PHP:

    ```
    composer require pestphp/pest --dev
    ```
2. Run the tests:

    ```
    ./vendor/bin/pest
    ```

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

[](#contributing)

Contributions are welcome! Please submit a pull request with your changes.

License
-------

[](#license)

The Directus PHP SDK is licensed under the [MIT License](LICENSE).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance56

Moderate activity, may be stable

Popularity40

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 53.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 ~249 days

Recently: every ~310 days

Total

6

Last Release

353d ago

Major Versions

v1.0.3 → v2.0.0-rc.12025-02-09

PHP version history (3 changes)v1.0.0PHP ^7.0

v1.0.3PHP ^7.0 || ^8.0

v2.0.0-rc.1PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/280e4b985f922abd667a75c49aee0c176202dcbf84464fd50de0cd9328092e60?d=identicon)[alantiller](/maintainers/alantiller)

---

Top Contributors

[![alantiller](https://avatars.githubusercontent.com/u/26198238?v=4)](https://github.com/alantiller "alantiller (17 commits)")[![andrii-bodnar](https://avatars.githubusercontent.com/u/29282228?v=4)](https://github.com/andrii-bodnar "andrii-bodnar (11 commits)")[![thejoekerman](https://avatars.githubusercontent.com/u/22023901?v=4)](https://github.com/thejoekerman "thejoekerman (3 commits)")[![stephane-monnot](https://avatars.githubusercontent.com/u/6066368?v=4)](https://github.com/stephane-monnot "stephane-monnot (1 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/alantiller-directus-php-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/alantiller-directus-php-sdk/health.svg)](https://phpackages.com/packages/alantiller-directus-php-sdk)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M984](/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)
