rapid-api-client 0.2.0__tar.gz → 0.3.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: rapid-api-client
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: Rapidly develop your API clients using decorators and annotations
5
5
  Author: Sébastien MB
6
6
  Author-email: seb@essembeh.org
@@ -227,3 +227,7 @@ class MyApi(RapidApi)
227
227
  async def post_xml(self, body: Annotated[ResponseXmlRootModel, PydanticXmlBody()]): ...
228
228
 
229
229
  ```
230
+
231
+ # Examples
232
+
233
+ See [example directory](./examples/) for some examples
@@ -194,4 +194,8 @@ class MyApi(RapidApi)
194
194
  @post("/post")
195
195
  async def post_xml(self, body: Annotated[ResponseXmlRootModel, PydanticXmlBody()]): ...
196
196
 
197
- ```
197
+ ```
198
+
199
+ # Examples
200
+
201
+ See [example directory](./examples/) for some examples
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "rapid-api-client"
3
- version = "0.2.0"
3
+ version = "0.3.0"
4
4
  description = "Rapidly develop your API clients using decorators and annotations"
5
5
  authors = ["Sébastien MB <seb@essembeh.org>"]
6
6
  readme = "README.md"
@@ -6,7 +6,15 @@ from typing import Any, Awaitable, Callable, Dict, Mapping, Self, Tuple, Type, T
6
6
  from httpx import AsyncClient, Request, Response
7
7
  from pydantic import BaseModel
8
8
 
9
- from .model import Body, FileBody, Header, Path, Query, RapidApi, pydantic_xml
9
+ from .model import (
10
+ Body,
11
+ FileBody,
12
+ Header,
13
+ Path,
14
+ Query,
15
+ RapidApi,
16
+ pydantic_xml,
17
+ )
10
18
  from .utils import filter_none_values, find_annotation
11
19
 
12
20
  RESP = TypeVar("RESP", bound=BaseModel | Response)
@@ -34,8 +42,12 @@ class CustomParameters:
34
42
  return out
35
43
 
36
44
 
37
- def build_request(
45
+ REQUEST_BUILDER = Callable[..., Request]
46
+
47
+
48
+ def create_request(
38
49
  client: AsyncClient,
50
+ request_builder: Callable[..., Request],
39
51
  signature: Signature,
40
52
  parameters: CustomParameters,
41
53
  method: str,
@@ -56,12 +68,14 @@ def build_request(
56
68
  for param, annot in parameters.headers.items()
57
69
  }
58
70
  )
71
+
59
72
  params = filter_none_values(
60
73
  {
61
74
  annot.alias or param: ba.arguments[param]
62
75
  for param, annot in parameters.query.items()
63
76
  }
64
77
  )
78
+
65
79
  content = None
66
80
  files = {}
67
81
  for param, annot in parameters.body.items():
@@ -71,13 +85,22 @@ def build_request(
71
85
  else:
72
86
  content = annot.serialize(value)
73
87
 
74
- return client.build_request(
75
- method, path, headers=headers, params=params, content=content, files=files
88
+ return request_builder(
89
+ client,
90
+ method,
91
+ path,
92
+ headers=headers,
93
+ params=params,
94
+ content=content,
95
+ files=files,
76
96
  )
77
97
 
78
98
 
79
99
  def http(
80
- path: str, method: str = "GET", response_class: Type[RESP] = Response
100
+ path: str,
101
+ method: str = "GET",
102
+ response_class: Type[RESP] = Response,
103
+ request_builder: Callable[..., Request] = AsyncClient.build_request,
81
104
  ) -> Callable[[Callable], Callable[..., Awaitable[RESP]]]:
82
105
  def decorator(func: Callable) -> Callable[..., Awaitable[RESP]]:
83
106
  sig = signature(func)
@@ -89,8 +112,15 @@ def http(
89
112
  args[0], RapidApi
90
113
  ), f"{args[0]} should be an instance of RapidApi"
91
114
  client = args[0].client
92
- request = build_request(
93
- client, sig, custom_parameters, method, path, args, kwargs
115
+ request = create_request(
116
+ client,
117
+ request_builder,
118
+ sig,
119
+ custom_parameters,
120
+ method,
121
+ path,
122
+ args,
123
+ kwargs,
94
124
  )
95
125
  response = await client.send(request)
96
126
  if pydantic_xml is not None and issubclass(
@@ -1,5 +1,5 @@
1
1
  from dataclasses import dataclass, field
2
- from typing import Any
2
+ from typing import Any, Dict
3
3
 
4
4
  from httpx import AsyncClient
5
5
  from pydantic import BaseModel
@@ -15,6 +15,14 @@ class RapidApi:
15
15
  client: AsyncClient = field(default_factory=AsyncClient)
16
16
 
17
17
 
18
+ class RequestModifier:
19
+ def update_headers(self, headers: Dict[str, str]) -> Dict[str, str]: ...
20
+
21
+ def update_query(self, query_parameters: Dict[str, str]) -> Dict[str, str]: ...
22
+
23
+ def update_path(self, path: str) -> str: ...
24
+
25
+
18
26
  class CustomParameter: ...
19
27
 
20
28