Skip to content

Commit e0366b0

Browse files
docs: Add client configuration guide and update navigation
- Added `client-configuration.md` detailing setup options for `PdfRestClient` and `AsyncPdfRestClient`, including parameters, timeout configurations, custom HTTPX client usage, and headers. - Updated `index.md` to include links to the new `getting-started.md` and `client-configuration.md` guides. - Modified `mkdocs.yml` to reflect the new navigation structure. Assisted-by: Codex
1 parent 48d67c2 commit e0366b0

3 files changed

Lines changed: 153 additions & 0 deletions

File tree

docs/client-configuration.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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.

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Useful references:
1616
- [pdfRest homepage](https://pdfrest.com/)
1717
- [API reference](https://pdfrest.com/apidocs/)
1818
- [API Lab (interactive testing)](https://pdfrest.com/apilab/)
19+
- [Getting started guide](getting-started.md)
20+
- [Client configuration guide](client-configuration.md)
1921

2022
## How this Python API relates to pdfRest
2123

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ markdown_extensions:
3737
nav:
3838
- Home: index.md
3939
- Getting Started: getting-started.md
40+
- Client Configuration: client-configuration.md
4041
- API Reference: api-reference.md

0 commit comments

Comments
 (0)