typerdrive Client modules
typerdrive.client.attach
Provide a decorator that attaches TyperdriveClient
instances to a typer
command function.
Attributes
Classes
Functions
attach_client
attach_client(
**client_urls_or_settings_keys: str,
) -> Callable[
[ContextFunction[P, T]], ContextFunction[P, T]
]
Attach TyperdriveClient
instances to the decorated typer
command function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_urls_or_settings_keys
|
str
|
A key/value mapping for base urls to use in the clients. The key will be the name of the client. The value will be either the base url to be used by the client or a key to the settings where the base url can be found. |
{}
|
Source code in src/typerdrive/client/attach.py
get_client
Retrieve a specific TyperdriveClient
from the TyperdriveContext
.
get_client_manager
Retrieve the ClientManager
from the TyperdriveContext
.
Source code in src/typerdrive/client/attach.py
typerdrive.client.base
Provide a specialized HTTP client for making requests to APIs.
Classes
TyperdriveClient
Bases: Client
Extend the http.Client
with *_x()
methods that provide useful features for processing requests.
Source code in src/typerdrive/client/base.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
Functions
delete_x
delete_x(
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a DELETE request against an API using the request_x()
method.
Source code in src/typerdrive/client/base.py
get_x
get_x(
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a GET request against an API using the request_x()
method.
Source code in src/typerdrive/client/base.py
patch_x
patch_x(
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a PATCH request against an API using the request_x()
method.
Source code in src/typerdrive/client/base.py
post_x
post_x(
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a POST request against an API using the request_x()
method.
Source code in src/typerdrive/client/base.py
put_x
put_x(
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a PUT request against an API using the request_x()
method.
Source code in src/typerdrive/client/base.py
request_x
request_x(
method: str,
url: URL | str,
*,
param_obj: BaseModel | None = None,
body_obj: BaseModel | None = None,
expected_status: int | None = None,
expect_response: bool = True,
response_model: type[RM] | None = None,
**request_kwargs: Any,
) -> RM | int | dict[str, Any]
Make a request against an API.
Provides functionality to take url params and request body from instances of pydantic
models.
Also, provides checks for the status code returned from the API.
Will deserialize the response into a pydantic
model if one is provided.
Note that all the arguments of httpx.Client
are also supported.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
str
|
The HTTP method to use in the request |
required |
url
|
URL | str
|
The url to use for the request. Will be appended to |
required |
param_obj
|
BaseModel | None
|
An optional |
None
|
body_obj
|
BaseModel | None
|
An optional |
None
|
expected_status
|
int | None
|
If provided, check the response code from the API. If the code doesn't match, raise an exception. |
None
|
expect_response
|
bool
|
If set, expect the response to have a JSON body that needs to be deserialized. If not set, just return the status code. |
True
|
response_model
|
type[RM] | None
|
If provided, deserialize the response into an instance of this model. If not provided, the return value will just be a dictionary containing the response data. |
None
|
Source code in src/typerdrive/client/base.py
typerdrive.client.exceptions
Provide exceptions specific to the client feature of typerdrive
.
Classes
ClientError
Bases: TyperdriveError
The base exception for client errors.
Source code in src/typerdrive/client/exceptions.py
typerdrive.client.manager
Provide a class for managing the typerdrive
client feature.
Classes
ClientManager
Manage instances of TyperdriveClient
.
Source code in src/typerdrive/client/manager.py
Attributes
clients
instance-attribute
The `TyperdriveClient instances to manage.
Functions
__init__
add_client
Add a TyperdriveClient
under the given name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the client |
required |
spec
|
ClientSpec
|
A |
required |
Source code in src/typerdrive/client/manager.py
get_client
Fetch a client from the manager matching the given name.