fastspec 0.2.7__tar.gz → 0.2.9__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.
- {fastspec-0.2.7 → fastspec-0.2.9}/PKG-INFO +1 -1
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec/__init__.py +3 -1
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec/_modidx.py +2 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec/gql.py +2 -1
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec/oapi.py +9 -2
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec/spec.py +17 -3
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/PKG-INFO +1 -1
- {fastspec-0.2.7 → fastspec-0.2.9}/LICENSE +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/README.md +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/SOURCES.txt +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/dependency_links.txt +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/entry_points.txt +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/requires.txt +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/fastspec.egg-info/top_level.txt +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/pyproject.toml +0 -0
- {fastspec-0.2.7 → fastspec-0.2.9}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastspec
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: Dynamic OpenAPI, Discovery, and GraphQL spec client for Python — turn any API spec into a fully-typed async client with attribute chaining, streaming, and file uploads
|
|
5
5
|
Author-email: Kerem Turgutlu <keremturgutlu@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -74,6 +74,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
74
74
|
'fastspec.oapi.SyncOpFunc': ('oapi.html#syncopfunc', 'fastspec/oapi.py'),
|
|
75
75
|
'fastspec.oapi.SyncOpFunc.__call__': ('oapi.html#syncopfunc.__call__', 'fastspec/oapi.py'),
|
|
76
76
|
'fastspec.oapi._examples_doc': ('oapi.html#_examples_doc', 'fastspec/oapi.py'),
|
|
77
|
+
'fastspec.oapi._file_arg': ('oapi.html#_file_arg', 'fastspec/oapi.py'),
|
|
77
78
|
'fastspec.oapi._join_url': ('oapi.html#_join_url', 'fastspec/oapi.py'),
|
|
78
79
|
'fastspec.oapi._path': ('oapi.html#_path', 'fastspec/oapi.py'),
|
|
79
80
|
'fastspec.oapi.op_func': ('oapi.html#op_func', 'fastspec/oapi.py')},
|
|
@@ -98,6 +99,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
98
99
|
'fastspec.spec._discovery_collect_params': ('spec.html#_discovery_collect_params', 'fastspec/spec.py'),
|
|
99
100
|
'fastspec.spec._first_url': ('spec.html#_first_url', 'fastspec/spec.py'),
|
|
100
101
|
'fastspec.spec._group_name': ('spec.html#_group_name', 'fastspec/spec.py'),
|
|
102
|
+
'fastspec.spec._is_binary': ('spec.html#_is_binary', 'fastspec/spec.py'),
|
|
101
103
|
'fastspec.spec._media_twin': ('spec.html#_media_twin', 'fastspec/spec.py'),
|
|
102
104
|
'fastspec.spec._op_docs_url': ('spec.html#_op_docs_url', 'fastspec/spec.py'),
|
|
103
105
|
'fastspec.spec._path_params': ('spec.html#_path_params', 'fastspec/spec.py'),
|
|
@@ -256,8 +256,9 @@ def _repr_markdown_(self:GqlFrag): return f'```text\n{self!r}\n```\n\n{inspect.g
|
|
|
256
256
|
|
|
257
257
|
# %% ../nbs/05_gql.ipynb #9c52696f
|
|
258
258
|
def _unwrap(data, steps):
|
|
259
|
-
for nm, _, raw in steps:
|
|
259
|
+
for i, (nm, _, raw) in enumerate(steps):
|
|
260
260
|
if data is None: return None
|
|
261
|
+
if isinstance(data, (list, L)): return L(_unwrap(o, steps[i:]) for o in data)
|
|
261
262
|
data = data[nm]
|
|
262
263
|
if raw: break
|
|
263
264
|
return data
|
|
@@ -17,6 +17,7 @@ from fastcore.apisurface import snake, sanitized_params, mk_sig, mk_doc, mk_grou
|
|
|
17
17
|
|
|
18
18
|
from .spec import OpSpec, SpecParser
|
|
19
19
|
from fasttransport.core import AsyncTransport,SyncTransport
|
|
20
|
+
from fasttransport.errors import APIError
|
|
20
21
|
|
|
21
22
|
|
|
22
23
|
# %% ../nbs/04_oapi.ipynb #6b2f1057
|
|
@@ -74,6 +75,11 @@ def _bind(self:OpFunc, args, kwargs):
|
|
|
74
75
|
return kwargs
|
|
75
76
|
|
|
76
77
|
# %% ../nbs/04_oapi.ipynb #9327d89c
|
|
78
|
+
def _file_arg(v):
|
|
79
|
+
"Convert a `Path` to an httpx `(filename, bytes, content_type)` tuple; pass other file inputs through."
|
|
80
|
+
if isinstance(v, Path): return (v.name, v.read_bytes(), mimetypes.guess_type(v.name)[0] or 'application/octet-stream')
|
|
81
|
+
return v
|
|
82
|
+
|
|
77
83
|
@patch
|
|
78
84
|
def _split(self:OpFunc, kwargs):
|
|
79
85
|
"Split kwargs into route/query/body/files + control kwargs."
|
|
@@ -88,7 +94,8 @@ def _split(self:OpFunc, kwargs):
|
|
|
88
94
|
route, query, body, files = {}, {}, {}, {}
|
|
89
95
|
for orig,v in params.items():
|
|
90
96
|
if orig in self.route_params: route[orig] = v
|
|
91
|
-
elif orig in self.file_params:
|
|
97
|
+
elif orig in self.file_params:
|
|
98
|
+
if v is not None: files[orig] = _file_arg(v)
|
|
92
99
|
elif orig in self.query_params: query[orig] = v
|
|
93
100
|
elif orig in self.body_params: body[orig] = v
|
|
94
101
|
|
|
@@ -206,7 +213,7 @@ def _upload(self:OpFunc, media, media_type, *, headers, query, route, body):
|
|
|
206
213
|
if hasattr(media, 'read'): media = media.read()
|
|
207
214
|
ctype = media_type or mimetypes.guess_type(fname or '')[0] or 'application/octet-stream'
|
|
208
215
|
url = _path(self.media_url, route_params=route)
|
|
209
|
-
return then(self.client.request(
|
|
216
|
+
return then(self.client.request(self.verb, url, headers={**headers, 'X-Upload-Content-Type': ctype}, params={**query, 'uploadType': 'resumable'}, json=body, raw=True),
|
|
210
217
|
~Self.headers['location'], partial(self.client.request, 'PUT', headers={'Content-Type': ctype}, content=media), dict2obj)
|
|
211
218
|
|
|
212
219
|
# %% ../nbs/04_oapi.ipynb #a45f810a
|
|
@@ -127,14 +127,28 @@ def _schema_props_required(schema, spec):
|
|
|
127
127
|
|
|
128
128
|
# %% ../nbs/03_spec.ipynb #2319e3a4
|
|
129
129
|
_type_map = dict(string=str, integer=int, number=float, boolean=bool, array=list, object=dict)
|
|
130
|
+
_text_media = {'application/json', 'application/xml', 'application/x-www-form-urlencoded'}
|
|
131
|
+
|
|
132
|
+
def _is_binary(schema, spec):
|
|
133
|
+
"True when `schema` describes raw binary data (OpenAPI 3.0 `format: binary` or 3.1 binary `contentMediaType`)."
|
|
134
|
+
if not isinstance(schema, dict): return False
|
|
135
|
+
schema = _resolve_obj(schema, spec)
|
|
136
|
+
if schema.get("format") == "binary": return True
|
|
137
|
+
mt = schema.get("contentMediaType")
|
|
138
|
+
if mt and not schema.get("contentEncoding") and not mt.startswith("text/") and mt not in _text_media: return True
|
|
139
|
+
for key in ("anyOf", "oneOf"):
|
|
140
|
+
subs = [_resolve_obj(s, spec) for s in schema.get(key, [])]
|
|
141
|
+
non_null = [s for s in subs if s.get("type") != "null"]
|
|
142
|
+
if non_null and all(_is_binary(s, spec) for s in non_null): return True
|
|
143
|
+
return False
|
|
130
144
|
|
|
131
145
|
def _schema_py_type(schema, spec):
|
|
132
146
|
"Best-effort Python type from a JSON Schema fragment."
|
|
133
147
|
if not isinstance(schema, dict): return None
|
|
134
148
|
schema = _resolve_obj(schema, spec)
|
|
149
|
+
if _is_binary(schema, spec): return bytes
|
|
135
150
|
t = schema.get("type")
|
|
136
|
-
if isinstance(t, L): t = first(t
|
|
137
|
-
if t == "string" and schema.get("format") == "binary": return bytes
|
|
151
|
+
if isinstance(t, (list, L)): t = first(o for o in t if o != 'null')
|
|
138
152
|
if t in _type_map: return _type_map[t]
|
|
139
153
|
if t == "null": return type(None)
|
|
140
154
|
for key in ("oneOf", "anyOf", "allOf"):
|
|
@@ -208,7 +222,7 @@ def _body_params(op, spec):
|
|
|
208
222
|
return AttrDict(body_params=[], file_params=[], required_params=set(), param_types={},
|
|
209
223
|
param_docs={}, param_defaults={}, request_content_type=ct, body_examples=bexs)
|
|
210
224
|
props, req = _schema_props_required(schema, spec)
|
|
211
|
-
fparams = [k for k,v in props.items() if
|
|
225
|
+
fparams = [k for k,v in props.items() if _is_binary(v, spec)]
|
|
212
226
|
bparams = [k for k in props if k not in fparams]
|
|
213
227
|
ptypes = {k: _schema_py_type(v, spec) for k,v in props.items()}
|
|
214
228
|
pdocs = {k: d for k,v in props.items() if (d := _prop_desc(v, spec))}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: fastspec
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.9
|
|
4
4
|
Summary: Dynamic OpenAPI, Discovery, and GraphQL spec client for Python — turn any API spec into a fully-typed async client with attribute chaining, streaming, and file uploads
|
|
5
5
|
Author-email: Kerem Turgutlu <keremturgutlu@gmail.com>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|