Download the PHP package polyzon/polyzon-php without Composer

On this page you can find all versions of the php package polyzon/polyzon-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package polyzon-php

Polyzon PHP SDK

The official PHP client for the Polyzon public API: search 3D models across Thingiverse, Printables, MakerWorld, Cults3D and 20 more sites, and fetch model cards. It needs nothing but ext-curl and ext-json, and comes with immutable typed results, keep-alive connections, parallel batch requests over curl_multi, automatic retries, proxy support and typed exceptions.

Русская версия

Requirements

Installation

Quick start

More in examples/: quick start, pagination, parallel batch, proxy (php examples/quickstart.php after composer install).

Authentication

Every request is authorised with your personal token (pzk_…). Pass it explicitly or set the POLYZON_API_KEY environment variable:

The default is read with getenv(). If your framework loads .env files without putenv() (Symfony Dotenv, for example), pass apiKey: $_ENV['POLYZON_API_KEY']. The constructor validates the token (1–512 visible ASCII characters) and never prints it: var_dump($client) shows pzk_Q7xR….

Usage

All methods are synchronous and take named arguments. Results are immutable readonly objects.

Search

Unset arguments are not sent. Sort, Lang, Source and License hold the known values as constants (plus ALL), but every argument and field is a plain string: new sources appear over time.

Pagination

searchAll takes the same arguments and returns a lazy Generator of items:

It starts at page (default 1) and stops when hasMore is false, a page is empty, or at page 100 (the server's limit). Every page costs one request of the daily quota, so use size: 50 and break as soon as you have enough. Invalid arguments throw at once; request errors are thrown while iterating.

Model card

source and id are the ones from search items. They are validated before any request (source matches ^[a-z0-9]{1,32}$, id matches ^[A-Za-z0-9._-]{1,255}$ and is not . or ..); an invalid value throws InvalidArgumentException.

Many models at once

getModels accepts ModelRef objects, search items, models or [source, id] pairs (any iterable). It runs real parallel transfers over curl_multi, at most concurrency at a time (default 4), and returns one ModelResult per reference in input order. It never throws because of one model: each result holds either model or error, and failed requests are retried like any other. After an AuthenticationException, PermissionDeniedException or QuotaExceededException the references not yet started get that same error without a request. Each model costs one request of the daily quota.

Account and limits

Neither costs daily quota (they still count toward the per-minute limit).

Response metadata

Every result has a meta property:

Errors

Every failed request throws a subclass of Polyzon\Exception\PolyzonException (a RuntimeException):

Exception When
ApiConnectionException network failure: DNS, TCP, TLS, proxy, connection reset
ApiTimeoutException an attempt took longer than timeout (subclass of ApiConnectionException)
InvalidResponseException a 2xx answer whose body is not a JSON object or exceeds 8 MiB
BadRequestException 400: bad_request (see $e->param) or page_too_deep
AuthenticationException 401: unauthorized (no token) or invalid_token (wrong or revoked)
PermissionDeniedException 403 account_action_required: accept the current terms at polyzon.org/account
NotFoundException 404 not_found
GoneException 410 gone: the model was removed at the right holder's request — delete your copy too
RateLimitException 429 rate_limited: more than 20 requests a minute (retried automatically)
QuotaExceededException 429 quota_exceeded: the daily quota is spent until 00:00 UTC (subclass of RateLimitException, never retried)
InternalServerException 5xx: unavailable, internal, edge errors
ApiException any other HTTP error, including an unexpected 3xx (redirects are never followed); base class of the HTTP errors

ApiException has the readonly properties status, errorCode (the stable machine-readable reason, or null; it is not called code because getCode() already returns the HTTP status), title, detail (usually in Russian), param, requestId, retryAfter (seconds or null), headers and body. Its message reads 401 invalid_token: Токен не найден или отозван. (request id …).

Invalid arguments throw the standard InvalidArgumentException before any request; it is not a PolyzonException.

Retries

Failed requests are retried up to maxRetries times (default 2) on connection errors, timeouts, HTTP 500, 502, 503, 504 and 429 rate_limited. The delay is the server's Retry-After when present (seconds or an HTTP date; at most 60 seconds — if the server asks for longer, the error is thrown at once), otherwise exponential backoff min(8 s, 0.5 s × 2^attempt) with jitter. quota_exceeded, a 429 without a code and other 4xx errors are never retried.

Timeouts

timeout limits each attempt (connect + response), in seconds; default 30, of which connecting may take at most 10. A timed-out attempt throws ApiTimeoutException (after the retries).

Proxies

TLS and CA certificates

TLS verification (certificate and host name) is always on and cannot be turned off. Behind a TLS-inspecting corporate proxy, trust its root certificate:

The bundle replaces the default trust store for the API and for an https:// proxy. Without caBundle libcurl uses the system store or the curl.cainfo php.ini setting (on Windows, point curl.cainfo at a cacert.pem if PHP has none).

Concurrency

A client is immutable and keeps connections alive (shared with clients made by withOptions), so create one and reuse it for sequential requests and batches. For parallel requests use getModels, which drives up to concurrency transfers at once over curl_multi with a sliding window.

withOptions accepts apiKey, timeout, maxRetries, userAgent and logger; the base URL, proxy and CA bundle stay those of the original client. Connections close when the last client using them is garbage-collected.

A client must not be shared between threads (ext-parallel, pthreads): give every thread its own client. Clients cannot be serialized either.

Async

PHP has no standard async runtime, so the client is synchronous; getModels covers parallel fetching. In ReactPHP / Amp applications, call it from a worker process or a thread with its own client.

Logging

The logger gets debug lines for every attempt (method, path with query, status, attempt, duration) and warning lines for retries (reason and delay), with the same data in $context. It never gets headers or the token. No PSR package is required.

Rate limits and quota

Check them with $client->limits() or $result->meta->rateLimit (the daily window after the request). QuotaExceededException::$retryAfter tells when the day resets.

Testing your code

Point the client at a local mock: http:// is accepted for localhost, 127.0.0.1 and [::1].

User-Agent

Requests send User-Agent: polyzon-php/1.0.0 (php 8.4.13; linux/x86_64). Add your app with new Polyzon\Client(userAgent: 'my-bot/2.1').

Versioning

This package follows Semantic Versioning. Breaking changes of the public API (the Polyzon\ classes, except Polyzon\Internal\ and members marked @internal) only come with a new major version. Constructors of result classes are internal: new fields may be added in minor versions. See CHANGELOG.md.

Security

Never ship your token to browsers or mobile apps — keep it server-side. Anyone holding it can spend your quota. The client only talks HTTPS (plain http:// is accepted for localhost only), never follows redirects, always verifies TLS, caps response bodies at 8 MiB and keeps the token out of var_dump, print_r, var_export, json_encode and stack traces. Report vulnerabilities as described in SECURITY.md.

Links

If you use the free Polyzon API, it would be great if you mentioned Polyzon (for example, with a link to polyzon.org) on the pages of your project where the API is used.

License

MIT


All versions of polyzon-php with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-curl Version *
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package polyzon/polyzon-php contains the following files

Loading the files please wait ...