hubmap-search-sdk 1.0.0a1__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 (95) hide show
  1. hubmap_search_sdk-1.0.0a1/.gitignore +16 -0
  2. hubmap_search_sdk-1.0.0a1/.release-please-manifest.json +3 -0
  3. hubmap_search_sdk-1.0.0a1/CHANGELOG.md +31 -0
  4. hubmap_search_sdk-1.0.0a1/CONTRIBUTING.md +129 -0
  5. hubmap_search_sdk-1.0.0a1/LICENSE +7 -0
  6. hubmap_search_sdk-1.0.0a1/PKG-INFO +355 -0
  7. hubmap_search_sdk-1.0.0a1/README.md +324 -0
  8. hubmap_search_sdk-1.0.0a1/SECURITY.md +27 -0
  9. hubmap_search_sdk-1.0.0a1/api.md +105 -0
  10. hubmap_search_sdk-1.0.0a1/bin/check-release-environment +21 -0
  11. hubmap_search_sdk-1.0.0a1/bin/publish-pypi +6 -0
  12. hubmap_search_sdk-1.0.0a1/examples/.keep +4 -0
  13. hubmap_search_sdk-1.0.0a1/mypy.ini +50 -0
  14. hubmap_search_sdk-1.0.0a1/noxfile.py +9 -0
  15. hubmap_search_sdk-1.0.0a1/pyproject.toml +206 -0
  16. hubmap_search_sdk-1.0.0a1/release-please-config.json +66 -0
  17. hubmap_search_sdk-1.0.0a1/requirements-dev.lock +104 -0
  18. hubmap_search_sdk-1.0.0a1/requirements.lock +45 -0
  19. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/__init__.py +94 -0
  20. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_base_client.py +1969 -0
  21. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_client.py +464 -0
  22. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_compat.py +219 -0
  23. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_constants.py +14 -0
  24. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_exceptions.py +108 -0
  25. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_files.py +123 -0
  26. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_models.py +804 -0
  27. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_qs.py +150 -0
  28. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_resource.py +43 -0
  29. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_response.py +832 -0
  30. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_streaming.py +333 -0
  31. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_types.py +217 -0
  32. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/__init__.py +57 -0
  33. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_logs.py +25 -0
  34. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_proxy.py +62 -0
  35. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_reflection.py +42 -0
  36. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_streams.py +12 -0
  37. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_sync.py +86 -0
  38. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_transform.py +402 -0
  39. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_typing.py +149 -0
  40. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_utils/_utils.py +414 -0
  41. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/_version.py +4 -0
  42. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/lib/.keep +4 -0
  43. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/py.typed +0 -0
  44. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/__init__.py +145 -0
  45. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/add.py +367 -0
  46. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/clear_docs.py +342 -0
  47. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/indices.py +145 -0
  48. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/mapping.py +212 -0
  49. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/mget.py +265 -0
  50. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/param_search.py +197 -0
  51. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/reindex.py +164 -0
  52. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/scroll_search.py +181 -0
  53. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/search.py +313 -0
  54. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/resources/update.py +367 -0
  55. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/__init__.py +23 -0
  56. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/add_create_document_params.py +11 -0
  57. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/add_create_document_with_index_params.py +13 -0
  58. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/add_update_document_with_scope_params.py +15 -0
  59. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/index_list_response.py +11 -0
  60. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/mget_retrieve_multiple_by_index_params.py +11 -0
  61. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/mget_retrieve_multiple_params.py +11 -0
  62. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/param_search_execute_params.py +18 -0
  63. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/scroll_search_create_params.py +11 -0
  64. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/search_execute_index_query_params.py +20 -0
  65. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/search_execute_query_params.py +20 -0
  66. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/update_update_document_at_index_params.py +13 -0
  67. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/update_update_document_params.py +11 -0
  68. hubmap_search_sdk-1.0.0a1/src/hubmap_search_sdk/types/update_update_document_with_scope_params.py +15 -0
  69. hubmap_search_sdk-1.0.0a1/tests/__init__.py +1 -0
  70. hubmap_search_sdk-1.0.0a1/tests/api_resources/__init__.py +1 -0
  71. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_add.py +1746 -0
  72. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_clear_docs.py +336 -0
  73. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_indices.py +78 -0
  74. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_mapping.py +161 -0
  75. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_mget.py +185 -0
  76. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_param_search.py +123 -0
  77. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_reindex.py +104 -0
  78. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_scroll_search.py +136 -0
  79. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_search.py +345 -0
  80. hubmap_search_sdk-1.0.0a1/tests/api_resources/test_update.py +1746 -0
  81. hubmap_search_sdk-1.0.0a1/tests/conftest.py +53 -0
  82. hubmap_search_sdk-1.0.0a1/tests/sample_file.txt +1 -0
  83. hubmap_search_sdk-1.0.0a1/tests/test_client.py +1671 -0
  84. hubmap_search_sdk-1.0.0a1/tests/test_deepcopy.py +58 -0
  85. hubmap_search_sdk-1.0.0a1/tests/test_extract_files.py +64 -0
  86. hubmap_search_sdk-1.0.0a1/tests/test_files.py +51 -0
  87. hubmap_search_sdk-1.0.0a1/tests/test_models.py +888 -0
  88. hubmap_search_sdk-1.0.0a1/tests/test_qs.py +78 -0
  89. hubmap_search_sdk-1.0.0a1/tests/test_required_args.py +111 -0
  90. hubmap_search_sdk-1.0.0a1/tests/test_response.py +277 -0
  91. hubmap_search_sdk-1.0.0a1/tests/test_streaming.py +254 -0
  92. hubmap_search_sdk-1.0.0a1/tests/test_transform.py +434 -0
  93. hubmap_search_sdk-1.0.0a1/tests/test_utils/test_proxy.py +23 -0
  94. hubmap_search_sdk-1.0.0a1/tests/test_utils/test_typing.py +73 -0
  95. hubmap_search_sdk-1.0.0a1/tests/utils.py +159 -0
@@ -0,0 +1,16 @@
1
+ .prism.log
2
+ .vscode
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
+ ".": "1.0.0-alpha.1"
3
+ }
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0-alpha.1 (2025-04-02)
4
+
5
+ Full Changelog: [v0.0.1-alpha.0...v1.0.0-alpha.1](https://github.com/hubmapconsortium/search-python-sdk/compare/v0.0.1-alpha.0...v1.0.0-alpha.1)
6
+
7
+ ### Features
8
+
9
+ * **api:** manual updates ([#11](https://github.com/hubmapconsortium/search-python-sdk/issues/11)) ([76597b5](https://github.com/hubmapconsortium/search-python-sdk/commit/76597b5ad8f49d88da941d179a9495572144642c))
10
+ * **api:** manual updates ([#12](https://github.com/hubmapconsortium/search-python-sdk/issues/12)) ([b3d6313](https://github.com/hubmapconsortium/search-python-sdk/commit/b3d6313ecae9e916026210e4f94e3a7b876d1bbf))
11
+ * **api:** manual updates ([#13](https://github.com/hubmapconsortium/search-python-sdk/issues/13)) ([fc259f2](https://github.com/hubmapconsortium/search-python-sdk/commit/fc259f27fa9afd4695acf8dfffac6fa47a5b6545))
12
+ * **api:** manual updates ([#14](https://github.com/hubmapconsortium/search-python-sdk/issues/14)) ([bfa831e](https://github.com/hubmapconsortium/search-python-sdk/commit/bfa831ea00491960b41f20fd2ea0852233839875))
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * **ci:** ensure pip is always available ([#9](https://github.com/hubmapconsortium/search-python-sdk/issues/9)) ([524119b](https://github.com/hubmapconsortium/search-python-sdk/commit/524119ba0c28d35a9b229d96ff1bb9f717f56eff))
18
+ * **ci:** remove publishing patch ([#10](https://github.com/hubmapconsortium/search-python-sdk/issues/10)) ([8568269](https://github.com/hubmapconsortium/search-python-sdk/commit/8568269a1f203dd0a2f3a4c9f20e021ca1897614))
19
+ * pluralize `list` response variables ([0648111](https://github.com/hubmapconsortium/search-python-sdk/commit/06481110f2020316049a4dfcda461248afddc577))
20
+ * **types:** handle more discriminated union shapes ([#7](https://github.com/hubmapconsortium/search-python-sdk/issues/7)) ([86b7241](https://github.com/hubmapconsortium/search-python-sdk/commit/86b72413d22db458c881b045c5cd5734c32c1c5d))
21
+
22
+
23
+ ### Chores
24
+
25
+ * fix typos ([7d4c98c](https://github.com/hubmapconsortium/search-python-sdk/commit/7d4c98c8fab9cdb99f32d822c9776ac7154175bc))
26
+ * go live ([#1](https://github.com/hubmapconsortium/search-python-sdk/issues/1)) ([651687d](https://github.com/hubmapconsortium/search-python-sdk/commit/651687d9d2beb26ffb9f820d51c54dedb56fdf10))
27
+ * **internal:** bump rye to 0.44.0 ([#6](https://github.com/hubmapconsortium/search-python-sdk/issues/6)) ([299dfde](https://github.com/hubmapconsortium/search-python-sdk/commit/299dfde0beafe703585cb9947bf96ac2672a956b))
28
+ * **internal:** codegen related update ([b51e083](https://github.com/hubmapconsortium/search-python-sdk/commit/b51e083df6c00c80bd990001e9592eff35397d8e))
29
+ * **internal:** codegen related update ([#5](https://github.com/hubmapconsortium/search-python-sdk/issues/5)) ([5036848](https://github.com/hubmapconsortium/search-python-sdk/commit/503684874f704aa140f575289faaf7147390ce5f))
30
+ * **internal:** remove extra empty newlines ([#4](https://github.com/hubmapconsortium/search-python-sdk/issues/4)) ([7202499](https://github.com/hubmapconsortium/search-python-sdk/commit/7202499f89b6c27072c87e383859de1a2f895a95))
31
+ * update SDK settings ([#3](https://github.com/hubmapconsortium/search-python-sdk/issues/3)) ([0efe09c](https://github.com/hubmapconsortium/search-python-sdk/commit/0efe09c48f70468cf184847fdb58b729972ffac1))
@@ -0,0 +1,129 @@
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
+ $ rye shell
21
+ # or manually activate - https://docs.python.org/3/library/venv.html#how-venvs-work
22
+ $ source .venv/bin/activate
23
+
24
+ # now you can omit the `rye run` prefix
25
+ $ python script.py
26
+ ```
27
+
28
+ ### Without Rye
29
+
30
+ 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:
31
+
32
+ ```sh
33
+ $ pip install -r requirements-dev.lock
34
+ ```
35
+
36
+ ## Modifying/Adding code
37
+
38
+ Most of the SDK is generated code. Modifications to code will be persisted between generations, but may
39
+ result in merge conflicts between manual patches and changes from the generator. The generator will never
40
+ modify the contents of the `src/hubmap_search_sdk/lib/` and `examples/` directories.
41
+
42
+ ## Adding and running examples
43
+
44
+ All files in the `examples/` directory are not modified by the generator and can be freely edited or added to.
45
+
46
+ ```py
47
+ # add an example to examples/<your-example>.py
48
+
49
+ #!/usr/bin/env -S rye run python
50
+
51
+ ```
52
+
53
+ ```sh
54
+ $ chmod +x examples/<your-example>.py
55
+ # run the example against your api
56
+ $ ./examples/<your-example>.py
57
+ ```
58
+
59
+ ## Using the repository from source
60
+
61
+ If you’d like to use the repository from source, you can either install from git or link to a cloned repository:
62
+
63
+ To install via git:
64
+
65
+ ```sh
66
+ $ pip install git+ssh://git@github.com/hubmapconsortium/search-python-sdk.git
67
+ ```
68
+
69
+ Alternatively, you can build from source and install the wheel file:
70
+
71
+ 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.
72
+
73
+ To create a distributable version of the library, all you have to do is run this command:
74
+
75
+ ```sh
76
+ $ rye build
77
+ # or
78
+ $ python -m build
79
+ ```
80
+
81
+ Then to install:
82
+
83
+ ```sh
84
+ $ pip install ./path-to-wheel-file.whl
85
+ ```
86
+
87
+ ## Running tests
88
+
89
+ Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
90
+
91
+ ```sh
92
+ # you will need npm installed
93
+ $ npx prism mock path/to/your/openapi.yml
94
+ ```
95
+
96
+ ```sh
97
+ $ ./scripts/test
98
+ ```
99
+
100
+ ## Linting and formatting
101
+
102
+ This repository uses [ruff](https://github.com/astral-sh/ruff) and
103
+ [black](https://github.com/psf/black) to format the code in the repository.
104
+
105
+ To lint:
106
+
107
+ ```sh
108
+ $ ./scripts/lint
109
+ ```
110
+
111
+ To format and fix all ruff issues automatically:
112
+
113
+ ```sh
114
+ $ ./scripts/format
115
+ ```
116
+
117
+ ## Publishing and releases
118
+
119
+ Changes made to this repository via the automated release PR pipeline should publish to PyPI automatically. If
120
+ the changes aren't made through the automated pipeline, you may want to make releases manually.
121
+
122
+ ### Publish with a GitHub workflow
123
+
124
+ You can release to package managers by using [the `Publish PyPI` GitHub action](https://www.github.com/hubmapconsortium/search-python-sdk/actions/workflows/publish-pypi.yml). This requires a setup organization or repository secret to be set up.
125
+
126
+ ### Publish manually
127
+
128
+ If you need to manually release a package, you can run the `bin/publish-pypi` script with a `PYPI_TOKEN` set on
129
+ the environment.
@@ -0,0 +1,7 @@
1
+ Copyright 2025 hubmap-search-sdk
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,355 @@
1
+ Metadata-Version: 2.3
2
+ Name: hubmap_search_sdk
3
+ Version: 1.0.0a1
4
+ Summary: The official Python library for the hubmap-search-sdk API
5
+ Project-URL: Homepage, https://github.com/hubmapconsortium/search-python-sdk
6
+ Project-URL: Repository, https://github.com/hubmapconsortium/search-python-sdk
7
+ Author-email: Hubmap Search SDK <help@hubmapconsortium.org>
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: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.8
24
+ Requires-Dist: anyio<5,>=3.5.0
25
+ Requires-Dist: distro<2,>=1.7.0
26
+ Requires-Dist: httpx<1,>=0.23.0
27
+ Requires-Dist: pydantic<3,>=1.9.0
28
+ Requires-Dist: sniffio
29
+ Requires-Dist: typing-extensions<5,>=4.10
30
+ Description-Content-Type: text/markdown
31
+
32
+ # Hubmap Search SDK Python API library
33
+
34
+ [![PyPI version](https://img.shields.io/pypi/v/hubmap_search_sdk.svg)](https://pypi.org/project/hubmap_search_sdk/)
35
+
36
+ The Hubmap Search SDK Python library provides convenient access to the Hubmap Search SDK REST API from any Python 3.8+
37
+ application. The library includes type definitions for all request params and response fields,
38
+ and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
39
+
40
+ It is generated with [Stainless](https://www.stainless.com/).
41
+
42
+ ## Documentation
43
+
44
+ The REST API documentation can be found on [docs.hubmapconsortium.org](https://docs.hubmapconsortium.org/clt/generate-manifest.html). The full API of this library can be found in [api.md](https://github.com/hubmapconsortium/search-python-sdk/tree/main/api.md).
45
+
46
+ ## Installation
47
+
48
+ ```sh
49
+ # install from PyPI
50
+ pip install --pre hubmap_search_sdk
51
+ ```
52
+
53
+ ## Usage
54
+
55
+ The full API of this library can be found in [api.md](https://github.com/hubmapconsortium/search-python-sdk/tree/main/api.md).
56
+
57
+ ```python
58
+ from hubmap_search_sdk import HubmapSearchSDK
59
+
60
+ client = HubmapSearchSDK(
61
+ bearer_token="My Bearer Token",
62
+ )
63
+
64
+ indices = client.indices.list()
65
+ print(indices.indices)
66
+ ```
67
+
68
+ ## Async usage
69
+
70
+ Simply import `AsyncHubmapSearchSDK` instead of `HubmapSearchSDK` and use `await` with each API call:
71
+
72
+ ```python
73
+ import asyncio
74
+ from hubmap_search_sdk import AsyncHubmapSearchSDK
75
+
76
+ client = AsyncHubmapSearchSDK(
77
+ bearer_token="My Bearer Token",
78
+ )
79
+
80
+
81
+ async def main() -> None:
82
+ indices = await client.indices.list()
83
+ print(indices.indices)
84
+
85
+
86
+ asyncio.run(main())
87
+ ```
88
+
89
+ Functionality between the synchronous and asynchronous clients is otherwise identical.
90
+
91
+ ## Using types
92
+
93
+ 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:
94
+
95
+ - Serializing back into JSON, `model.to_json()`
96
+ - Converting to a dictionary, `model.to_dict()`
97
+
98
+ 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`.
99
+
100
+ ## Handling errors
101
+
102
+ When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `hubmap_search_sdk.APIConnectionError` is raised.
103
+
104
+ When the API returns a non-success status code (that is, 4xx or 5xx
105
+ response), a subclass of `hubmap_search_sdk.APIStatusError` is raised, containing `status_code` and `response` properties.
106
+
107
+ All errors inherit from `hubmap_search_sdk.APIError`.
108
+
109
+ ```python
110
+ import hubmap_search_sdk
111
+ from hubmap_search_sdk import HubmapSearchSDK
112
+
113
+ client = HubmapSearchSDK()
114
+
115
+ try:
116
+ client.indices.list()
117
+ except hubmap_search_sdk.APIConnectionError as e:
118
+ print("The server could not be reached")
119
+ print(e.__cause__) # an underlying Exception, likely raised within httpx.
120
+ except hubmap_search_sdk.RateLimitError as e:
121
+ print("A 429 status code was received; we should back off a bit.")
122
+ except hubmap_search_sdk.APIStatusError as e:
123
+ print("Another non-200-range status code was received")
124
+ print(e.status_code)
125
+ print(e.response)
126
+ ```
127
+
128
+ Error codes are as follows:
129
+
130
+ | Status Code | Error Type |
131
+ | ----------- | -------------------------- |
132
+ | 400 | `BadRequestError` |
133
+ | 401 | `AuthenticationError` |
134
+ | 403 | `PermissionDeniedError` |
135
+ | 404 | `NotFoundError` |
136
+ | 422 | `UnprocessableEntityError` |
137
+ | 429 | `RateLimitError` |
138
+ | >=500 | `InternalServerError` |
139
+ | N/A | `APIConnectionError` |
140
+
141
+ ### Retries
142
+
143
+ Certain errors are automatically retried 2 times by default, with a short exponential backoff.
144
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict,
145
+ 429 Rate Limit, and >=500 Internal errors are all retried by default.
146
+
147
+ You can use the `max_retries` option to configure or disable retry settings:
148
+
149
+ ```python
150
+ from hubmap_search_sdk import HubmapSearchSDK
151
+
152
+ # Configure the default for all requests:
153
+ client = HubmapSearchSDK(
154
+ # default is 2
155
+ max_retries=0,
156
+ )
157
+
158
+ # Or, configure per-request:
159
+ client.with_options(max_retries=5).indices.list()
160
+ ```
161
+
162
+ ### Timeouts
163
+
164
+ By default requests time out after 1 minute. You can configure this with a `timeout` option,
165
+ which accepts a float or an [`httpx.Timeout`](https://www.python-httpx.org/advanced/#fine-tuning-the-configuration) object:
166
+
167
+ ```python
168
+ from hubmap_search_sdk import HubmapSearchSDK
169
+
170
+ # Configure the default for all requests:
171
+ client = HubmapSearchSDK(
172
+ # 20 seconds (default is 1 minute)
173
+ timeout=20.0,
174
+ )
175
+
176
+ # More granular control:
177
+ client = HubmapSearchSDK(
178
+ timeout=httpx.Timeout(60.0, read=5.0, write=10.0, connect=2.0),
179
+ )
180
+
181
+ # Override per-request:
182
+ client.with_options(timeout=5.0).indices.list()
183
+ ```
184
+
185
+ On timeout, an `APITimeoutError` is thrown.
186
+
187
+ Note that requests that time out are [retried twice by default](https://github.com/hubmapconsortium/search-python-sdk/tree/main/#retries).
188
+
189
+ ## Advanced
190
+
191
+ ### Logging
192
+
193
+ We use the standard library [`logging`](https://docs.python.org/3/library/logging.html) module.
194
+
195
+ You can enable logging by setting the environment variable `HUBMAP_SEARCH_SDK_LOG` to `info`.
196
+
197
+ ```shell
198
+ $ export HUBMAP_SEARCH_SDK_LOG=info
199
+ ```
200
+
201
+ Or to `debug` for more verbose logging.
202
+
203
+ ### How to tell whether `None` means `null` or missing
204
+
205
+ 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`:
206
+
207
+ ```py
208
+ if response.my_field is None:
209
+ if 'my_field' not in response.model_fields_set:
210
+ print('Got json like {}, without a "my_field" key present at all.')
211
+ else:
212
+ print('Got json like {"my_field": null}.')
213
+ ```
214
+
215
+ ### Accessing raw response data (e.g. headers)
216
+
217
+ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to any HTTP method call, e.g.,
218
+
219
+ ```py
220
+ from hubmap_search_sdk import HubmapSearchSDK
221
+
222
+ client = HubmapSearchSDK()
223
+ response = client.indices.with_raw_response.list()
224
+ print(response.headers.get('X-My-Header'))
225
+
226
+ index = response.parse() # get the object that `indices.list()` would have returned
227
+ print(index.indices)
228
+ ```
229
+
230
+ These methods return an [`APIResponse`](https://github.com/hubmapconsortium/search-python-sdk/tree/main/src/hubmap_search_sdk/_response.py) object.
231
+
232
+ The async client returns an [`AsyncAPIResponse`](https://github.com/hubmapconsortium/search-python-sdk/tree/main/src/hubmap_search_sdk/_response.py) with the same structure, the only difference being `await`able methods for reading the response content.
233
+
234
+ #### `.with_streaming_response`
235
+
236
+ The above interface eagerly reads the full response body when you make the request, which may not always be what you want.
237
+
238
+ 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.
239
+
240
+ ```python
241
+ with client.indices.with_streaming_response.list() as response:
242
+ print(response.headers.get("X-My-Header"))
243
+
244
+ for line in response.iter_lines():
245
+ print(line)
246
+ ```
247
+
248
+ The context manager is required so that the response will reliably be closed.
249
+
250
+ ### Making custom/undocumented requests
251
+
252
+ This library is typed for convenient access to the documented API.
253
+
254
+ If you need to access undocumented endpoints, params, or response properties, the library can still be used.
255
+
256
+ #### Undocumented endpoints
257
+
258
+ To make requests to undocumented endpoints, you can make requests using `client.get`, `client.post`, and other
259
+ http verbs. Options on the client will be respected (such as retries) when making this request.
260
+
261
+ ```py
262
+ import httpx
263
+
264
+ response = client.post(
265
+ "/foo",
266
+ cast_to=httpx.Response,
267
+ body={"my_param": True},
268
+ )
269
+
270
+ print(response.headers.get("x-foo"))
271
+ ```
272
+
273
+ #### Undocumented request params
274
+
275
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` request
276
+ options.
277
+
278
+ #### Undocumented response properties
279
+
280
+ To access undocumented response properties, you can access the extra fields like `response.unknown_prop`. You
281
+ can also get all the extra fields on the Pydantic model as a dict with
282
+ [`response.model_extra`](https://docs.pydantic.dev/latest/api/base_model/#pydantic.BaseModel.model_extra).
283
+
284
+ ### Configuring the HTTP client
285
+
286
+ You can directly override the [httpx client](https://www.python-httpx.org/api/#client) to customize it for your use case, including:
287
+
288
+ - Support for [proxies](https://www.python-httpx.org/advanced/proxies/)
289
+ - Custom [transports](https://www.python-httpx.org/advanced/transports/)
290
+ - Additional [advanced](https://www.python-httpx.org/advanced/clients/) functionality
291
+
292
+ ```python
293
+ import httpx
294
+ from hubmap_search_sdk import HubmapSearchSDK, DefaultHttpxClient
295
+
296
+ client = HubmapSearchSDK(
297
+ # Or use the `HUBMAP_SEARCH_SDK_BASE_URL` env var
298
+ base_url="http://my.test.server.example.com:8083",
299
+ http_client=DefaultHttpxClient(
300
+ proxy="http://my.test.proxy.example.com",
301
+ transport=httpx.HTTPTransport(local_address="0.0.0.0"),
302
+ ),
303
+ )
304
+ ```
305
+
306
+ You can also customize the client on a per-request basis by using `with_options()`:
307
+
308
+ ```python
309
+ client.with_options(http_client=DefaultHttpxClient(...))
310
+ ```
311
+
312
+ ### Managing HTTP resources
313
+
314
+ 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.
315
+
316
+ ```py
317
+ from hubmap_search_sdk import HubmapSearchSDK
318
+
319
+ with HubmapSearchSDK() as client:
320
+ # make requests here
321
+ ...
322
+
323
+ # HTTP client is now closed
324
+ ```
325
+
326
+ ## Versioning
327
+
328
+ 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:
329
+
330
+ 1. Changes that only affect static types, without breaking runtime behavior.
331
+ 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.)_
332
+ 3. Changes that we do not expect to impact the vast majority of users in practice.
333
+
334
+ We take backwards-compatibility seriously and work hard to ensure you can rely on a smooth upgrade experience.
335
+
336
+ We are keen for your feedback; please open an [issue](https://www.github.com/hubmapconsortium/search-python-sdk/issues) with questions, bugs, or suggestions.
337
+
338
+ ### Determining the installed version
339
+
340
+ 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.
341
+
342
+ You can determine the version that is being used at runtime with:
343
+
344
+ ```py
345
+ import hubmap_search_sdk
346
+ print(hubmap_search_sdk.__version__)
347
+ ```
348
+
349
+ ## Requirements
350
+
351
+ Python 3.8 or higher.
352
+
353
+ ## Contributing
354
+
355
+ See [the contributing documentation](https://github.com/hubmapconsortium/search-python-sdk/tree/main/./CONTRIBUTING.md).