Search by

sdk-generator / sdk-runtime

dmorenof

Lightweight shared PHP runtime for contract-driven SDKs.

Package info

github.com/sdk-generator/sdk-runtime

pkg:composer/sdk-generator/sdk-runtime

Statistics

Installs: 783

Dependents: 52

Suggesters: 0

Stars: 0

Open Issues: 0


README

PHP package CI License: MIT

The engine for typed PHP API clients, from an OpenAPI file or by hand. Transport, authentication (API key, basic, bearer, OAuth2 with automatic renewal, OpenID Connect with ID-token validation, mutual TLS), typed models validated where you assign, errors, retries, redirects, streaming and timeouts live here, written and tested once; an SDK holds only what is specific to its API. It is the base of every SDK made by sdk-generator, which reads OpenAPI 3.x, Swagger 2.0, RAML, Postman collections and browser HAR captures, and you can write your own client on it for an API that has no specification. PHP 8.4+.

Everything the generator and this runtime do, on one page: Everything it can do.

A client holds its own transport and credentials, and nothing is shared between clients.

Why use it

Measured on 2026-12-04 (runtime 1.16.0, generator 1.19.0) against OpenAPI Generator 7.26 on PHP 8.4, with the SDK each generator makes from the same published contract, a clean process per measurement and the same real answer served to both:

This runtime + generator OpenAPI Generator
PokeAPI (102 operations): everything installed 3.6 MB 6.7 MB
PokeAPI: one Pokémon (350 KB of JSON), time per call 0.50× (5.2 ms) 10.5 ms
PokeAPI: peak memory of that call 0.67× (9.7 MB) 14.4 MB
met.no (Swagger, 12 operations): time per call 0.33×–0.36×
Casafari (46 operations): everything installed 4.0 MB 6.3 MB
PokeAPI + Wikimedia + met.no in one project: everything installed 3.9 MB 8.6 MB
Casafari: peak memory, nested models 2.5 MB 10 MB
Memory growth over thousands of calls 4 KiB 163–3,130 KiB

And less to write: OAuth2 tokens are fetched and renewed for you, models are plain typed properties (no getters and setters), and retries, redirects, timeouts and proxies are one Configuration.

Where it is not better, said plainly: the runtime is paid once, so a single very small API installs more (met.no alone: 2.8 MB against 1.9 MB) and every further API on the same runtime only adds its own, smaller code (the three above together are half of OpenAPI Generator's), the first call in a fresh process is about 1.25× slower (with or without OPcache), and it needs PHP 8.4. The method and every table are in Why this runtime; every benchmark of the project, with its scripts and how to repeat it, is listed in the generator's Benchmarks.

In thirty seconds

use Acme\Accounts\{Configuration, Users};
use Acme\Accounts\DTOs\NewUser;

Users::configure(new Configuration());   // an SDK generated from the API's specification

$new = new NewUser();
$new->name = 'Ada';

$user = Users::post($new);               // typed, validated model
echo $user->id;

Documentation

I want to… Read
See what it costs and what it saves, measured Why this runtime
Make my first call Getting started
Work with models, parameters and errors Using an SDK
Pass parameters, upload files, send cookies Sending data
Authenticate (API key, bearer, basic, OAuth2) Authentication
Set timeouts, retries, redirects, proxies, servers Transport and servers
Read headers, files, streams and error bodies Responses
Understand validation and formats Validation
Write a client for an API with no specification Writing an API client by hand
Write or change a generator Operation metadata
Look up a class API reference
Know what may change between versions Public API and versioning

The full index, with a one-minute model of how the pieces fit, is docs/README.md. Notes on features as they were introduced in versions 0.4 to 0.31 are kept in docs/archive.

Compatibility

From 1.0.0 the package follows Semantic Versioning. What is stable, what is internal and what counts as a breaking change is defined in docs/PUBLIC_API.md.

Development

Use PHP 8.4+ and Composer 2:

composer install
bash ci/run-tests.sh

Source code belongs in src/ under Dmorenof\SdkRuntime\; tests belong in tests/.

GitHub Flow

Develop on a branch and open a PR. A version is published only when its work is finished and proven and the owner confirms (changing VERSION on main publishes); versions are not published piecemeal. See AGENTS.md, CONTRIBUTING.md and RELEASING.md.

License

MIT; see LICENSE.