You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(client): add support for streaming raw responses (#132)
As an alternative to `with_raw_response` we now provide
`with_streaming_response` as well. When using these methods you
will have to use a context manager to ensure that the response is
always cleaned up.
Copy file name to clipboardExpand all lines: README.md
+30-2Lines changed: 30 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -288,7 +288,7 @@ if response.my_field is None:
288
288
289
289
### Accessing raw response data (e.g. headers)
290
290
291
-
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call.
291
+
The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
292
292
293
293
```py
294
294
from orb import Orb
@@ -304,7 +304,35 @@ customer = response.parse() # get the object that `customers.create()` would ha
304
304
print(customer.id)
305
305
```
306
306
307
-
These methods return an [`APIResponse`](https://github.com/orbcorp/orb-python/tree/main/src/orb/_response.py) object.
307
+
These methods return an [`LegacyAPIResponse`](https://github.com/orbcorp/orb-python/tree/main/src/orb/_legacy_response.py) object. This is a legacy class as we're changing it slightly in the next major version.
308
+
309
+
For the sync client this will mostly be the same with the exception
310
+
of `content` & `text` will be methods instead of properties. In the
311
+
async client, all methods will be async.
312
+
313
+
A migration script will be provided & the migration in general should
314
+
be smooth.
315
+
316
+
#### `.with_streaming_response`
317
+
318
+
The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
319
+
320
+
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
321
+
322
+
As such, `.with_streaming_response` methods return a different [`APIResponse`](https://github.com/orbcorp/orb-python/tree/main/src/orb/_response.py) object, and the async client returns an [`AsyncAPIResponse`](https://github.com/orbcorp/orb-python/tree/main/src/orb/_response.py) object.
323
+
324
+
```python
325
+
with client.customers.with_streaming_response.create(
326
+
email="example-customer@withorb.com",
327
+
name="My Customer",
328
+
) as response:
329
+
print(response.headers.get("X-My-Header"))
330
+
331
+
for line in response.iter_lines():
332
+
print(line)
333
+
```
334
+
335
+
The context manager is required so that the response will reliably be closed.
0 commit comments