|
| 1 | +# Client configuration |
| 2 | + |
| 3 | +This guide explains how to configure |
| 4 | +[`PdfRestClient`](api-reference.md#pdfrest.PdfRestClient) and |
| 5 | +[`AsyncPdfRestClient`](api-reference.md#pdfrest.AsyncPdfRestClient), including |
| 6 | +how SDK settings map to HTTPX behavior. |
| 7 | + |
| 8 | +## Constructor parameters |
| 9 | + |
| 10 | +Both clients support a shared baseline: |
| 11 | + |
| 12 | +- `api_key`: API key used for the `Api-Key` header. If omitted, the SDK reads |
| 13 | + `PDFREST_API_KEY` from the environment. |
| 14 | +- `base_url`: API host (defaults to `https://api.pdfrest.com`). |
| 15 | +- `timeout`: `float` seconds or an |
| 16 | + [`httpx.Timeout`](https://www.python-httpx.org/api/#timeout) object. |
| 17 | +- `headers`: default headers merged into every request. |
| 18 | +- `max_retries`: retry count for retryable transport/timeouts and retryable |
| 19 | + HTTP status responses. |
| 20 | + |
| 21 | +Sync-only options ([`PdfRestClient`](api-reference.md#pdfrest.PdfRestClient)): |
| 22 | + |
| 23 | +- `http_client`: preconfigured |
| 24 | + [`httpx.Client`](https://www.python-httpx.org/api/#client) instance to reuse. |
| 25 | +- `transport`: custom |
| 26 | + [`httpx.BaseTransport`](https://www.python-httpx.org/advanced/transports/). |
| 27 | + |
| 28 | +Async-only options |
| 29 | +([`AsyncPdfRestClient`](api-reference.md#pdfrest.AsyncPdfRestClient)): |
| 30 | + |
| 31 | +- `http_client`: preconfigured |
| 32 | + [`httpx.AsyncClient`](https://www.python-httpx.org/api/#asyncclient) instance |
| 33 | + to reuse. |
| 34 | +- `transport`: custom |
| 35 | + [`httpx.AsyncBaseTransport`](https://www.python-httpx.org/advanced/transports/). |
| 36 | +- `concurrency_limit`: controls async file-info fetch fanout in multi-file |
| 37 | + operations. |
| 38 | + |
| 39 | +## Timeout configuration |
| 40 | + |
| 41 | +By default, the SDK uses an HTTPX timeout profile with a longer read timeout. |
| 42 | +You can override with either a single float or a full timeout object: |
| 43 | + |
| 44 | +```python |
| 45 | +import httpx |
| 46 | +from pdfrest import PdfRestClient |
| 47 | + |
| 48 | +with PdfRestClient( |
| 49 | + timeout=httpx.Timeout(connect=5.0, read=180.0, write=30.0, pool=10.0) |
| 50 | +) as client: |
| 51 | + status = client.up() |
| 52 | +``` |
| 53 | + |
| 54 | +HTTPX references: |
| 55 | + |
| 56 | +- [Timeouts](https://www.python-httpx.org/advanced/timeouts/) |
| 57 | +- [API reference: `httpx.Timeout`](https://www.python-httpx.org/api/) |
| 58 | + |
| 59 | +## Using a custom HTTPX client |
| 60 | + |
| 61 | +If you need advanced HTTP behavior (custom TLS, proxies, limits, event hooks, |
| 62 | +or a shared connection pool), provide a preconfigured HTTPX client. |
| 63 | + |
| 64 | +```python |
| 65 | +import httpx |
| 66 | +from pdfrest import PdfRestClient |
| 67 | + |
| 68 | +http_client = httpx.Client( |
| 69 | + timeout=httpx.Timeout(20.0), |
| 70 | + limits=httpx.Limits(max_connections=20, max_keepalive_connections=10), |
| 71 | +) |
| 72 | + |
| 73 | +with PdfRestClient(http_client=http_client) as client: |
| 74 | + response = client.up() |
| 75 | +``` |
| 76 | + |
| 77 | +HTTPX references: |
| 78 | + |
| 79 | +- [Clients](https://www.python-httpx.org/advanced/clients/) |
| 80 | +- [Resource Limits](https://www.python-httpx.org/advanced/resource-limits/) |
| 81 | +- [Proxies](https://www.python-httpx.org/advanced/proxies/) |
| 82 | +- [SSL](https://www.python-httpx.org/advanced/ssl/) |
| 83 | +- [Event Hooks](https://www.python-httpx.org/advanced/event-hooks/) |
| 84 | + |
| 85 | +## Using a custom transport |
| 86 | + |
| 87 | +For low-level customization (for example test transports and custom routing), |
| 88 | +pass `transport=...`: |
| 89 | + |
| 90 | +```python |
| 91 | +import httpx |
| 92 | +from pdfrest import PdfRestClient |
| 93 | + |
| 94 | +transport = httpx.HTTPTransport(retries=0) |
| 95 | + |
| 96 | +with PdfRestClient(transport=transport) as client: |
| 97 | + response = client.up() |
| 98 | +``` |
| 99 | + |
| 100 | +HTTPX reference: |
| 101 | + |
| 102 | +- [Transports](https://www.python-httpx.org/advanced/transports/) |
| 103 | + |
| 104 | +## Default and per-request headers |
| 105 | + |
| 106 | +`headers=` on the client sets default headers for all calls. Endpoint methods |
| 107 | +also accept `extra_headers=` to override or add request-specific headers. |
| 108 | + |
| 109 | +```python |
| 110 | +from pdfrest import PdfRestClient |
| 111 | + |
| 112 | +with PdfRestClient(headers={"X-App-Name": "my-service"}) as client: |
| 113 | + info = client.up(extra_headers={"X-Request-ID": "req-123"}) |
| 114 | +``` |
| 115 | + |
| 116 | +## `no-id-prefix` header |
| 117 | + |
| 118 | +pdfRest supports a `no-id-prefix: true` request header used for |
| 119 | +pdfAssistant compatibility. In the server implementation (`../PDFCloud-API/apis/security.js`), |
| 120 | +this causes generated IDs to omit the leading numeric prefix and return a plain |
| 121 | +UUIDv4 string. |
| 122 | + |
| 123 | +### How to enable it |
| 124 | + |
| 125 | +Set it as a default client header or per-request `extra_headers`: |
| 126 | + |
| 127 | +```python |
| 128 | +from pdfrest import PdfRestClient |
| 129 | + |
| 130 | +with PdfRestClient(headers={"no-id-prefix": "true"}) as client: |
| 131 | + uploaded = client.files.create_from_paths(["./input.pdf"]) |
| 132 | +``` |
| 133 | + |
| 134 | +### Effect on `PdfRestFileID` |
| 135 | + |
| 136 | +[`PdfRestFileID`](api-reference.md#pdfrest.models.PdfRestFileID) accepts both |
| 137 | +forms: |
| 138 | + |
| 139 | +- prefixed: `1<uuid-v4>` or `2<uuid-v4>` (37 chars) |
| 140 | +- no prefix: `<uuid-v4>` (36 chars) |
| 141 | + |
| 142 | +When `no-id-prefix` is enabled, returned IDs are the 36-character no-prefix |
| 143 | +variant. In that case: |
| 144 | + |
| 145 | +- `file_id.prefix` is `None` |
| 146 | +- `file_id.uuid` is still the UUID portion |
| 147 | + |
| 148 | +This means existing SDK code that uses |
| 149 | +[`PdfRestFileID`](api-reference.md#pdfrest.models.PdfRestFileID) remains |
| 150 | +compatible with either server ID format. |
0 commit comments