autorender 0.1.0__tar.gz

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.
Files changed (96) hide show
  1. autorender-0.1.0/.gitignore +16 -0
  2. autorender-0.1.0/.release-please-manifest.json +3 -0
  3. autorender-0.1.0/CHANGELOG.md +43 -0
  4. autorender-0.1.0/CONTRIBUTING.md +127 -0
  5. autorender-0.1.0/LICENSE +7 -0
  6. autorender-0.1.0/PKG-INFO +438 -0
  7. autorender-0.1.0/README.md +403 -0
  8. autorender-0.1.0/SECURITY.md +27 -0
  9. autorender-0.1.0/api.md +55 -0
  10. autorender-0.1.0/bin/check-release-environment +21 -0
  11. autorender-0.1.0/bin/publish-pypi +6 -0
  12. autorender-0.1.0/examples/.keep +4 -0
  13. autorender-0.1.0/noxfile.py +9 -0
  14. autorender-0.1.0/pyproject.toml +269 -0
  15. autorender-0.1.0/release-please-config.json +66 -0
  16. autorender-0.1.0/requirements-dev.lock +149 -0
  17. autorender-0.1.0/requirements.lock +76 -0
  18. autorender-0.1.0/src/autorender/__init__.py +102 -0
  19. autorender-0.1.0/src/autorender/_base_client.py +2136 -0
  20. autorender-0.1.0/src/autorender/_client.py +623 -0
  21. autorender-0.1.0/src/autorender/_compat.py +226 -0
  22. autorender-0.1.0/src/autorender/_constants.py +14 -0
  23. autorender-0.1.0/src/autorender/_exceptions.py +108 -0
  24. autorender-0.1.0/src/autorender/_files.py +173 -0
  25. autorender-0.1.0/src/autorender/_models.py +952 -0
  26. autorender-0.1.0/src/autorender/_qs.py +149 -0
  27. autorender-0.1.0/src/autorender/_resource.py +43 -0
  28. autorender-0.1.0/src/autorender/_response.py +835 -0
  29. autorender-0.1.0/src/autorender/_streaming.py +338 -0
  30. autorender-0.1.0/src/autorender/_types.py +273 -0
  31. autorender-0.1.0/src/autorender/_utils/__init__.py +64 -0
  32. autorender-0.1.0/src/autorender/_utils/_compat.py +45 -0
  33. autorender-0.1.0/src/autorender/_utils/_datetime_parse.py +136 -0
  34. autorender-0.1.0/src/autorender/_utils/_json.py +35 -0
  35. autorender-0.1.0/src/autorender/_utils/_logs.py +25 -0
  36. autorender-0.1.0/src/autorender/_utils/_path.py +127 -0
  37. autorender-0.1.0/src/autorender/_utils/_proxy.py +65 -0
  38. autorender-0.1.0/src/autorender/_utils/_reflection.py +42 -0
  39. autorender-0.1.0/src/autorender/_utils/_resources_proxy.py +24 -0
  40. autorender-0.1.0/src/autorender/_utils/_streams.py +12 -0
  41. autorender-0.1.0/src/autorender/_utils/_sync.py +58 -0
  42. autorender-0.1.0/src/autorender/_utils/_transform.py +457 -0
  43. autorender-0.1.0/src/autorender/_utils/_typing.py +156 -0
  44. autorender-0.1.0/src/autorender/_utils/_utils.py +433 -0
  45. autorender-0.1.0/src/autorender/_version.py +4 -0
  46. autorender-0.1.0/src/autorender/lib/.keep +4 -0
  47. autorender-0.1.0/src/autorender/pagination.py +74 -0
  48. autorender-0.1.0/src/autorender/py.typed +0 -0
  49. autorender-0.1.0/src/autorender/resources/__init__.py +61 -0
  50. autorender-0.1.0/src/autorender/resources/files.py +457 -0
  51. autorender-0.1.0/src/autorender/resources/folders.py +467 -0
  52. autorender-0.1.0/src/autorender/resources/multipart_uploads.py +302 -0
  53. autorender-0.1.0/src/autorender/resources/uploads.py +401 -0
  54. autorender-0.1.0/src/autorender/types/__init__.py +23 -0
  55. autorender-0.1.0/src/autorender/types/file_list_params.py +21 -0
  56. autorender-0.1.0/src/autorender/types/file_list_response.py +66 -0
  57. autorender-0.1.0/src/autorender/types/file_rename_params.py +12 -0
  58. autorender-0.1.0/src/autorender/types/file_rename_response.py +53 -0
  59. autorender-0.1.0/src/autorender/types/file_retrieve_response.py +53 -0
  60. autorender-0.1.0/src/autorender/types/folder_create_params.py +15 -0
  61. autorender-0.1.0/src/autorender/types/folder_create_response.py +26 -0
  62. autorender-0.1.0/src/autorender/types/folder_list_params.py +17 -0
  63. autorender-0.1.0/src/autorender/types/folder_list_response.py +30 -0
  64. autorender-0.1.0/src/autorender/types/folder_rename_params.py +12 -0
  65. autorender-0.1.0/src/autorender/types/folder_rename_response.py +26 -0
  66. autorender-0.1.0/src/autorender/types/multipart_upload_complete_params.py +13 -0
  67. autorender-0.1.0/src/autorender/types/multipart_upload_complete_response.py +56 -0
  68. autorender-0.1.0/src/autorender/types/multipart_upload_start_params.py +30 -0
  69. autorender-0.1.0/src/autorender/types/multipart_upload_start_response.py +41 -0
  70. autorender-0.1.0/src/autorender/types/upload_create_from_url_params.py +31 -0
  71. autorender-0.1.0/src/autorender/types/upload_create_from_url_response.py +56 -0
  72. autorender-0.1.0/src/autorender/types/upload_create_params.py +38 -0
  73. autorender-0.1.0/src/autorender/types/upload_create_response.py +56 -0
  74. autorender-0.1.0/tests/__init__.py +1 -0
  75. autorender-0.1.0/tests/api_resources/__init__.py +1 -0
  76. autorender-0.1.0/tests/api_resources/test_files.py +336 -0
  77. autorender-0.1.0/tests/api_resources/test_folders.py +334 -0
  78. autorender-0.1.0/tests/api_resources/test_multipart_uploads.py +209 -0
  79. autorender-0.1.0/tests/api_resources/test_uploads.py +215 -0
  80. autorender-0.1.0/tests/conftest.py +84 -0
  81. autorender-0.1.0/tests/sample_file.txt +1 -0
  82. autorender-0.1.0/tests/test_client.py +2000 -0
  83. autorender-0.1.0/tests/test_extract_files.py +91 -0
  84. autorender-0.1.0/tests/test_files.py +148 -0
  85. autorender-0.1.0/tests/test_models.py +1017 -0
  86. autorender-0.1.0/tests/test_qs.py +78 -0
  87. autorender-0.1.0/tests/test_required_args.py +111 -0
  88. autorender-0.1.0/tests/test_response.py +277 -0
  89. autorender-0.1.0/tests/test_streaming.py +250 -0
  90. autorender-0.1.0/tests/test_transform.py +460 -0
  91. autorender-0.1.0/tests/test_utils/test_datetime_parse.py +110 -0
  92. autorender-0.1.0/tests/test_utils/test_json.py +126 -0
  93. autorender-0.1.0/tests/test_utils/test_path.py +89 -0
  94. autorender-0.1.0/tests/test_utils/test_proxy.py +34 -0
  95. autorender-0.1.0/tests/test_utils/test_typing.py +73 -0
  96. autorender-0.1.0/tests/utils.py +167 -0
@@ -0,0 +1,16 @@
1
+ .prism.log
2
+ .stdy.log
3
+ _dev
4
+
5
+ __pycache__
6
+ .mypy_cache
7
+
8
+ dist
9
+
10
+ .venv
11
+ .idea
12
+
13
+ .env
14
+ .envrc
15
+ codegen.log
16
+ Brewfile.lock.json
@@ -0,0 +1,3 @@
1
+ {
2
+ ".": "0.1.0"
3
+ }
@@ -0,0 +1,43 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2026-05-15)
4
+
5
+ Full Changelog: [v0.0.1...v0.1.0](https://github.com/autorenderhq/autorender-python/compare/v0.0.1...v0.1.0)
6
+
7
+ ### Features
8
+
9
+ * **api:** api update ([84d1942](https://github.com/autorenderhq/autorender-python/commit/84d19422bdd7a80d8c0d52fe6bb0e989f7b2abe7))
10
+ * **api:** api update ([9dc8482](https://github.com/autorenderhq/autorender-python/commit/9dc848263fbf6509dd3e84a3a7963a897d14991b))
11
+ * **api:** api update ([04c1163](https://github.com/autorenderhq/autorender-python/commit/04c116350cc7a2f5f288a8fd9febd020083cf536))
12
+ * **api:** api update ([b4d6dbe](https://github.com/autorenderhq/autorender-python/commit/b4d6dbee14ac3e753968ce90388eaf01d2af4b94))
13
+ * **api:** api update ([3932736](https://github.com/autorenderhq/autorender-python/commit/393273609afc67cc8b30d33bb27861edb1e20988))
14
+ * **api:** api update ([58346bd](https://github.com/autorenderhq/autorender-python/commit/58346bdeba4b11a33fd1e63c69fceb432424bdf0))
15
+ * **api:** api update ([7fdb60a](https://github.com/autorenderhq/autorender-python/commit/7fdb60a62af1ae9fd716c3a9939d2cc128bd4a85))
16
+ * **api:** api update ([79c95b0](https://github.com/autorenderhq/autorender-python/commit/79c95b0a55d59e214f0b00936a5b517c0f66ca13))
17
+ * **api:** api update ([b43e6a1](https://github.com/autorenderhq/autorender-python/commit/b43e6a1b4b157808d3ef2606552df4e68c1524e7))
18
+ * **api:** api update ([658511c](https://github.com/autorenderhq/autorender-python/commit/658511ca294a346646139b0c4c5e0f4e151115e4))
19
+ * **internal/types:** support eagerly validating pydantic iterators ([477052f](https://github.com/autorenderhq/autorender-python/commit/477052fa9cd1ff89c96ee4b8febf010851c6501e))
20
+ * support setting headers via env ([749df21](https://github.com/autorenderhq/autorender-python/commit/749df21f7ac657d44cb297707a5ec2506bcb0df9))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * **client:** add missing f-string prefix in file type error message ([0f93e15](https://github.com/autorenderhq/autorender-python/commit/0f93e15723c120a2f409cf2884d085f7966d5d0c))
26
+ * **examples:** use timestamp names and correct response shape in files.py ([b4d13a7](https://github.com/autorenderhq/autorender-python/commit/b4d13a7d72784c4448424db46495c985276773d3))
27
+ * **pagination:** resolve pyright incompatible override for has_next_page ([5cf6e56](https://github.com/autorenderhq/autorender-python/commit/5cf6e565ac0aeecdc5e59b887b1e008892eed1ce))
28
+ * strip Content-Type header for body-less requests; add examples ([c3591d0](https://github.com/autorenderhq/autorender-python/commit/c3591d02910ded15e21a7ed7da402bf149f46857))
29
+ * use correct field name format for multipart file arrays ([f968ef9](https://github.com/autorenderhq/autorender-python/commit/f968ef95330967c6b888ea3fc89c85f12ee926d1))
30
+
31
+
32
+ ### Performance Improvements
33
+
34
+ * **client:** optimize file structure copying in multipart requests ([498d621](https://github.com/autorenderhq/autorender-python/commit/498d621cc46637650c03f1ed9d00749dbcab9c99))
35
+
36
+
37
+ ### Chores
38
+
39
+ * **internal:** more robust bootstrap script ([798e8b7](https://github.com/autorenderhq/autorender-python/commit/798e8b79c22e0173d4f30a80924dcad627cc838f))
40
+ * **internal:** reformat pyproject.toml ([fcc4169](https://github.com/autorenderhq/autorender-python/commit/fcc4169f137c6f4e6305bd0b8133658ad5337aa6))
41
+ * remove examples from SDK (moved to stainless-examples runner) ([12a383e](https://github.com/autorenderhq/autorender-python/commit/12a383e16ab6e856905dd8ce8f3f666ff914c43c))
42
+ * **tests:** bump steady to v0.22.1 ([30a0e81](https://github.com/autorenderhq/autorender-python/commit/30a0e8184adf8271f879cb9e5175ed52404a0043))
43
+ * update SDK settings ([aead4ee](https://github.com/autorenderhq/autorender-python/commit/aead4ee8dd9504134612b1845cd18576b7c58848))
@@ -0,0 +1,127 @@
1
+ ## Setting up the environment
2
+
3
+ ### With Rye
4
+
5
+ We use [Rye](https://rye.astral.sh/) to manage dependencies because it will automatically provision a Python environment with the expected Python version. To set it up, run:
6
+
7
+ ```sh
8
+ $ ./scripts/bootstrap
9
+ ```
10
+
11
+ Or [install Rye manually](https://rye.astral.sh/guide/installation/) and run:
12
+
13
+ ```sh
14
+ $ rye sync --all-features
15
+ ```
16
+
17
+ You can then run scripts using `rye run python script.py` or by activating the virtual environment:
18
+
19
+ ```sh
20
+ # Activate the virtual environment - https://docs.python.org/3/library/venv.html#how-venvs-work
21
+ $ source .venv/bin/activate
22
+
23
+ # now you can omit the `rye run` prefix
24
+ $ python script.py
25
+ ```
26
+
27
+ ### Without Rye
28
+
29
+ Alternatively if you don't want to install `Rye`, you can stick with the standard `pip` setup by ensuring you have the Python version specified in `.python-version`, create a virtual environment however you desire and then install dependencies using this command:
30
+
31
+ ```sh
32
+ $ pip install -r requirements-dev.lock
33
+ ```
34
+
35
+ ## Modifying/Adding code
36
+
37
+ Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
38
+ result in merge conflicts between manual patches and changes from the generator. The generator will never
39
+ modify the contents of the `src/autorender/lib/` and `examples/` directories.
40
+
41
+ ## Adding and running examples
42
+
43
+ All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
44
+
45
+ ```py
46
+ # add an example to examples/<your-example>.py
47
+
48
+ #!/usr/bin/env -S rye run python
49
+
50
+ ```
51
+
52
+ ```sh
53
+ $ chmod +x examples/<your-example>.py
54
+ # run the example against your api
55
+ $ ./examples/<your-example>.py
56
+ ```
57
+
58
+ ## Using the repository from source
59
+
60
+ If you’d like to use the repository from source, you can either install from git or link to a cloned repository:
61
+
62
+ To install via git:
63
+
64
+ ```sh
65
+ $ pip install git+ssh://git@github.com/autorenderhq/autorender-python.git
66
+ ```
67
+
68
+ Alternatively, you can build from source and install the wheel file:
69
+
70
+ Building this package will create two files in the `dist/` directory, a `.tar.gz` containing the source files and a `.whl` that can be used to install the package efficiently.
71
+
72
+ To create a distributable version of the library, all you have to do is run this command:
73
+
74
+ ```sh
75
+ $ rye build
76
+ # or
77
+ $ python -m build
78
+ ```
79
+
80
+ Then to install:
81
+
82
+ ```sh
83
+ $ pip install ./path-to-wheel-file.whl
84
+ ```
85
+
86
+ ## Running tests
87
+
88
+ Most tests require you to [set up a mock server](https://github.com/dgellow/steady) against the OpenAPI spec to run the tests.
89
+
90
+ ```sh
91
+ $ ./scripts/mock
92
+ ```
93
+
94
+ ```sh
95
+ $ ./scripts/test
96
+ ```
97
+
98
+ ## Linting and formatting
99
+
100
+ This repository uses [ruff](https://github.com/astral-sh/ruff) and
101
+ [black](https://github.com/psf/black) to format the code in the repository.
102
+
103
+ To lint:
104
+
105
+ ```sh
106
+ $ ./scripts/lint
107
+ ```
108
+
109
+ To format and fix all ruff issues automatically:
110
+
111
+ ```sh
112
+ $ ./scripts/format
113
+ ```
114
+
115
+ ## Publishing and releases
116
+
117
+ Changes made to this repository via the automated release PR pipeline should publish to PyPI automatically. If
118
+ the changes aren't made through the automated pipeline, you may want to make releases manually.
119
+
120
+ ### Publish with a GitHub workflow
121
+
122
+ You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/autorenderhq/autorender-python/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.
123
+
124
+ ### Publish manually
125
+
126
+ If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on
127
+ the environment.
@@ -0,0 +1,7 @@
1
+ Copyright 2026 autorender
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,438 @@
1
+ Metadata-Version: 2.3
2
+ Name: autorender
3
+ Version: 0.1.0
4
+ Summary: The official Python library for the autorender API
5
+ Project-URL: Homepage, https://github.com/autorenderhq/autorender-python
6
+ Project-URL: Repository, https://github.com/autorenderhq/autorender-python
7
+ Author-email: Autorender <engineering@autorender.io>
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.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.9
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.14
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
+ # Autorender Python API library
37
+
38
+ <!-- prettier-ignore -->
39
+ [![PyPI version](https://img.shields.io/pypi/v/autorender.svg?label=pypi%20(stable))](https://pypi.org/project/autorender/)
40
+
41
+ The Autorender Python library provides convenient access to the Autorender REST API from any Python 3.9+
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 [autorender.mintlify.app](https://autorender.mintlify.app/). The full API of this library can be found in [api.md](https://github.com/autorenderhq/autorender-python/tree/main/api.md).
50
+
51
+ ## Installation
52
+
53
+ ```sh
54
+ # install from PyPI
55
+ pip install autorender
56
+ ```
57
+
58
+ ## Usage
59
+
60
+ The full API of this library can be found in [api.md](https://github.com/autorenderhq/autorender-python/tree/main/api.md).
61
+
62
+ ```python
63
+ import os
64
+ from autorender import Autorender
65
+
66
+ client = Autorender(
67
+ api_key=os.environ.get("AUTORENDER_API_KEY"), # This is the default and can be omitted
68
+ )
69
+
70
+ files = client.files.list(
71
+ limit=10,
72
+ )
73
+ print(files.files)
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 `AUTORENDER_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 `AsyncAutorender` instead of `Autorender` and use `await` with each API call:
84
+
85
+ ```python
86
+ import os
87
+ import asyncio
88
+ from autorender import AsyncAutorender
89
+
90
+ client = AsyncAutorender(
91
+ api_key=os.environ.get("AUTORENDER_API_KEY"), # This is the default and can be omitted
92
+ )
93
+
94
+
95
+ async def main() -> None:
96
+ files = await client.files.list(
97
+ limit=10,
98
+ )
99
+ print(files.files)
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 autorender[aiohttp]
116
+ ```
117
+
118
+ Then you can enable it by instantiating the client with `http_client=DefaultAioHttpClient()`:
119
+
120
+ ```python
121
+ import os
122
+ import asyncio
123
+ from autorender import DefaultAioHttpClient
124
+ from autorender import AsyncAutorender
125
+
126
+
127
+ async def main() -> None:
128
+ async with AsyncAutorender(
129
+ api_key=os.environ.get("AUTORENDER_API_KEY"), # This is the default and can be omitted
130
+ http_client=DefaultAioHttpClient(),
131
+ ) as client:
132
+ files = await client.files.list(
133
+ limit=10,
134
+ )
135
+ print(files.files)
136
+
137
+
138
+ asyncio.run(main())
139
+ ```
140
+
141
+ ## Using types
142
+
143
+ 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:
144
+
145
+ - Serializing back into JSON, `model.to_json()`
146
+ - Converting to a dictionary, `model.to_dict()`
147
+
148
+ 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`.
149
+
150
+ ## File uploads
151
+
152
+ Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
153
+
154
+ ```python
155
+ from pathlib import Path
156
+ from autorender import Autorender
157
+
158
+ client = Autorender()
159
+
160
+ client.uploads.create(
161
+ file=Path("/path/to/file"),
162
+ file_name="product.jpg",
163
+ )
164
+ ```
165
+
166
+ The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
167
+
168
+ ## Handling errors
169
+
170
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `autorender.APIConnectionError` is raised.
171
+
172
+ When the API returns a non-success status code (that is, 4xx or 5xx
173
+ response), a subclass of `autorender.APIStatusError` is raised, containing `status_code` and `response` properties.
174
+
175
+ All errors inherit from `autorender.APIError`.
176
+
177
+ ```python
178
+ import autorender
179
+ from autorender import Autorender
180
+
181
+ client = Autorender()
182
+
183
+ try:
184
+ client.uploads.create(
185
+ file=b"<binary>",
186
+ file_name="photo.jpg",
187
+ )
188
+ except autorender.APIConnectionError as e:
189
+ print("The server could not be reached")
190
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
191
+ except autorender.RateLimitError as e:
192
+ print("A 429 status code was received; we should back off a bit.")
193
+ except autorender.APIStatusError as e:
194
+ print("Another non-200-range status code was received")
195
+ print(e.status_code)
196
+ print(e.response)
197
+ ```
198
+
199
+ Error codes are as follows:
200
+
201
+ | Status Code | Error Type |
202
+ | ----------- | -------------------------- |
203
+ | 400 | `BadRequestError` |
204
+ | 401 | `AuthenticationError` |
205
+ | 403 | `PermissionDeniedError` |
206
+ | 404 | `NotFoundError` |
207
+ | 422 | `UnprocessableEntityError` |
208
+ | 429 | `RateLimitError` |
209
+ | >=500 | `InternalServerError` |
210
+ | N/A | `APIConnectionError` |
211
+
212
+ ### Retries
213
+
214
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
215
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
216
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
217
+
218
+ You can use the `max_retries` option to configure or disable retry settings:
219
+
220
+ ```python
221
+ from autorender import Autorender
222
+
223
+ # Configure the default for all requests:
224
+ client = Autorender(
225
+ # default is 2
226
+ max_retries=0,
227
+ )
228
+
229
+ # Or, configure per-request:
230
+ client.with_options(max_retries=5).uploads.create(
231
+ file=b"<binary>",
232
+ file_name="photo.jpg",
233
+ )
234
+ ```
235
+
236
+ ### Timeouts
237
+
238
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
239
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/timeouts/#fine-tuning-the-configuration) object:
240
+
241
+ ```python
242
+ from autorender import Autorender
243
+
244
+ # Configure the default for all requests:
245
+ client = Autorender(
246
+ # 20 seconds (default is 1 minute)
247
+ timeout=20.0,
248
+ )
249
+
250
+ # More granular control:
251
+ client = Autorender(
252
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
253
+ )
254
+
255
+ # Override per-request:
256
+ client.with_options(timeout=5.0).uploads.create(
257
+ file=b"<binary>",
258
+ file_name="photo.jpg",
259
+ )
260
+ ```
261
+
262
+ On timeout, an `APITimeoutError` is thrown.
263
+
264
+ Note that requests that time out are [retried twice by default](https://github.com/autorenderhq/autorender-python/tree/main/#retries).
265
+
266
+ ## Advanced
267
+
268
+ ### Logging
269
+
270
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
271
+
272
+ You can enable logging by setting the environment variable `AUTORENDER_LOG` to `info`.
273
+
274
+ ```shell
275
+ $ export AUTORENDER_LOG=info
276
+ ```
277
+
278
+ Or to `debug` for more verbose logging.
279
+
280
+ ### How to tell whether `None` means `null` or missing
281
+
282
+ 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`:
283
+
284
+ ```py
285
+ if response.my_field is None:
286
+ if 'my_field' not in response.model_fields_set:
287
+ print('Got json like {}, without a "my_field" key present at all.')
288
+ else:
289
+ print('Got json like {"my_field": null}.')
290
+ ```
291
+
292
+ ### Accessing raw response data (e.g. headers)
293
+
294
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
295
+
296
+ ```py
297
+ from autorender import Autorender
298
+
299
+ client = Autorender()
300
+ response = client.uploads.with_raw_response.create(
301
+ file=b"<binary>",
302
+ file_name="photo.jpg",
303
+ )
304
+ print(response.headers.get('X-My-Header'))
305
+
306
+ upload = response.parse() # get the object that `uploads.create()` would have returned
307
+ print(upload.id)
308
+ ```
309
+
310
+ These methods return an [`APIResponse`](https://github.com/autorenderhq/autorender-python/tree/main/src/autorender/_response.py) object.
311
+
312
+ The async client returns an [`AsyncAPIResponse`](https://github.com/autorenderhq/autorender-python/tree/main/src/autorender/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
313
+
314
+ #### `.with_streaming_response`
315
+
316
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
317
+
318
+ 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.
319
+
320
+ ```python
321
+ with client.uploads.with_streaming_response.create(
322
+ file=b"<binary>",
323
+ file_name="photo.jpg",
324
+ ) as response:
325
+ print(response.headers.get("X-My-Header"))
326
+
327
+ for line in response.iter_lines():
328
+ print(line)
329
+ ```
330
+
331
+ The context manager is required so that the response will reliably be closed.
332
+
333
+ ### Making custom/undocumented requests
334
+
335
+ This library is typed for convenient access to the documented API.
336
+
337
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
338
+
339
+ #### Undocumented endpoints
340
+
341
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
342
+ http verbs. Options on the client will be respected (such as retries) when making this request.
343
+
344
+ ```py
345
+ import httpx
346
+
347
+ response = client.post(
348
+ "/foo",
349
+ cast_to=httpx.Response,
350
+ body={"my_param": True},
351
+ )
352
+
353
+ print(response.headers.get("x-foo"))
354
+ ```
355
+
356
+ #### Undocumented request params
357
+
358
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
359
+ options.
360
+
361
+ #### Undocumented response properties
362
+
363
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
364
+ can also get all the extra fields on the Pydantic model as a dict with
365
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
366
+
367
+ ### Configuring the HTTP client
368
+
369
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
370
+
371
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
372
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
373
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
374
+
375
+ ```python
376
+ import httpx
377
+ from autorender import Autorender, DefaultHttpxClient
378
+
379
+ client = Autorender(
380
+ # Or use the `AUTORENDER_BASE_URL` env var
381
+ base_url="http://my.test.server.example.com:8083",
382
+ http_client=DefaultHttpxClient(
383
+ proxy="http://my.test.proxy.example.com",
384
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
385
+ ),
386
+ )
387
+ ```
388
+
389
+ You can also customize the client on a per-request basis by using `with_options()`:
390
+
391
+ ```python
392
+ client.with_options(http_client=DefaultHttpxClient(...))
393
+ ```
394
+
395
+ ### Managing HTTP resources
396
+
397
+ 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.
398
+
399
+ ```py
400
+ from autorender import Autorender
401
+
402
+ with Autorender() as client:
403
+ # make requests here
404
+ ...
405
+
406
+ # HTTP client is now closed
407
+ ```
408
+
409
+ ## Versioning
410
+
411
+ 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:
412
+
413
+ 1. Changes that only affect static types, without breaking runtime behavior.
414
+ 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.)_
415
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
416
+
417
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
418
+
419
+ We are keen for your feedback; please open an [issue](https://www.github.com/autorenderhq/autorender-python/issues) with questions, bugs, or suggestions.
420
+
421
+ ### Determining the installed version
422
+
423
+ 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.
424
+
425
+ You can determine the version that is being used at runtime with:
426
+
427
+ ```py
428
+ import autorender
429
+ print(autorender.__version__)
430
+ ```
431
+
432
+ ## Requirements
433
+
434
+ Python 3.9 or higher.
435
+
436
+ ## Contributing
437
+
438
+ See [the contributing documentation](https://github.com/autorenderhq/autorender-python/tree/main/./CONTRIBUTING.md).