{"id":22354023,"url":"https://github.com/rubixml/client","last_synced_at":"2025-10-25T16:46:36.264Z","repository":{"id":62538027,"uuid":"399668192","full_name":"RubixML/Client","owner":"RubixML","description":"Client-side SDK for Rubix ML Server to use in your PHP applications.","archived":false,"fork":false,"pushed_at":"2023-09-19T21:45:00.000Z","size":21,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-16T22:15:44.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubixML.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null}},"created_at":"2021-08-25T02:42:29.000Z","updated_at":"2023-09-19T21:52:45.000Z","dependencies_parsed_at":"2023-09-30T01:55:25.456Z","dependency_job_id":null,"html_url":"https://github.com/RubixML/Client","commit_stats":{"total_commits":5,"total_committers":1,"mean_commits":5.0,"dds":0.0,"last_synced_commit":"456d8b2c8a096b244aa92760dd25d4898f10f23b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixML%2FClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixML%2FClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixML%2FClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixML%2FClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubixML","download_url":"https://codeload.github.com/RubixML/Client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228114882,"owners_count":17871742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-04T13:10:53.482Z","updated_at":"2025-10-25T16:46:31.241Z","avatar_url":"https://github.com/RubixML.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rubix Client\nThe PHP client SDK for Rubix ML Server.\n\n## Installation\nInstall Rubix Client SDK using [Composer](https://getcomposer.org/):\n\n```sh\n$ composer require rubix/client\n```\n\n## Requirements\n- [PHP](https://php.net/manual/en/install.php) 7.4 or above\n\n## Documentation\nThe latest documentation can be found below.\n\n### Table of Contents\n- [Clients](#clients)\n\t- [REST Client](#rest-client)\n- [Client Middleware](#client-middleware)\n\t- [Backoff and Retry](#backoff-and-retry)\n\t- [Basic Authenticator](#basic-authenticator-client-side)\n\t- [Compress Request Body](#compress-request-body)\n\t- [Shared Token Authenticator](#shared-token-authenticator-client-side)\n\n---\n### Clients\nClients allow you to communicate directly with a model server using a friendly object-oriented interface inside your PHP applications. Under the hood, clients handle all the networking communication and content negotiation for you so you can write programs *as if* the model was directly accessible in your applications.\n\nReturn the predictions from the model:\n```php\npublic predict(Dataset $dataset) : array\n```\n\n```php\nuse Rubix\\Client\\RESTClient;\n\n$client = new RESTClient('127.0.0.1', 8080);\n\n// Import a dataset\n\n$predictions = $client-\u003epredict($dataset);\n```\n\nCalculate the joint probabilities of each sample in a dataset:\n```php\npublic proba(Dataset $dataset) : array\n```\n\nCalculate the anomaly scores of each sample in a dataset:\n```php\npublic score(Dataset $dataset) : array\n```\n\n### Async Clients\nClients that implement the Async Client interface have asynchronous versions of all the standard client methods. All asynchronous methods return a [Promises/A+](https://promisesaplus.com/) object that resolves to the return value of the response. Promises allow you to perform other work while the request is processing or to execute multiple requests in parallel. Calling the `wait()` method on the promise will block until the promise is resolved and return the value.\n\n```php\npublic predictAsync(Dataset $dataset) : Promise\n```\n\n```php\n$promise = $client-\u003epredictAsync($dataset);\n\n// Do something else\n\n$predictions = $promise-\u003ewait();\n```\n\nReturn a promise for the probabilities predicted by the model:\n```php\npublic probaAsync(Dataset $dataset) : Promise\n```\n\nReturn a promise for the anomaly scores predicted by the model:\n```php\npublic scoreAsync(Dataset $dataset) : Promise\n```\n\n### REST Client\nThe REST Client communicates with the [HTTP Server](#http-server) through the JSON REST API it exposes.\n\nInterfaces: [Client](#clients), [AsyncClient](#async-clients)\n\n#### Parameters\n| # | Param | Default | Type | Description |\n|---|---|---|---|---|\n| 1 | host | '127.0.0.1' | string | The IP address or hostname of the server. |\n| 2 | port | 8000 | int | The network port that the HTTP server is running on. |\n| 3 | secure | false | bool | Should we use an encrypted HTTP channel (HTTPS)? |\n| 4 | middlewares | | array | The stack of client middleware to run on each request/response.  |\n| 5 | timeout | | float | The number of seconds to wait before giving up on the request. |\n| 6 | verify certificate | true | bool | Should we try to verify the server's TLS certificate? |\n\n**Example**\n\n```php\nuse Rubix\\Client\\RESTClient;\nuse Rubix\\Client\\HTTP\\Middleware\\BasicAuthenticator;\nuse Rubix\\Client\\HTTP\\Middleware\\CompressRequestBody;\nuse Rubix\\Client\\HTTP\\Middleware\\BackoffAndRetry;\nuse Rubix\\Client\\HTTP\\Encoders\\Gzip;\n\n$client = new RESTClient('127.0.0.1', 443, true, [\n\tnew BasicAuthenticator('user', 'password'),\n\tnew CompressRequestBody(new Gzip(1)),\n\tnew BackoffAndRetry(),\n], 0.0, true);\n```\n\n### Client Middleware\nSimilarly to Server middleware, client middlewares are functions that hook into the request/response cycle but from the client end. Some of the server middlewares have accompanying client middleware such as [Basic Authenticator](#basic-authenticator) and [Shared Token Authenticator](#shared-token-authenticator).\n\n### Backoff and Retry\nThe Backoff and Retry middleware handles Too Many Requests (429) and Service Unavailable (503) responses by retrying the request after waiting for a period of time to avoid overloading the server even further. An acceptable backoff period is gradually achieved by multiplicatively increasing the delay between retries.\n\n#### Parameters\n| # | Param | Default | Type | Description |\n|---|---|---|---|---|\n| 1 | max retries | 3 | int | The maximum number of times to retry the request before giving up. |\n| 2 | initial delay | 0.5 | float | The number of seconds to delay between retries before exponential backoff is applied. |\n\n**Example**\n\n```php\nuse Rubix\\Client\\HTTP\\Middleware\\BackoffAndRetry;\n\n$middleware = new BackoffAndRetry(5, 0.5);\n```\n\n### Basic Authenticator (Client Side)\nAdds the necessary authorization headers to the request using the Basic scheme.\n\n#### Parameters\n| # | Param | Default | Type | Description |\n|---|---|---|---|---|\n| 1 | username | | string | The user's name. |\n| 2 | password | | string | The user's password. |\n\n**Example**\n\n```php\nuse Rubix\\Client\\HTTP\\Middleware\\BasicAuthenticator;\n\n$middleware = new BasicAuthenticator('morgan', 'secret');\n```\n\n### Compress Request Body\nApply the Gzip compression algorithm to the request body.\n\n#### Parameters\n| # | Param | Default | Type | Description |\n|---|---|---|---|---|\n| 1 | level | 5 | int | The compression level between 0 and 9 with 0 meaning no compression. |\n| 2 | threshold | 65535 | int | The minimum size of the request body in bytes in order to be compressed. |\n\n**Example**\n\n```php\nuse Rubix\\Client\\HTTP\\Middleware\\CompressRequestBody;\n\n$middleware = new CompressRequestBody(5, 65535);\n```\n\n### Shared Token Authenticator (Client Side)\nAdds the necessary authorization headers to the request using the Bearer scheme.\n\n#### Parameters\n| # | Param | Default | Type | Description |\n|---|---|---|---|---|\n| 1 | token | | string | The shared token to authenticate the request. |\n\n**Example**\n\n```php\nuse Rubix\\Client\\HTTP\\Middleware\\SharedtokenAuthenticator;\n\n$middleware = new SharedTokenAuthenticator('secret');\n```\n\n## License\nThe code is licensed [MIT](LICENSE) and the documentation is licensed [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubixml%2Fclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubixml%2Fclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubixml%2Fclient/lists"}