tzafon 0.1.4__py3-none-any.whl → 1.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of tzafon might be problematic. Click here for more details.

Files changed (52) hide show
  1. tzafon/__init__.py +114 -2
  2. tzafon/_base_client.py +1995 -0
  3. tzafon/_client.py +403 -0
  4. tzafon/_compat.py +219 -0
  5. tzafon/_constants.py +14 -0
  6. tzafon/_exceptions.py +108 -0
  7. tzafon/_files.py +123 -0
  8. tzafon/_models.py +835 -0
  9. tzafon/_qs.py +150 -0
  10. tzafon/_resource.py +43 -0
  11. tzafon/_response.py +830 -0
  12. tzafon/_streaming.py +333 -0
  13. tzafon/_types.py +260 -0
  14. tzafon/_utils/__init__.py +64 -0
  15. tzafon/_utils/_compat.py +45 -0
  16. tzafon/_utils/_datetime_parse.py +136 -0
  17. tzafon/_utils/_logs.py +25 -0
  18. tzafon/_utils/_proxy.py +65 -0
  19. tzafon/_utils/_reflection.py +42 -0
  20. tzafon/_utils/_resources_proxy.py +24 -0
  21. tzafon/_utils/_streams.py +12 -0
  22. tzafon/_utils/_sync.py +86 -0
  23. tzafon/_utils/_transform.py +457 -0
  24. tzafon/_utils/_typing.py +156 -0
  25. tzafon/_utils/_utils.py +421 -0
  26. tzafon/_version.py +4 -0
  27. tzafon/batch_wrapper.py +102 -0
  28. tzafon/client_extensions.py +61 -0
  29. tzafon/py.typed +0 -0
  30. tzafon/resources/__init__.py +19 -0
  31. tzafon/resources/computers.py +822 -0
  32. tzafon/types/__init__.py +13 -0
  33. tzafon/types/action_result.py +17 -0
  34. tzafon/types/computer_create_params.py +30 -0
  35. tzafon/types/computer_execute_action_params.py +11 -0
  36. tzafon/types/computer_execute_batch_params.py +11 -0
  37. tzafon/types/computer_execute_batch_response.py +8 -0
  38. tzafon/types/computer_keep_alive_response.py +8 -0
  39. tzafon/types/computer_list_response.py +10 -0
  40. tzafon/types/computer_navigate_params.py +11 -0
  41. tzafon/types/computer_response.py +19 -0
  42. tzafon/wrapper.py +102 -0
  43. tzafon-1.4.0.dist-info/METADATA +429 -0
  44. tzafon-1.4.0.dist-info/RECORD +46 -0
  45. {tzafon-0.1.4.dist-info → tzafon-1.4.0.dist-info}/WHEEL +1 -1
  46. tzafon-1.4.0.dist-info/licenses/LICENSE +7 -0
  47. tzafon/_connection.py +0 -49
  48. tzafon/client.py +0 -116
  49. tzafon/exceptions.py +0 -6
  50. tzafon/models.py +0 -99
  51. tzafon-0.1.4.dist-info/METADATA +0 -62
  52. tzafon-0.1.4.dist-info/RECORD +0 -8
@@ -0,0 +1,13 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from .action_result import ActionResult as ActionResult
6
+ from .computer_response import ComputerResponse as ComputerResponse
7
+ from .computer_create_params import ComputerCreateParams as ComputerCreateParams
8
+ from .computer_list_response import ComputerListResponse as ComputerListResponse
9
+ from .computer_navigate_params import ComputerNavigateParams as ComputerNavigateParams
10
+ from .computer_keep_alive_response import ComputerKeepAliveResponse as ComputerKeepAliveResponse
11
+ from .computer_execute_batch_params import ComputerExecuteBatchParams as ComputerExecuteBatchParams
12
+ from .computer_execute_action_params import ComputerExecuteActionParams as ComputerExecuteActionParams
13
+ from .computer_execute_batch_response import ComputerExecuteBatchResponse as ComputerExecuteBatchResponse
@@ -0,0 +1,17 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Dict, Optional
4
+
5
+ from .._models import BaseModel
6
+
7
+ __all__ = ["ActionResult"]
8
+
9
+
10
+ class ActionResult(BaseModel):
11
+ error_message: Optional[str] = None
12
+
13
+ result: Optional[Dict[str, object]] = None
14
+
15
+ status: Optional[str] = None
16
+
17
+ timestamp: Optional[str] = None
@@ -0,0 +1,30 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import TypedDict
6
+
7
+ __all__ = ["ComputerCreateParams", "Display"]
8
+
9
+
10
+ class ComputerCreateParams(TypedDict, total=False):
11
+ context_id: str
12
+
13
+ display: Display
14
+ """TODO: implement"""
15
+
16
+ kind: str
17
+ """\"browser"|"desktop"|"code" etc"""
18
+
19
+ stealth: object
20
+ """TODO: implement"""
21
+
22
+ timeout_seconds: int
23
+
24
+
25
+ class Display(TypedDict, total=False):
26
+ height: int
27
+
28
+ scale: float
29
+
30
+ width: int
@@ -0,0 +1,11 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Required, TypedDict
6
+
7
+ __all__ = ["ComputerExecuteActionParams"]
8
+
9
+
10
+ class ComputerExecuteActionParams(TypedDict, total=False):
11
+ body: Required[object]
@@ -0,0 +1,11 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Required, TypedDict
6
+
7
+ __all__ = ["ComputerExecuteBatchParams"]
8
+
9
+
10
+ class ComputerExecuteBatchParams(TypedDict, total=False):
11
+ body: Required[object]
@@ -0,0 +1,8 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Dict
4
+ from typing_extensions import TypeAlias
5
+
6
+ __all__ = ["ComputerExecuteBatchResponse"]
7
+
8
+ ComputerExecuteBatchResponse: TypeAlias = Dict[str, object]
@@ -0,0 +1,8 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Dict
4
+ from typing_extensions import TypeAlias
5
+
6
+ __all__ = ["ComputerKeepAliveResponse"]
7
+
8
+ ComputerKeepAliveResponse: TypeAlias = Dict[str, object]
@@ -0,0 +1,10 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import List
4
+ from typing_extensions import TypeAlias
5
+
6
+ from .computer_response import ComputerResponse
7
+
8
+ __all__ = ["ComputerListResponse"]
9
+
10
+ ComputerListResponse: TypeAlias = List[ComputerResponse]
@@ -0,0 +1,11 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing_extensions import Required, TypedDict
6
+
7
+ __all__ = ["ComputerNavigateParams"]
8
+
9
+
10
+ class ComputerNavigateParams(TypedDict, total=False):
11
+ body: Required[object]
@@ -0,0 +1,19 @@
1
+ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ from typing import Dict, Optional
4
+
5
+ from .._models import BaseModel
6
+
7
+ __all__ = ["ComputerResponse"]
8
+
9
+
10
+ class ComputerResponse(BaseModel):
11
+ id: Optional[str] = None
12
+
13
+ created_at: Optional[str] = None
14
+
15
+ endpoints: Optional[Dict[str, str]] = None
16
+
17
+ status: Optional[str] = None
18
+
19
+ type: Optional[str] = None
tzafon/wrapper.py ADDED
@@ -0,0 +1,102 @@
1
+ """Custom Computer wrapper for cleaner API - protected from Stainless regeneration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING
6
+
7
+ if TYPE_CHECKING:
8
+ from ._client import Computer as TzafonClient
9
+ from .types.action_result import ActionResult
10
+
11
+ __all__ = ["ComputerWrapper"]
12
+
13
+
14
+ class ComputerWrapper:
15
+ """High-level wrapper for computer automation with clean OOP API."""
16
+
17
+ def __init__(self, client: TzafonClient, computer_id: str) -> None:
18
+ self._client = client
19
+ self.id = computer_id
20
+
21
+ def navigate(self, url: str) -> ActionResult:
22
+ """Navigate to a URL."""
23
+ return self._client.computers.execute_action(
24
+ self.id, body={"action": {"type": "go_to_url", "url": url}}
25
+ )
26
+
27
+ def type(self, text: str) -> ActionResult:
28
+ """Type text."""
29
+ return self._client.computers.execute_action(
30
+ self.id, body={"action": {"type": "type", "text": text}}
31
+ )
32
+
33
+ def click(self, x: int, y: int) -> ActionResult:
34
+ """Click at coordinates."""
35
+ return self._client.computers.execute_action(
36
+ self.id, body={"action": {"type": "click", "x": x, "y": y}}
37
+ )
38
+
39
+ def screenshot(self) -> ActionResult:
40
+ """Take a screenshot."""
41
+ return self._client.computers.execute_action(
42
+ self.id, body={"action": {"type": "screenshot"}}
43
+ )
44
+
45
+ def double_click(self, x: int, y: int) -> ActionResult:
46
+ """Double-click at coordinates."""
47
+ return self._client.computers.execute_action(
48
+ self.id, body={"action": {"type": "double_click", "x": x, "y": y}}
49
+ )
50
+
51
+ def right_click(self, x: int, y: int) -> ActionResult:
52
+ """Right-click at coordinates."""
53
+ return self._client.computers.execute_action(
54
+ self.id, body={"action": {"type": "right_click", "x": x, "y": y}}
55
+ )
56
+
57
+ def drag(self, from_x: int, from_y: int, to_x: int, to_y: int) -> ActionResult:
58
+ """Drag from one position to another."""
59
+ return self._client.computers.execute_action(
60
+ self.id,
61
+ body={
62
+ "action": {
63
+ "type": "drag",
64
+ "x1": from_x,
65
+ "y1": from_y,
66
+ "x2": to_x,
67
+ "y2": to_y,
68
+ }
69
+ },
70
+ )
71
+
72
+ def hotkey(self, *keys: str) -> ActionResult:
73
+ """Press a hotkey combination."""
74
+ return self._client.computers.execute_action(
75
+ self.id, body={"action": {"type": "keypress", "keys": list(keys)}}
76
+ )
77
+
78
+ def scroll(self, direction: str, amount: int = 500) -> ActionResult:
79
+ """Scroll in a direction."""
80
+ dy = amount if direction == "down" else -amount
81
+ return self._client.computers.execute_action(
82
+ self.id, body={"action": {"type": "scroll", "x": 0, "y": 0, "dx": 0, "dy": dy}}
83
+ )
84
+
85
+ def wait(self, seconds: float) -> ActionResult:
86
+ """Wait for a specified time."""
87
+ return self._client.computers.execute_action(
88
+ self.id, body={"action": {"type": "wait", "ms": int(seconds * 1000)}}
89
+ )
90
+
91
+ def terminate(self) -> None:
92
+ """Terminate the computer session."""
93
+ self._client.computers.terminate(self.id)
94
+
95
+ def __enter__(self) -> ComputerWrapper:
96
+ """Context manager entry."""
97
+ return self
98
+
99
+ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
100
+ """Context manager exit - auto cleanup."""
101
+ self.terminate()
102
+
@@ -0,0 +1,429 @@
1
+ Metadata-Version: 2.3
2
+ Name: tzafon
3
+ Version: 1.4.0
4
+ Summary: The official Python library for the computer API
5
+ Project-URL: Homepage, https://github.com/stainless-sdks/computer-python
6
+ Project-URL: Repository, https://github.com/stainless-sdks/computer-python
7
+ Author-email: Computer <atul.gavande@tzafon.ai>
8
+ License: MIT
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: MacOS
12
+ Classifier: Operating System :: Microsoft :: Windows
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Operating System :: POSIX
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.8
25
+ Requires-Dist: anyio<5,>=3.5.0
26
+ Requires-Dist: distro<2,>=1.7.0
27
+ Requires-Dist: httpx<1,>=0.23.0
28
+ Requires-Dist: pydantic<3,>=1.9.0
29
+ Requires-Dist: sniffio
30
+ Requires-Dist: typing-extensions<5,>=4.10
31
+ Provides-Extra: aiohttp
32
+ Requires-Dist: aiohttp; extra == 'aiohttp'
33
+ Requires-Dist: httpx-aiohttp>=0.1.9; extra == 'aiohttp'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # Computer Python API library
37
+
38
+ <!-- prettier-ignore -->
39
+ [![PyPI version](https://img.shields.io/pypi/v/tzafon.svg?label=pypi%20(stable))](https://pypi.org/project/tzafon/)
40
+
41
+ The Computer Python library provides convenient access to the Computer REST API from any Python 3.8+
42
+ application. The library includes type definitions for all request params and response fields,
43
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
44
+
45
+ It is generated with [Stainless](https://www.stainless.com/).
46
+
47
+ ## Documentation
48
+
49
+ The REST API documentation can be found on [docs.tzafon.ai](http://docs.tzafon.ai). The full API of this library can be found in [api.md](https://github.com/stainless-sdks/computer-python/tree/main/api.md).
50
+
51
+ ## Installation
52
+
53
+ ```sh
54
+ # install from PyPI
55
+ pip install tzafon
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ The full API of this library can be found in [api.md](https://github.com/stainless-sdks/computer-python/tree/main/api.md).
61
+
62
+ ```python
63
+ import os
64
+ from tzafon import Computer
65
+
66
+ client = Computer(
67
+ api_key=os.environ.get("TZAFON_API_KEY"), # This is the default and can be omitted
68
+ )
69
+
70
+ computer_response = client.computers.create(
71
+ kind="browser",
72
+ )
73
+ print(computer_response.id)
74
+ ```
75
+
76
+ While you can provide an `api_key` keyword argument,
77
+ we recommend using [python-dotenv](https://pypi.org/project/python-dotenv/)
78
+ to add `TZAFON_API_KEY="My API Key"` to your `.env` file
79
+ so that your API Key is not stored in source control.
80
+
81
+ ## Async usage
82
+
83
+ Simply import `AsyncComputer` instead of `Computer` and use `await` with each API call:
84
+
85
+ ```python
86
+ import os
87
+ import asyncio
88
+ from tzafon import AsyncComputer
89
+
90
+ client = AsyncComputer(
91
+ api_key=os.environ.get("TZAFON_API_KEY"), # This is the default and can be omitted
92
+ )
93
+
94
+
95
+ async def main() -> None:
96
+ computer_response = await client.computers.create(
97
+ kind="browser",
98
+ )
99
+ print(computer_response.id)
100
+
101
+
102
+ asyncio.run(main())
103
+ ```
104
+
105
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
106
+
107
+ ### With aiohttp
108
+
109
+ By default, the async client uses `httpx` for HTTP requests. However, for improved concurrency performance you may also use `aiohttp` as the HTTP backend.
110
+
111
+ You can enable this by installing `aiohttp`:
112
+
113
+ ```sh
114
+ # install from PyPI
115
+ pip install tzafon[aiohttp]
116
+ ```
117
+
118
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
119
+
120
+ ```python
121
+ import asyncio
122
+ from tzafon import DefaultAioHttpClient
123
+ from tzafon import AsyncComputer
124
+
125
+
126
+ async def main() -> None:
127
+ async with AsyncComputer(
128
+ api_key="My API Key",
129
+ http_client=DefaultAioHttpClient(),
130
+ ) as client:
131
+ computer_response = await client.computers.create(
132
+ kind="browser",
133
+ )
134
+ print(computer_response.id)
135
+
136
+
137
+ asyncio.run(main())
138
+ ```
139
+
140
+ ## Using types
141
+
142
+ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typing.html#typing.TypedDict). Responses are [Pydantic models](https://docs.pydantic.dev) which also provide helper methods for things like:
143
+
144
+ - Serializing back into JSON, `model.to_json()`
145
+ - Converting to a dictionary, `model.to_dict()`
146
+
147
+ Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
148
+
149
+ ## Nested params
150
+
151
+ Nested parameters are dictionaries, typed using `TypedDict`, for example:
152
+
153
+ ```python
154
+ from tzafon import Computer
155
+
156
+ client = Computer()
157
+
158
+ computer_response = client.computers.create(
159
+ display={},
160
+ )
161
+ print(computer_response.display)
162
+ ```
163
+
164
+ ## Handling errors
165
+
166
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `tzafon.APIConnectionError` is raised.
167
+
168
+ When the API returns a non-success status code (that is, 4xx or 5xx
169
+ response), a subclass of `tzafon.APIStatusError` is raised, containing `status_code` and `response` properties.
170
+
171
+ All errors inherit from `tzafon.APIError`.
172
+
173
+ ```python
174
+ import tzafon
175
+ from tzafon import Computer
176
+
177
+ client = Computer()
178
+
179
+ try:
180
+ client.computers.create(
181
+ kind="browser",
182
+ )
183
+ except tzafon.APIConnectionError as e:
184
+ print("The server could not be reached")
185
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
186
+ except tzafon.RateLimitError as e:
187
+ print("A 429 status code was received; we should back off a bit.")
188
+ except tzafon.APIStatusError as e:
189
+ print("Another non-200-range status code was received")
190
+ print(e.status_code)
191
+ print(e.response)
192
+ ```
193
+
194
+ Error codes are as follows:
195
+
196
+ | Status Code | Error Type |
197
+ | ----------- | -------------------------- |
198
+ | 400 | `BadRequestError` |
199
+ | 401 | `AuthenticationError` |
200
+ | 403 | `PermissionDeniedError` |
201
+ | 404 | `NotFoundError` |
202
+ | 422 | `UnprocessableEntityError` |
203
+ | 429 | `RateLimitError` |
204
+ | >=500 | `InternalServerError` |
205
+ | N/A | `APIConnectionError` |
206
+
207
+ ### Retries
208
+
209
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
210
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
211
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
212
+
213
+ You can use the `max_retries` option to configure or disable retry settings:
214
+
215
+ ```python
216
+ from tzafon import Computer
217
+
218
+ # Configure the default for all requests:
219
+ client = Computer(
220
+ # default is 2
221
+ max_retries=0,
222
+ )
223
+
224
+ # Or, configure per-request:
225
+ client.with_options(max_retries=5).computers.create(
226
+ kind="browser",
227
+ )
228
+ ```
229
+
230
+ ### Timeouts
231
+
232
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
233
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
234
+
235
+ ```python
236
+ from tzafon import Computer
237
+
238
+ # Configure the default for all requests:
239
+ client = Computer(
240
+ # 20 seconds (default is 1 minute)
241
+ timeout=20.0,
242
+ )
243
+
244
+ # More granular control:
245
+ client = Computer(
246
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
247
+ )
248
+
249
+ # Override per-request:
250
+ client.with_options(timeout=5.0).computers.create(
251
+ kind="browser",
252
+ )
253
+ ```
254
+
255
+ On timeout, an `APITimeoutError` is thrown.
256
+
257
+ Note that requests that time out are [retried twice by default](https://github.com/stainless-sdks/computer-python/tree/main/#retries).
258
+
259
+ ## Advanced
260
+
261
+ ### Logging
262
+
263
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
264
+
265
+ You can enable logging by setting the environment variable `COMPUTER_LOG` to `info`.
266
+
267
+ ```shell
268
+ $ export COMPUTER_LOG=info
269
+ ```
270
+
271
+ Or to `debug` for more verbose logging.
272
+
273
+ ### How to tell whether `None` means `null` or missing
274
+
275
+ In an API response, a field may be explicitly `null`, or missing entirely; in either case, its value is `None` in this library. You can differentiate the two cases with `.model_fields_set`:
276
+
277
+ ```py
278
+ if response.my_field is None:
279
+ if 'my_field' not in response.model_fields_set:
280
+ print('Got json like {}, without a "my_field" key present at all.')
281
+ else:
282
+ print('Got json like {"my_field": null}.')
283
+ ```
284
+
285
+ ### Accessing raw response data (e.g. headers)
286
+
287
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
288
+
289
+ ```py
290
+ from tzafon import Computer
291
+
292
+ client = Computer()
293
+ response = client.computers.with_raw_response.create(
294
+ kind="browser",
295
+ )
296
+ print(response.headers.get('X-My-Header'))
297
+
298
+ computer = response.parse() # get the object that `computers.create()` would have returned
299
+ print(computer.id)
300
+ ```
301
+
302
+ These methods return an [`APIResponse`](https://github.com/atulgavandetzafon/computer-python/tree/main/src/tzafon/_response.py) object.
303
+
304
+ The async client returns an [`AsyncAPIResponse`](https://github.com/atulgavandetzafon/computer-python/tree/main/src/tzafon/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
305
+
306
+ #### `.with_streaming_response`
307
+
308
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
309
+
310
+ 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.
311
+
312
+ ```python
313
+ with client.computers.with_streaming_response.create(
314
+ kind="browser",
315
+ ) as response:
316
+ print(response.headers.get("X-My-Header"))
317
+
318
+ for line in response.iter_lines():
319
+ print(line)
320
+ ```
321
+
322
+ The context manager is required so that the response will reliably be closed.
323
+
324
+ ### Making custom/undocumented requests
325
+
326
+ This library is typed for convenient access to the documented API.
327
+
328
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
329
+
330
+ #### Undocumented endpoints
331
+
332
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
333
+ http verbs. Options on the client will be respected (such as retries) when making this request.
334
+
335
+ ```py
336
+ import httpx
337
+
338
+ response = client.post(
339
+ "/foo",
340
+ cast_to=httpx.Response,
341
+ body={"my_param": True},
342
+ )
343
+
344
+ print(response.headers.get("x-foo"))
345
+ ```
346
+
347
+ #### Undocumented request params
348
+
349
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
350
+ options.
351
+
352
+ #### Undocumented response properties
353
+
354
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
355
+ can also get all the extra fields on the Pydantic model as a dict with
356
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
357
+
358
+ ### Configuring the HTTP client
359
+
360
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
361
+
362
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
363
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
364
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
365
+
366
+ ```python
367
+ import httpx
368
+ from tzafon import Computer, DefaultHttpxClient
369
+
370
+ client = Computer(
371
+ # Or use the `COMPUTER_BASE_URL` env var
372
+ base_url="http://my.test.server.example.com:8083",
373
+ http_client=DefaultHttpxClient(
374
+ proxy="http://my.test.proxy.example.com",
375
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
376
+ ),
377
+ )
378
+ ```
379
+
380
+ You can also customize the client on a per-request basis by using `with_options()`:
381
+
382
+ ```python
383
+ client.with_options(http_client=DefaultHttpxClient(...))
384
+ ```
385
+
386
+ ### Managing HTTP resources
387
+
388
+ By default the library closes underlying HTTP connections whenever the client is [garbage collected](https://docs.python.org/3/reference/datamodel.html#object.__del__). You can manually close the client using the `.close()` method if desired, or with a context manager that closes when exiting.
389
+
390
+ ```py
391
+ from tzafon import Computer
392
+
393
+ with Computer() as client:
394
+ # make requests here
395
+ ...
396
+
397
+ # HTTP client is now closed
398
+ ```
399
+
400
+ ## Versioning
401
+
402
+ This package generally follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions, though certain backwards-incompatible changes may be released as minor versions:
403
+
404
+ 1. Changes that only affect static types, without breaking runtime behavior.
405
+ 2. Changes to library internals which are technically public but not intended or documented for external use. _(Please open a GitHub issue to let us know if you are relying on such internals.)_
406
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
407
+
408
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
409
+
410
+ We are keen for your feedback; please open an [issue](https://www.github.com/atulgavandetzafon/computer-python/issues) with questions, bugs, or suggestions.
411
+
412
+ ### Determining the installed version
413
+
414
+ If you've upgraded to the latest version but aren't seeing any new features you were expecting then your python environment is likely still using an older version.
415
+
416
+ You can determine the version that is being used at runtime with:
417
+
418
+ ```py
419
+ import tzafon
420
+ print(tzafon.__version__)
421
+ ```
422
+
423
+ ## Requirements
424
+
425
+ Python 3.8 or higher.
426
+
427
+ ## Contributing
428
+
429
+ See [the contributing documentation](https://github.com/stainless-sdks/computer-python/tree/main/./CONTRIBUTING.md).