gts-agency-python-sdk 0.0.1__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.
- gts_agency_python_sdk-0.0.1/LICENSE +201 -0
- gts_agency_python_sdk-0.0.1/PKG-INFO +221 -0
- gts_agency_python_sdk-0.0.1/README.md +197 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/__init__.py +0 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/auth_hooks.py +55 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/client.py +212 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/credentials.py +54 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/__init__.py +0 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/annotations_client.py +495 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/annotations_dto.py +200 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/base_client.py +126 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/datasets_client.py +109 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/datasets_dto.py +81 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/datasource_client.py +44 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/datasource_dto.py +107 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/files_client.py +184 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/files_dto.py +36 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/gateway_client.py +81 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/gateway_dto.py +37 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/ontology_client.py +203 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/ontology_dto.py +221 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/prompts_client.py +56 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/rules_client.py +33 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/rules_dto.py +108 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_client.py +95 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_dto.py +94 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_templates_client.py +23 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_templates_dto.py +27 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_vault_client.py +135 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/session_vault_dto.py +75 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/work_queue_client.py +230 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/delegates/work_queue_dto.py +127 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/domain.py +140 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/observability/__init__.py +60 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/observability/auth.py +15 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/observability/bootstrap.py +344 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/__init__.py +0 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/conftest.py +106 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_annotations_client.py +599 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_annotations_dto.py +299 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_base_client.py +153 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_client_facade.py +105 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_credentials.py +67 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_files_client.py +264 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_files_dto.py +93 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_gateway_dto.py +70 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_gateway_facade.py +229 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_gateway_openai.py +76 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_observability_auth.py +125 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_observability_facade_threadsafety.py +50 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_observability_langfuse.py +76 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_observability_packaging.py +78 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_observability_pipeline.py +246 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_ontology_client.py +152 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_ontology_dto.py +158 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_client.py +128 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_dto.py +75 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_templates_client.py +36 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_templates_dto.py +45 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_vault_client.py +151 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_session_vault_dto.py +27 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_stub_requests.py +39 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_work_queue_client.py +388 -0
- gts_agency_python_sdk-0.0.1/agency_sdk/test/test_work_queue_dto.py +233 -0
- gts_agency_python_sdk-0.0.1/gts_agency_python_sdk.egg-info/PKG-INFO +221 -0
- gts_agency_python_sdk-0.0.1/gts_agency_python_sdk.egg-info/SOURCES.txt +69 -0
- gts_agency_python_sdk-0.0.1/gts_agency_python_sdk.egg-info/dependency_links.txt +1 -0
- gts_agency_python_sdk-0.0.1/gts_agency_python_sdk.egg-info/requires.txt +17 -0
- gts_agency_python_sdk-0.0.1/gts_agency_python_sdk.egg-info/top_level.txt +1 -0
- gts_agency_python_sdk-0.0.1/pyproject.toml +59 -0
- gts_agency_python_sdk-0.0.1/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Ground Truth Systems, Inc
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gts-agency_python-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Author-email: Ground Control Systems <engineering@groundcontrolsystems.com>
|
|
5
|
+
Requires-Python: >=3.12
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: requests>=2.32.0
|
|
9
|
+
Requires-Dist: pydantic>=2.9.2
|
|
10
|
+
Requires-Dist: pyjwt<3.0.0,>=2.3.0
|
|
11
|
+
Requires-Dist: openai>=1.0.0
|
|
12
|
+
Provides-Extra: observability
|
|
13
|
+
Requires-Dist: opentelemetry-sdk>=1.27.0; extra == "observability"
|
|
14
|
+
Requires-Dist: opentelemetry-exporter-otlp-proto-http>=1.27.0; extra == "observability"
|
|
15
|
+
Requires-Dist: opentelemetry-instrumentation-logging>=0.48b0; extra == "observability"
|
|
16
|
+
Requires-Dist: langfuse>=3.8.1; extra == "observability"
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: mypy==1.4.1; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest==7.4.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-cov==4.1.0; extra == "dev"
|
|
21
|
+
Requires-Dist: pre-commit==3.8.0; extra == "dev"
|
|
22
|
+
Requires-Dist: black==23.12.1; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# Agency Python SDK
|
|
26
|
+
|
|
27
|
+
Python client SDK for the GTS Agency platform. Provides typed HTTP clients for datasets, datasources, files, ontologies, prompts, and rules APIs.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install gts-agency-python-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
For development:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install -e ".[dev]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Optional OpenTelemetry tracing support (Langfuse backend):
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install gts-agency-python-sdk[observability]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Configuration
|
|
48
|
+
|
|
49
|
+
The examples in this repository use the following environment variables for authentication and configuration:
|
|
50
|
+
|
|
51
|
+
- `AGENCY_AUTH_URL`: The OAuth2 token endpoint URL.
|
|
52
|
+
- `AGENCY_API_URL`: The base URL for the Agency API.
|
|
53
|
+
- `AGENCY_ORG_ID`: The organization ID to use for requests.
|
|
54
|
+
- `AGENCY_CLIENT_ID`: Your OAuth2 client ID.
|
|
55
|
+
- `AGENCY_CLIENT_SECRET`: Your OAuth2 client secret.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from agency_sdk.client import AgencyClient, CredentialsSupplier
|
|
61
|
+
|
|
62
|
+
credentials = CredentialsSupplier(
|
|
63
|
+
auth_base_url="https://auth.example.com",
|
|
64
|
+
client_id="your-client-id",
|
|
65
|
+
client_secret="your-client-secret",
|
|
66
|
+
)
|
|
67
|
+
client = AgencyClient(token_supplier=credentials, base_url="https://api.example.com")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Delegate Clients
|
|
71
|
+
|
|
72
|
+
Access each API domain through the facade:
|
|
73
|
+
|
|
74
|
+
- `client.dataset()` — datasets CRUD, filesystem traversal, clone
|
|
75
|
+
- `client.datasource()` — datasource and table introspection
|
|
76
|
+
- `client.files()` — tenant file storage: list, upload, folder management, delete, signed URLs, `gtsf://` URI resolution, streamed download
|
|
77
|
+
- `client.ontology()` — list ontologies (name → id, optional `kind` filter), export (JSON snapshot, Turtle/OWL, SHACL, package, package-zip), and entity-datasource mappings
|
|
78
|
+
- `client.prompts()` — prompt CRUD via command pattern
|
|
79
|
+
- `client.rules()` — rule listing, detail, execution, and execution history
|
|
80
|
+
- `client.session_vault()` — session-scoped key/value vault for agent state (classification-based encryption, audited reveal)
|
|
81
|
+
- `client.work_queues()` — work-queue ingestion: create items with exactly-once external refs, publish, claim by ref, queue-scoped owner lookup (`get_items_by_ref`), unblock/retry/reprocess, delete, and `list()` to resolve a queue name→id (409 returns a typed claim-lost result from the error envelope's `error.details`, plus a `contended` flag — not an exception)
|
|
82
|
+
- `client.sessions()` — report progress on a dispatched control-plane session: `attach` to the inherited session then `update` its status/result/events/metrics (the agent inherits the session, never self-registers — no `register`)
|
|
83
|
+
- `client.session_templates()` — list session templates to resolve a template name → id (read-only)
|
|
84
|
+
- `client.annotations()` — publish a knowledge graph as annotator work: `push_graph()` does resolve-workflow → create-batch → bind-workflow → multipart upload → read-back in one call (one job per `class: "rule"` vertex), plus the individual legs, `bind_workflow`/`list_workflows` (a batch cannot hold jobs until a workflow is bound to it), batch reads, and the job specifications that seed each job's checklist ([docs/annotations.md](docs/annotations.md))
|
|
85
|
+
- `client.gateway(org_id=..., gateway_base_url=...)` — OpenAI-compatible LLM calls routed through the org's agentgateway (shared credentials + `x-org` routing header)
|
|
86
|
+
|
|
87
|
+
### Rules Example
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from agency_sdk.delegates.rules_dto import ExecuteRequest
|
|
91
|
+
|
|
92
|
+
rules = client.rules()
|
|
93
|
+
|
|
94
|
+
# List rules
|
|
95
|
+
result = rules.list(organisation_id=2)
|
|
96
|
+
for rule in result.items:
|
|
97
|
+
print(f"{rule.name} (status={rule.active_version_status})")
|
|
98
|
+
|
|
99
|
+
# Get rule detail
|
|
100
|
+
detail = rules.get(rule_id="rule-id", organisation_id=2)
|
|
101
|
+
|
|
102
|
+
# Execute a rule
|
|
103
|
+
response = rules.execute(
|
|
104
|
+
rule_id="rule-id",
|
|
105
|
+
request=ExecuteRequest(organisation=2, context={"key": "value"}, trace=True),
|
|
106
|
+
)
|
|
107
|
+
print(f"Result: {response.result}")
|
|
108
|
+
|
|
109
|
+
# List execution history
|
|
110
|
+
executions = rules.list_executions(rule_id="rule-id", organisation_id=2)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Files Example
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
files = client.files()
|
|
117
|
+
|
|
118
|
+
# Upload into a folder (multipart; up to 100 MiB per file and per request)
|
|
119
|
+
result = files.upload(organisation_id=2, file_paths=["report.pdf"], path="guidelines")
|
|
120
|
+
file_id = result.uploaded[0].id
|
|
121
|
+
|
|
122
|
+
# Resolve a gtsf:// reference (as found in configurations and rule annotations)
|
|
123
|
+
signed = files.resolve_gtsf_uri(f"gtsf://{file_id}", organisation_id=2)
|
|
124
|
+
print(f"Download until {signed.expires_at}: {signed.signed_url}")
|
|
125
|
+
|
|
126
|
+
# Or download directly (streamed to disk via the signed URL)
|
|
127
|
+
files.download(file_id=file_id, organisation_id=2, target_path="./report.pdf")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
See [docs/files_storage_flows.md](docs/files_storage_flows.md) for the full
|
|
131
|
+
upload/download architecture.
|
|
132
|
+
|
|
133
|
+
### Ontology Export Example
|
|
134
|
+
|
|
135
|
+
Agents retrieve a typed JSON snapshot and use its classes, relations, and
|
|
136
|
+
properties to decide how to treat data. Text formats (`turtle`, `shacl`,
|
|
137
|
+
`package`) return `str`; `package-zip` is binary and must go through
|
|
138
|
+
`export_bytes()`.
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
ontology = client.ontology()
|
|
142
|
+
|
|
143
|
+
listed = ontology.list(organisation_id=2)
|
|
144
|
+
ontology_id = next(item.id for item in listed.items if item.name == "claims")
|
|
145
|
+
|
|
146
|
+
snapshot = ontology.export_snapshot(ontology_id=ontology_id, organisation_id=2)
|
|
147
|
+
for entity in snapshot.entities.values():
|
|
148
|
+
print(f"{entity.entity_type}: {entity.label}")
|
|
149
|
+
|
|
150
|
+
turtle = ontology.export(ontology_id=ontology_id, organisation_id=2, export_format="turtle")
|
|
151
|
+
zip_bytes = ontology.export_bytes(ontology_id=ontology_id, organisation_id=2, export_format="package-zip")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Observability Example
|
|
155
|
+
|
|
156
|
+
Opt-in OpenTelemetry tracing + log correlation, shipped to a Langfuse backend and
|
|
157
|
+
authenticated with the same credentials as the API client. Requires the
|
|
158
|
+
`[observability]` extra.
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
obs = client.observability("gts-myagent") # reuses credentials; host defaults to base_url
|
|
162
|
+
tracer = obs.init() # exporters live; stdlib logging bridged
|
|
163
|
+
|
|
164
|
+
with obs.agent_run("agent.myagent", correlation_id=cid) as span:
|
|
165
|
+
logger.info("doing work") # stamped with the span's trace id
|
|
166
|
+
result = do_work()
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
See [docs/observability.md](docs/observability.md) for the full setup, the API,
|
|
170
|
+
and migration from a per-agent bootstrap.
|
|
171
|
+
|
|
172
|
+
### Agent Gateway Example
|
|
173
|
+
|
|
174
|
+
LLM calls routed through the org's deployed agentgateway — one m2m credential
|
|
175
|
+
instead of per-provider API keys. The gateway lives on its own host (not the
|
|
176
|
+
control-plane `base_url`); the SDK wires the rotating bearer, the `x-org` routing
|
|
177
|
+
header, and the URL into a standard **`openai`** client and hands it back.
|
|
178
|
+
|
|
179
|
+
```python
|
|
180
|
+
gateway = client.gateway(org_id="2", gateway_base_url="http://localhost:4000")
|
|
181
|
+
|
|
182
|
+
oai = gateway.openai_client() # standard openai.OpenAI, pre-wired to the gateway
|
|
183
|
+
r = oai.chat.completions.create(
|
|
184
|
+
model="biglambda1", # virtual-model name from the org's gateway config
|
|
185
|
+
messages=[{"role": "user", "content": "Summarize this rule ..."}],
|
|
186
|
+
temperature=0.0,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Streaming / tools / structured outputs — plain openai SDK
|
|
190
|
+
for chunk in oai.chat.completions.create(model="biglambda1", messages=[...], stream=True):
|
|
191
|
+
...
|
|
192
|
+
|
|
193
|
+
# Async (e.g. httpx-based agents)
|
|
194
|
+
aoai = gateway.async_openai_client()
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
See [docs/gateway.md](docs/gateway.md) for prod/test URL selection, URL
|
|
198
|
+
discovery, rotation-safe DIY openai wiring, and error semantics.
|
|
199
|
+
|
|
200
|
+
## Examples
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
export AGENCY_AUTH_URL="http://localhost:8080/realms/agency/protocol/openid-connect/token"
|
|
204
|
+
export AGENCY_API_URL="http://localhost:13001"
|
|
205
|
+
export AGENCY_ORG_ID="2"
|
|
206
|
+
export AGENCY_CLIENT_ID="your-client-id"
|
|
207
|
+
export AGENCY_CLIENT_SECRET="your-client-secret"
|
|
208
|
+
|
|
209
|
+
python examples/quick_clone_dataset.py
|
|
210
|
+
python examples/quick_create_prompt.py
|
|
211
|
+
python examples/quick_export_ontology.py
|
|
212
|
+
python examples/quick_execute_rule.py
|
|
213
|
+
python examples/quick_files.py
|
|
214
|
+
python examples/quick_annotations.py
|
|
215
|
+
python examples/quick_observability.py # requires the [observability] extra
|
|
216
|
+
python examples/quick_gateway.py # needs GATEWAY_BASE_URL (+ GATEWAY_MODEL); local gateway on :4000
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
To verify the SDK end to end against the local platform stack
|
|
220
|
+
(`gts-local-environment`), follow [docs/local_e2e.md](docs/local_e2e.md).
|
|
221
|
+
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
# Agency Python SDK
|
|
2
|
+
|
|
3
|
+
Python client SDK for the GTS Agency platform. Provides typed HTTP clients for datasets, datasources, files, ontologies, prompts, and rules APIs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install gts-agency-python-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For development:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Optional OpenTelemetry tracing support (Langfuse backend):
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install gts-agency-python-sdk[observability]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
The examples in this repository use the following environment variables for authentication and configuration:
|
|
26
|
+
|
|
27
|
+
- `AGENCY_AUTH_URL`: The OAuth2 token endpoint URL.
|
|
28
|
+
- `AGENCY_API_URL`: The base URL for the Agency API.
|
|
29
|
+
- `AGENCY_ORG_ID`: The organization ID to use for requests.
|
|
30
|
+
- `AGENCY_CLIENT_ID`: Your OAuth2 client ID.
|
|
31
|
+
- `AGENCY_CLIENT_SECRET`: Your OAuth2 client secret.
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from agency_sdk.client import AgencyClient, CredentialsSupplier
|
|
37
|
+
|
|
38
|
+
credentials = CredentialsSupplier(
|
|
39
|
+
auth_base_url="https://auth.example.com",
|
|
40
|
+
client_id="your-client-id",
|
|
41
|
+
client_secret="your-client-secret",
|
|
42
|
+
)
|
|
43
|
+
client = AgencyClient(token_supplier=credentials, base_url="https://api.example.com")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Delegate Clients
|
|
47
|
+
|
|
48
|
+
Access each API domain through the facade:
|
|
49
|
+
|
|
50
|
+
- `client.dataset()` — datasets CRUD, filesystem traversal, clone
|
|
51
|
+
- `client.datasource()` — datasource and table introspection
|
|
52
|
+
- `client.files()` — tenant file storage: list, upload, folder management, delete, signed URLs, `gtsf://` URI resolution, streamed download
|
|
53
|
+
- `client.ontology()` — list ontologies (name → id, optional `kind` filter), export (JSON snapshot, Turtle/OWL, SHACL, package, package-zip), and entity-datasource mappings
|
|
54
|
+
- `client.prompts()` — prompt CRUD via command pattern
|
|
55
|
+
- `client.rules()` — rule listing, detail, execution, and execution history
|
|
56
|
+
- `client.session_vault()` — session-scoped key/value vault for agent state (classification-based encryption, audited reveal)
|
|
57
|
+
- `client.work_queues()` — work-queue ingestion: create items with exactly-once external refs, publish, claim by ref, queue-scoped owner lookup (`get_items_by_ref`), unblock/retry/reprocess, delete, and `list()` to resolve a queue name→id (409 returns a typed claim-lost result from the error envelope's `error.details`, plus a `contended` flag — not an exception)
|
|
58
|
+
- `client.sessions()` — report progress on a dispatched control-plane session: `attach` to the inherited session then `update` its status/result/events/metrics (the agent inherits the session, never self-registers — no `register`)
|
|
59
|
+
- `client.session_templates()` — list session templates to resolve a template name → id (read-only)
|
|
60
|
+
- `client.annotations()` — publish a knowledge graph as annotator work: `push_graph()` does resolve-workflow → create-batch → bind-workflow → multipart upload → read-back in one call (one job per `class: "rule"` vertex), plus the individual legs, `bind_workflow`/`list_workflows` (a batch cannot hold jobs until a workflow is bound to it), batch reads, and the job specifications that seed each job's checklist ([docs/annotations.md](docs/annotations.md))
|
|
61
|
+
- `client.gateway(org_id=..., gateway_base_url=...)` — OpenAI-compatible LLM calls routed through the org's agentgateway (shared credentials + `x-org` routing header)
|
|
62
|
+
|
|
63
|
+
### Rules Example
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from agency_sdk.delegates.rules_dto import ExecuteRequest
|
|
67
|
+
|
|
68
|
+
rules = client.rules()
|
|
69
|
+
|
|
70
|
+
# List rules
|
|
71
|
+
result = rules.list(organisation_id=2)
|
|
72
|
+
for rule in result.items:
|
|
73
|
+
print(f"{rule.name} (status={rule.active_version_status})")
|
|
74
|
+
|
|
75
|
+
# Get rule detail
|
|
76
|
+
detail = rules.get(rule_id="rule-id", organisation_id=2)
|
|
77
|
+
|
|
78
|
+
# Execute a rule
|
|
79
|
+
response = rules.execute(
|
|
80
|
+
rule_id="rule-id",
|
|
81
|
+
request=ExecuteRequest(organisation=2, context={"key": "value"}, trace=True),
|
|
82
|
+
)
|
|
83
|
+
print(f"Result: {response.result}")
|
|
84
|
+
|
|
85
|
+
# List execution history
|
|
86
|
+
executions = rules.list_executions(rule_id="rule-id", organisation_id=2)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Files Example
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
files = client.files()
|
|
93
|
+
|
|
94
|
+
# Upload into a folder (multipart; up to 100 MiB per file and per request)
|
|
95
|
+
result = files.upload(organisation_id=2, file_paths=["report.pdf"], path="guidelines")
|
|
96
|
+
file_id = result.uploaded[0].id
|
|
97
|
+
|
|
98
|
+
# Resolve a gtsf:// reference (as found in configurations and rule annotations)
|
|
99
|
+
signed = files.resolve_gtsf_uri(f"gtsf://{file_id}", organisation_id=2)
|
|
100
|
+
print(f"Download until {signed.expires_at}: {signed.signed_url}")
|
|
101
|
+
|
|
102
|
+
# Or download directly (streamed to disk via the signed URL)
|
|
103
|
+
files.download(file_id=file_id, organisation_id=2, target_path="./report.pdf")
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
See [docs/files_storage_flows.md](docs/files_storage_flows.md) for the full
|
|
107
|
+
upload/download architecture.
|
|
108
|
+
|
|
109
|
+
### Ontology Export Example
|
|
110
|
+
|
|
111
|
+
Agents retrieve a typed JSON snapshot and use its classes, relations, and
|
|
112
|
+
properties to decide how to treat data. Text formats (`turtle`, `shacl`,
|
|
113
|
+
`package`) return `str`; `package-zip` is binary and must go through
|
|
114
|
+
`export_bytes()`.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
ontology = client.ontology()
|
|
118
|
+
|
|
119
|
+
listed = ontology.list(organisation_id=2)
|
|
120
|
+
ontology_id = next(item.id for item in listed.items if item.name == "claims")
|
|
121
|
+
|
|
122
|
+
snapshot = ontology.export_snapshot(ontology_id=ontology_id, organisation_id=2)
|
|
123
|
+
for entity in snapshot.entities.values():
|
|
124
|
+
print(f"{entity.entity_type}: {entity.label}")
|
|
125
|
+
|
|
126
|
+
turtle = ontology.export(ontology_id=ontology_id, organisation_id=2, export_format="turtle")
|
|
127
|
+
zip_bytes = ontology.export_bytes(ontology_id=ontology_id, organisation_id=2, export_format="package-zip")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Observability Example
|
|
131
|
+
|
|
132
|
+
Opt-in OpenTelemetry tracing + log correlation, shipped to a Langfuse backend and
|
|
133
|
+
authenticated with the same credentials as the API client. Requires the
|
|
134
|
+
`[observability]` extra.
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
obs = client.observability("gts-myagent") # reuses credentials; host defaults to base_url
|
|
138
|
+
tracer = obs.init() # exporters live; stdlib logging bridged
|
|
139
|
+
|
|
140
|
+
with obs.agent_run("agent.myagent", correlation_id=cid) as span:
|
|
141
|
+
logger.info("doing work") # stamped with the span's trace id
|
|
142
|
+
result = do_work()
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
See [docs/observability.md](docs/observability.md) for the full setup, the API,
|
|
146
|
+
and migration from a per-agent bootstrap.
|
|
147
|
+
|
|
148
|
+
### Agent Gateway Example
|
|
149
|
+
|
|
150
|
+
LLM calls routed through the org's deployed agentgateway — one m2m credential
|
|
151
|
+
instead of per-provider API keys. The gateway lives on its own host (not the
|
|
152
|
+
control-plane `base_url`); the SDK wires the rotating bearer, the `x-org` routing
|
|
153
|
+
header, and the URL into a standard **`openai`** client and hands it back.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
gateway = client.gateway(org_id="2", gateway_base_url="http://localhost:4000")
|
|
157
|
+
|
|
158
|
+
oai = gateway.openai_client() # standard openai.OpenAI, pre-wired to the gateway
|
|
159
|
+
r = oai.chat.completions.create(
|
|
160
|
+
model="biglambda1", # virtual-model name from the org's gateway config
|
|
161
|
+
messages=[{"role": "user", "content": "Summarize this rule ..."}],
|
|
162
|
+
temperature=0.0,
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Streaming / tools / structured outputs — plain openai SDK
|
|
166
|
+
for chunk in oai.chat.completions.create(model="biglambda1", messages=[...], stream=True):
|
|
167
|
+
...
|
|
168
|
+
|
|
169
|
+
# Async (e.g. httpx-based agents)
|
|
170
|
+
aoai = gateway.async_openai_client()
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
See [docs/gateway.md](docs/gateway.md) for prod/test URL selection, URL
|
|
174
|
+
discovery, rotation-safe DIY openai wiring, and error semantics.
|
|
175
|
+
|
|
176
|
+
## Examples
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
export AGENCY_AUTH_URL="http://localhost:8080/realms/agency/protocol/openid-connect/token"
|
|
180
|
+
export AGENCY_API_URL="http://localhost:13001"
|
|
181
|
+
export AGENCY_ORG_ID="2"
|
|
182
|
+
export AGENCY_CLIENT_ID="your-client-id"
|
|
183
|
+
export AGENCY_CLIENT_SECRET="your-client-secret"
|
|
184
|
+
|
|
185
|
+
python examples/quick_clone_dataset.py
|
|
186
|
+
python examples/quick_create_prompt.py
|
|
187
|
+
python examples/quick_export_ontology.py
|
|
188
|
+
python examples/quick_execute_rule.py
|
|
189
|
+
python examples/quick_files.py
|
|
190
|
+
python examples/quick_annotations.py
|
|
191
|
+
python examples/quick_observability.py # requires the [observability] extra
|
|
192
|
+
python examples/quick_gateway.py # needs GATEWAY_BASE_URL (+ GATEWAY_MODEL); local gateway on :4000
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
To verify the SDK end to end against the local platform stack
|
|
196
|
+
(`gts-local-environment`), follow [docs/local_e2e.md](docs/local_e2e.md).
|
|
197
|
+
|
|
File without changes
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Per-request bearer-token auth hooks, shared across the SDK.
|
|
2
|
+
|
|
3
|
+
A static ``Authorization`` header set at client construction goes stale: the
|
|
4
|
+
Keycloak m2m JWT rotates, and long-running clients (OTLP exporters, the gateway
|
|
5
|
+
``openai`` client) freeze whatever was set at build time. Both ``requests`` and
|
|
6
|
+
``httpx`` instead invoke their ``auth`` callable on *every* request, so routing
|
|
7
|
+
the token through these hooks means each request re-reads the (auto-refreshing,
|
|
8
|
+
cached) token and never sends an expired one.
|
|
9
|
+
|
|
10
|
+
Dependency-light on purpose so any consumer can reuse it: only core ``requests``
|
|
11
|
+
at import time; ``httpx`` is imported lazily inside :func:`make_httpx_bearer_auth`
|
|
12
|
+
(it arrives with the ``[observability]`` or ``[openai]`` extras).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
from typing import TYPE_CHECKING, Any, Callable
|
|
18
|
+
|
|
19
|
+
import requests.auth
|
|
20
|
+
|
|
21
|
+
if TYPE_CHECKING:
|
|
22
|
+
import httpx
|
|
23
|
+
|
|
24
|
+
# A callable returning a fresh bearer token, or None when unavailable.
|
|
25
|
+
TokenSupplier = Callable[[], "str | None"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class BearerTokenAuth(requests.auth.AuthBase):
|
|
29
|
+
"""requests per-request auth that stamps a fresh bearer token on every call."""
|
|
30
|
+
|
|
31
|
+
def __init__(self, token_supplier: TokenSupplier) -> None:
|
|
32
|
+
self._token_supplier = token_supplier
|
|
33
|
+
|
|
34
|
+
def __call__(self, request: Any) -> Any:
|
|
35
|
+
token = self._token_supplier()
|
|
36
|
+
if token:
|
|
37
|
+
request.headers["Authorization"] = f"Bearer {token}"
|
|
38
|
+
return request
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def make_httpx_bearer_auth(token_supplier: TokenSupplier) -> "httpx.Auth":
|
|
42
|
+
"""Build an ``httpx.Auth`` mirroring :class:`BearerTokenAuth` (lazy httpx import)."""
|
|
43
|
+
import httpx
|
|
44
|
+
|
|
45
|
+
class _HttpxBearerAuth(httpx.Auth):
|
|
46
|
+
def __init__(self, supplier: TokenSupplier) -> None:
|
|
47
|
+
self._token_supplier = supplier
|
|
48
|
+
|
|
49
|
+
def auth_flow(self, request: Any) -> Any:
|
|
50
|
+
token = self._token_supplier()
|
|
51
|
+
if token:
|
|
52
|
+
request.headers["Authorization"] = f"Bearer {token}"
|
|
53
|
+
yield request
|
|
54
|
+
|
|
55
|
+
return _HttpxBearerAuth(token_supplier)
|