xippios-core 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.
- xippios_core-0.1.0/.gitignore +21 -0
- xippios_core-0.1.0/CHANGELOG.md +53 -0
- xippios_core-0.1.0/LICENSE +201 -0
- xippios_core-0.1.0/PKG-INFO +230 -0
- xippios_core-0.1.0/README.md +198 -0
- xippios_core-0.1.0/docs/adr/0001-three-layer-architecture.md +29 -0
- xippios_core-0.1.0/docs/adr/0002-runtime-stack.md +25 -0
- xippios_core-0.1.0/docs/adr/0003-upstream-fidelity.md +28 -0
- xippios_core-0.1.0/docs/adr/0004-core-layout-and-mcp-sdk.md +45 -0
- xippios_core-0.1.0/docs/adr/0005-no-credentials-in-envelope.md +36 -0
- xippios_core-0.1.0/docs/adr/0006-nested-namespace-for-multi-api-providers.md +33 -0
- xippios_core-0.1.0/docs/adr/0007-invalid-request-error-and-post-routes.md +37 -0
- xippios_core-0.1.0/docs/adr/0008-hardening-from-the-first-source.md +47 -0
- xippios_core-0.1.0/docs/conventions.md +206 -0
- xippios_core-0.1.0/docs/definition-of-done.md +33 -0
- xippios_core-0.1.0/docs/handover.md +93 -0
- xippios_core-0.1.0/pyproject.toml +92 -0
- xippios_core-0.1.0/src/xippios/core/__init__.py +80 -0
- xippios_core-0.1.0/src/xippios/core/_loop.py +113 -0
- xippios_core-0.1.0/src/xippios/core/_version.py +10 -0
- xippios_core-0.1.0/src/xippios/core/client/__init__.py +119 -0
- xippios_core-0.1.0/src/xippios/core/client/_core.py +188 -0
- xippios_core-0.1.0/src/xippios/core/client/auth.py +147 -0
- xippios_core-0.1.0/src/xippios/core/client/cache.py +110 -0
- xippios_core-0.1.0/src/xippios/core/client/config.py +135 -0
- xippios_core-0.1.0/src/xippios/core/client/ratelimit.py +55 -0
- xippios_core-0.1.0/src/xippios/core/client/retry.py +83 -0
- xippios_core-0.1.0/src/xippios/core/config.py +84 -0
- xippios_core-0.1.0/src/xippios/core/errors.py +201 -0
- xippios_core-0.1.0/src/xippios/core/http/__init__.py +40 -0
- xippios_core-0.1.0/src/xippios/core/http/problems.py +88 -0
- xippios_core-0.1.0/src/xippios/core/http/router.py +144 -0
- xippios_core-0.1.0/src/xippios/core/mcp/__init__.py +35 -0
- xippios_core-0.1.0/src/xippios/core/mcp/cli.py +33 -0
- xippios_core-0.1.0/src/xippios/core/mcp/errors.py +13 -0
- xippios_core-0.1.0/src/xippios/core/mcp/results.py +89 -0
- xippios_core-0.1.0/src/xippios/core/mcp/server.py +116 -0
- xippios_core-0.1.0/src/xippios/core/models.py +207 -0
- xippios_core-0.1.0/src/xippios/core/pagination.py +112 -0
- xippios_core-0.1.0/src/xippios/core/py.typed +0 -0
- xippios_core-0.1.0/src/xippios/core/reference.py +130 -0
- xippios_core-0.1.0/src/xippios/core/testing/__init__.py +53 -0
- xippios_core-0.1.0/src/xippios/core/testing/adapters.py +46 -0
- xippios_core-0.1.0/src/xippios/core/testing/fixtures.py +113 -0
- xippios_core-0.1.0/src/xippios/core/testing/plugin.py +57 -0
- xippios_core-0.1.0/src/xippios/core/testing/record.py +41 -0
- xippios_core-0.1.0/src/xippios/core/testing/replay.py +32 -0
- xippios_core-0.1.0/src/xippios/core/testing/scrub.py +49 -0
- xippios_core-0.1.0/tests/client/test_auth.py +102 -0
- xippios_core-0.1.0/tests/client/test_cache.py +64 -0
- xippios_core-0.1.0/tests/client/test_client.py +281 -0
- xippios_core-0.1.0/tests/client/test_config.py +53 -0
- xippios_core-0.1.0/tests/client/test_ratelimit.py +53 -0
- xippios_core-0.1.0/tests/conftest.py +8 -0
- xippios_core-0.1.0/tests/http/test_problems.py +84 -0
- xippios_core-0.1.0/tests/http/test_router.py +207 -0
- xippios_core-0.1.0/tests/mcp/test_cli.py +26 -0
- xippios_core-0.1.0/tests/mcp/test_errors.py +22 -0
- xippios_core-0.1.0/tests/mcp/test_results.py +69 -0
- xippios_core-0.1.0/tests/mcp/test_server.py +117 -0
- xippios_core-0.1.0/tests/test_config.py +68 -0
- xippios_core-0.1.0/tests/test_errors.py +103 -0
- xippios_core-0.1.0/tests/test_loop.py +83 -0
- xippios_core-0.1.0/tests/test_models.py +178 -0
- xippios_core-0.1.0/tests/test_pagination.py +87 -0
- xippios_core-0.1.0/tests/test_public_surface.py +49 -0
- xippios_core-0.1.0/tests/test_reference.py +132 -0
- xippios_core-0.1.0/tests/testing/test_adapters.py +64 -0
- xippios_core-0.1.0/tests/testing/test_fixtures.py +63 -0
- xippios_core-0.1.0/tests/testing/test_plugin.py +63 -0
- xippios_core-0.1.0/tests/testing/test_record_replay.py +64 -0
- xippios_core-0.1.0/tests/testing/test_scrub.py +46 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# environments and caches
|
|
2
|
+
.venv/
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
.mypy_cache/
|
|
6
|
+
.ruff_cache/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.hypothesis/
|
|
9
|
+
|
|
10
|
+
# build artefacts
|
|
11
|
+
dist/
|
|
12
|
+
build/
|
|
13
|
+
*.egg-info/
|
|
14
|
+
|
|
15
|
+
# local secrets are never files, but belt and braces
|
|
16
|
+
.env
|
|
17
|
+
.envrc
|
|
18
|
+
|
|
19
|
+
# editors
|
|
20
|
+
.idea/
|
|
21
|
+
.vscode/
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/) (pre-1.0: breaking changes bump the minor).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-10-22
|
|
10
|
+
|
|
11
|
+
First release, cut after the first source package (sdk-usda-nass) had exercised it.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `xippios.core.errors`: the family error taxonomy (`XippiosError` and seven
|
|
16
|
+
subclasses), `error_from_response`, `raise_for_status`, `parse_retry_after`.
|
|
17
|
+
- `xippios.core.models`: `UpstreamModel`, `ResultMeta`, `Result[T]`, `parse`.
|
|
18
|
+
- `xippios.core.config`: `SourceSettings` base and `resolve_api_key`.
|
|
19
|
+
- `xippios.core.sync`: derive a sync function from an async one on a shared
|
|
20
|
+
background event loop.
|
|
21
|
+
- `xippios.core.client`: `AsyncClient` and `Client` with `ClientConfig`, `Timeouts`,
|
|
22
|
+
`RetryPolicy`, `RateLimit`, `MemoryCache` and the `CacheBackend` protocol.
|
|
23
|
+
- `xippios.core.client.auth`: `QueryKeyAuth`, `HeaderKeyAuth`, `BearerAuth`,
|
|
24
|
+
`BasicKeyAuth` and the `EnvKeyAuth` base, resolving the key from the environment on
|
|
25
|
+
the first request. Re-exported from `xippios.core`.
|
|
26
|
+
- `ResultMeta` redacts credential-like keys in `request` at construction (ADR-0005).
|
|
27
|
+
- `resolve_api_key` is typed to return `SecretStr` when the key is required.
|
|
28
|
+
- `xippios.core.pagination`: `paginate_offset`, `paginate_pages`, `paginate_cursor`,
|
|
29
|
+
`collect`.
|
|
30
|
+
- `xippios.core.reference`: `load_csv`, `load_json`, `load_table`.
|
|
31
|
+
- `xippios.core.mcp` (extra `mcp`): `build_server`, `register_tasks`, `cap_result`,
|
|
32
|
+
`error_to_text`, `main`.
|
|
33
|
+
- `xippios.core.http` (extra `http`): `router_from_tasks`, `problem_response`,
|
|
34
|
+
`install_error_handlers`.
|
|
35
|
+
- `xippios.core.testing` (extra `testing`): pytest plugin with the `live` gate,
|
|
36
|
+
fixture format, `record`, `replay`, scrubbing helpers.
|
|
37
|
+
- CI on Python 3.12, 3.13 and 3.14; trusted publishing on `v*` tags.
|
|
38
|
+
- `UpstreamModel` serialises `Decimal` fields as JSON numbers in both adapters
|
|
39
|
+
(ADR-0008); `UpstreamModel.project` builds projections; `parse_decimal` reads
|
|
40
|
+
published figures with separators or suppression codes.
|
|
41
|
+
- `ClientConfig.classify`: a source's error mapping, called on every response before
|
|
42
|
+
the default status mapping.
|
|
43
|
+
- `xippios.core.reference.render_str_enums` and `enum_member_name`: generated
|
|
44
|
+
`StrEnum` source for packaged value lists.
|
|
45
|
+
- `xippios.core.testing.assert_projection` and `mcp_call`.
|
|
46
|
+
- `InvalidRequestError` in the taxonomy (ADR-0007): a request refused before it is
|
|
47
|
+
sent; HTTP 422, MCP text. Re-exported from `xippios.core`.
|
|
48
|
+
- `xippios.core.http.is_scalar`.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- `router_from_tasks`: a task with any non-scalar parameter becomes a `POST` route whose
|
|
53
|
+
JSON body is an object keyed by parameter name; scalar-only tasks stay `GET`.
|
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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,230 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: xippios-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Shared core for the xippios Python SDK family: HTTP client, models, errors, MCP/HTTP adapters
|
|
5
|
+
Project-URL: Homepage, https://github.com/xippios/sdk-core
|
|
6
|
+
Project-URL: Changelog, https://github.com/xippios/sdk-core/blob/main/CHANGELOG.md
|
|
7
|
+
Project-URL: Issues, https://github.com/xippios/sdk-core/issues
|
|
8
|
+
Author: XIPPIOS GmbH
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: fastapi,httpx,mcp,pydantic,sdk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: httpx>=0.28
|
|
21
|
+
Requires-Dist: pydantic-settings>=2.7
|
|
22
|
+
Requires-Dist: pydantic>=2.11
|
|
23
|
+
Provides-Extra: http
|
|
24
|
+
Requires-Dist: fastapi>=0.115; extra == 'http'
|
|
25
|
+
Provides-Extra: mcp
|
|
26
|
+
Requires-Dist: mcp>=2.0; extra == 'mcp'
|
|
27
|
+
Provides-Extra: testing
|
|
28
|
+
Requires-Dist: anyio>=4; extra == 'testing'
|
|
29
|
+
Requires-Dist: pytest>=8; extra == 'testing'
|
|
30
|
+
Requires-Dist: respx>=0.22; extra == 'testing'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# xippios-core
|
|
34
|
+
|
|
35
|
+
Shared foundation of the [xippios](https://github.com/xippios) Python SDK family. Every
|
|
36
|
+
`xippios-<source>` package depends on it; nothing in it knows about any particular
|
|
37
|
+
upstream API.
|
|
38
|
+
|
|
39
|
+
It gives a source package the things that should be identical across the family:
|
|
40
|
+
|
|
41
|
+
- **HTTP client** on `httpx` with retries, a per-source rate limiter, an optional
|
|
42
|
+
response cache (off by default; the in-memory one is bounded by TTL and size),
|
|
43
|
+
explicit timeouts and one `User-Agent`. Async at the core, a sync facade on top.
|
|
44
|
+
- **Auth helpers** that read the key from the environment on the first request:
|
|
45
|
+
query parameter, header, bearer token or basic auth. A source's documented error
|
|
46
|
+
shapes go into `ClientConfig.classify`, consulted on every response.
|
|
47
|
+
- **Error taxonomy**: `ConfigError`, `AuthError`, `RateLimitError`, `NotFoundError`,
|
|
48
|
+
`ValidationError`, `UpstreamError`, `TransportError` and `InvalidRequestError` (a
|
|
49
|
+
request refused before it is sent), all under `XippiosError`.
|
|
50
|
+
- **Result envelope**: every task function returns `Result[T]` with `ResultMeta`
|
|
51
|
+
(source, endpoint, retrieved_at, published_at, vintage, request). `Decimal` fields
|
|
52
|
+
of upstream models arrive as JSON numbers in both adapters; `UpstreamModel.project`
|
|
53
|
+
builds a projection of a record under upstream names, `parse_decimal` reads a
|
|
54
|
+
published figure.
|
|
55
|
+
- **Reference-data loader** for code lists shipped inside a package.
|
|
56
|
+
- **Adapters** that turn task functions into MCP tools (`xippios.core.mcp`) and FastAPI
|
|
57
|
+
routes (`xippios.core.http`) without any logic of their own.
|
|
58
|
+
- **Test support**: a live-test gate, fixture recording with secrets scrubbed, and
|
|
59
|
+
replay through `respx` (`xippios.core.testing`).
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
uv add xippios-core # client, models, errors, reference, pagination
|
|
65
|
+
uv add "xippios-core[mcp]" # + MCP server helpers (official mcp SDK 2.x)
|
|
66
|
+
uv add "xippios-core[http]" # + FastAPI router helpers
|
|
67
|
+
uv add "xippios-core[testing]" # + pytest plugin, respx replay, fixture recording
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Python 3.12 or later.
|
|
71
|
+
|
|
72
|
+
## 30-second example
|
|
73
|
+
|
|
74
|
+
A source package writes its task function once, async, and derives the sync one:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from pydantic import Field
|
|
78
|
+
|
|
79
|
+
from xippios.core import (
|
|
80
|
+
AsyncClient,
|
|
81
|
+
ClientConfig,
|
|
82
|
+
QueryKeyAuth,
|
|
83
|
+
RateLimit,
|
|
84
|
+
Result,
|
|
85
|
+
ResultMeta,
|
|
86
|
+
UpstreamModel,
|
|
87
|
+
parse,
|
|
88
|
+
sync,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
client = AsyncClient(
|
|
92
|
+
ClientConfig(
|
|
93
|
+
source="example",
|
|
94
|
+
version="0.1.0",
|
|
95
|
+
base_url="https://api.example.org",
|
|
96
|
+
rate_limit=RateLimit(per_minute=60),
|
|
97
|
+
),
|
|
98
|
+
auth=QueryKeyAuth("key", "EXAMPLE_API_KEY", source="example"), # read on first request
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
class Series(UpstreamModel):
|
|
103
|
+
series_id: str = Field(alias="seriesId")
|
|
104
|
+
value: float
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
async def get_series_async(series_id: str, year: int = 2024) -> Result[list[Series]]:
|
|
108
|
+
"""Fetch one series for a year.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
series_id: Upstream identifier, e.g. ``"CORN_YIELD"``.
|
|
112
|
+
year: Four-digit year, e.g. ``2024``.
|
|
113
|
+
"""
|
|
114
|
+
params = {"id": series_id, "year": year}
|
|
115
|
+
raw = await client.get_json("/v1/series", params=params)
|
|
116
|
+
rows = parse(list[Series], raw["data"], source="example", endpoint="series")
|
|
117
|
+
meta = ResultMeta(source="example", endpoint="series", request=params)
|
|
118
|
+
return Result(data=rows, meta=meta)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
get_series = sync(get_series_async) # same signature, same docstring, blocks until done
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
>>> result = get_series("CORN_YIELD", year=2024)
|
|
126
|
+
>>> result.data[0].value, result.meta.retrieved_at
|
|
127
|
+
(177.3, datetime.datetime(2026, 10, 20, 12, 0, tzinfo=datetime.timezone.utc))
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
`meta.request` is provenance, not a copy of the call: `ResultMeta` redacts any key that
|
|
131
|
+
looks like a credential (`key`, `token`, `secret`, ...) so an envelope is safe to hand
|
|
132
|
+
to an agent or return over HTTP.
|
|
133
|
+
|
|
134
|
+
Upstream failures arrive as taxonomy errors, never as raw `httpx` exceptions:
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from xippios.core import NotFoundError, RateLimitError
|
|
138
|
+
|
|
139
|
+
try:
|
|
140
|
+
get_series("NOPE")
|
|
141
|
+
except NotFoundError as exc:
|
|
142
|
+
print(exc) # 404 from GET api.example.org/v1/series: ...
|
|
143
|
+
except RateLimitError as exc:
|
|
144
|
+
print(exc.retry_after)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## MCP server in five lines
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
# xippios/example/mcp.py
|
|
151
|
+
from xippios.core.mcp import build_server, main
|
|
152
|
+
from xippios.example import tasks
|
|
153
|
+
|
|
154
|
+
server = build_server("example", [tasks.get_series, tasks.list_commodities])
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def run() -> None: # entry point: xippios-example-mcp = "xippios.example.mcp:run"
|
|
158
|
+
main(server)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Tool names are `<source>_<function>` (`example_get_series`), the docstring is the tool
|
|
162
|
+
description, the signature is the input schema. Results are capped at 200 rows or
|
|
163
|
+
64 KB with a note on how to narrow the query; errors come back as
|
|
164
|
+
`error: <Class>: <message>`. `--http` serves streamable HTTP instead of stdio.
|
|
165
|
+
|
|
166
|
+
Client configuration, for Claude Desktop or any MCP client:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"mcpServers": {
|
|
171
|
+
"example": {
|
|
172
|
+
"command": "uvx",
|
|
173
|
+
"args": ["--from", "xippios-example[mcp]", "xippios-example-mcp"],
|
|
174
|
+
"env": { "EXAMPLE_API_KEY": "..." }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## HTTP routes in two lines
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from xippios.core.http import router_from_tasks
|
|
184
|
+
|
|
185
|
+
router = router_from_tasks("example", [tasks.get_series]) # GET /example/get_series?series_id=...
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Mount it on your FastAPI app. A task whose parameters are all scalars is a `GET` with
|
|
189
|
+
query parameters; a task with a mapping, list or model parameter is a `POST` whose JSON
|
|
190
|
+
body is keyed by parameter name. Responses are the `Result[T]` envelope; errors are
|
|
191
|
+
RFC 9457 problem details (`application/problem+json`), `InvalidRequestError` as 422.
|
|
192
|
+
|
|
193
|
+
## Testing a source package
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
# tests/conftest.py
|
|
197
|
+
pytest_plugins = ["xippios.core.testing.plugin"]
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
- `@pytest.mark.live` tests are skipped unless `XIPPIOS_LIVE_TESTS=1`.
|
|
201
|
+
- `replay_fixture("api_GET", "corn_2024")` mounts `tests/fixtures/api_GET/corn_2024.json`.
|
|
202
|
+
- `record(client, "/v1/series", fixture_path(...), params=...)` records a live response
|
|
203
|
+
with credentials scrubbed. Never hand-write a fixture.
|
|
204
|
+
|
|
205
|
+
## Status
|
|
206
|
+
|
|
207
|
+
| Module | What | Status |
|
|
208
|
+
| --- | --- | --- |
|
|
209
|
+
| `xippios.core.client` | httpx client, retries, rate limit, cache, sync facade | alpha |
|
|
210
|
+
| `xippios.core.errors` | taxonomy and response classification | alpha |
|
|
211
|
+
| `xippios.core.models` | `UpstreamModel`, `Result`, `ResultMeta`, `parse` | alpha |
|
|
212
|
+
| `xippios.core.config` | `SourceSettings`, `resolve_api_key` | alpha |
|
|
213
|
+
| `xippios.core.reference` | packaged CSV/JSON loaders | alpha |
|
|
214
|
+
| `xippios.core.pagination` | offset, page and cursor iterators | alpha |
|
|
215
|
+
| `xippios.core.mcp` | tool registration, result caps, error text, CLI | alpha |
|
|
216
|
+
| `xippios.core.http` | router factory, problem details | alpha |
|
|
217
|
+
| `xippios.core.testing` | live gate, record, replay, scrub | alpha |
|
|
218
|
+
|
|
219
|
+
Alpha: the public surface may change in a minor version until the first source
|
|
220
|
+
package, `sdk-usda-nass`, has exercised it.
|
|
221
|
+
|
|
222
|
+
## Conventions
|
|
223
|
+
|
|
224
|
+
The rules this package implements live in [docs/conventions.md](docs/conventions.md)
|
|
225
|
+
and the decisions behind them in [docs/adr/](docs/adr/). Changes to a convention are
|
|
226
|
+
their own PR plus an ADR.
|
|
227
|
+
|
|
228
|
+
## Licence
|
|
229
|
+
|
|
230
|
+
Apache-2.0. See [LICENSE](LICENSE).
|