Reference Guide¶
Traditional Python Sync API¶
- class restfly.APIClient(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, limits=Limits(max_connections=100, max_keepalive_connections=20, keepalive_expiry=5.0), max_redirects=20, event_hooks=None, base_url=None, transport=None, trust_env=True, default_encoding='utf-8', vendor='unknown', product='unknown', build='unknown', retry_max=5, json_load_kwargs=None, json_dump_kwargs=None, xml_load_kwargs=None, xml_dump_kwargs=None, error_map=None, error_class=None)[source]¶
- Parameters:
auth (AuthTypes | None)
params (QueryParamTypes | None)
headers (HeaderTypes | None)
cookies (CookieTypes | None)
verify (SSLContext | str | bool)
cert (CertTypes | None)
http1 (bool)
http2 (bool)
proxy (ProxyTypes | None)
mounts (dict[str, BaseTransport | None] | None)
timeout (TimeoutTypes)
follow_redirects (bool)
limits (Limits)
max_redirects (int)
event_hooks (dict[str, list[EventHook]] | None)
base_url (str | None)
transport (BaseTransport | None)
trust_env (bool)
default_encoding (str | Callable[[bytes], str])
vendor (str)
product (str)
build (str)
retry_max (int)
json_load_kwargs (dict[str, Any] | None)
json_dump_kwargs (dict[str, Any] | None)
xml_load_kwargs (dict[str, Any] | None)
xml_dump_kwargs (dict[str, Any] | None)
error_map (dict[int, ErrorStatus] | None)
error_class (type[APIError] | None)
- _base_url: str = ''¶
The base URL fragment to prefix all API calls with.
- _client: Client¶
HTTPX Client Session object
- _deauthenticate()[source]¶
De-authentication stub. De-authentication is automatically run as part of leaving context within the context manager.
Example
>>> class ExampleAPISession(APISession): ... def _deauthenticate(self): ... self.delete('session/token')
- _delete(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP DELETE request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _error_map: defaultdict[int, ErrorStatus]¶
The error map determining how to handle non-OK status codes. Represented by the integer status code along with an ErrorStatus data-class object detailing how to handle the response. Any overloads to the base error map should be provided here and this attribute will be then be replaced at initialization with the merging of the default map, this attribute, and anything passed to the constructor. The resulting error map will be used during operation of the APIClass object.
- _get(path='', *, response_model=None, response_model_kwargs=None, params=None, headers=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP GET request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
params (QueryParamTypes | None) – Request query parameters.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _json_dump_kwargs: dict[str, Any]¶
Client-level Pydantic BaseModel.model_dump kwargs
- _json_load_kwargs: dict[str, Any]¶
Client-level Pydantic BaseModel.model_validate kwargs
- _lib_name: str = 'RESTFly'¶
Library name
- _lib_version: str = '2'¶
Library version
- _logger: Logger¶
Logger for the client
- _patch(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PATCH request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _post(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP POST request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _put(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PUT request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: ~typing.Literal[None] = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Response[source]¶
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[list[~restfly.types.Model]], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) list[Model]
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model] | type[list[~restfly.types.Model]] | None = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model | list[Model] | Response
Construct and send an HTTP request.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
stream (bool)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _request_hook(request)[source]¶
The Request hook used for debug logging.
- Parameters:
request (Request) – The request object.
- Return type:
None
- _request_pre_process(method, url, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, request_model_kwargs=None, cookies=None, timeout=<httpx._client.UseClientDefault object>, extensions=None)¶
Performs preflight pre-processing of the request in preparation to be sent to HTTPX. Most notably this method is what handles any potential model marshalling into the request format. The output is passed as the kwargs into HTTPXs request builder.
- Parameters:
method (HTTPMethods) – The HTTP Method.
url (str) – The HTTP url (this can be either a partial or a full URL).
params (QueryParamTypes | None) – Query parameters.
content (RequestContent | None) – Raw request content.
data (RequestData | None) – The HTTP request body.
files (RequestFiles | None) – Any files to upload with the request.
json (Model | object | None) – Overrides the content and data attributes with JSON-formatted data.
xml (XMLModel | str | bytes | None) – Overrides the content and data attributes with XML-formatted data.
headers (dict[str, str] | None) – Any additional headers to pass into the request.
request_model_kwargs (dict[str, Any] | None) – The pydantic/pydantic-xml kwargs to be passed to the model as part of marshalling the data into the expected format.
cookies (CookieTypes | None) – The cookies to pass to the request.
timeout (TimeoutTypes | UseClientDefault) – The HTTP request timeout.
extensions (RequestExtensions | None) – Any request extensions passed as part of the request.
- Returns:
The kwargs dictionary to be passed to the request builder.
- Return type:
dict[str, Any]
- _response_hook(response)[source]¶
The Response hook used for informational logging.
- Parameters:
response (Response) – The response object.
- Return type:
None
- _retry_max: int = 5¶
Maximum number of retries to attempt before giving up.
- _retry_request(response)[source]¶
Processes the request from the response for the purpose of retrying it again.
- Parameters:
response (Response) – The response object
- Return type:
Request
- _stream(method, path='', *, params=None, content=None, data=None, files=None, headers=None, json=None, xml=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP request and stream the response back. This is an alternative method to making a call to _request that also supports closing of the response through the use of a context manager.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object with streaming enabled.
- Return type:
Iterator[Response]
- _xml_dump_kwargs: dict[str, Any]¶
Client-level Pydantic-XML BaseXmlModel.to_xml kwargs
- _xml_load_kwargs: dict[str, Any]¶
Client-level Pydantic-XML BaseXmlModel.from_xml kwargs
- class restfly.APIEndpoint(client)[source]¶
- Parameters:
client (APIClient | APIEndpoint)
- _client: APIClient¶
The client object that this endpoint is associated with. Provided here in order to interact with other endpoints that may be grafted to the client.
- _delete(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP DELETE request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _get(path='', *, response_model=None, response_model_kwargs=None, params=None, headers=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP GET request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
params (QueryParamTypes | None) – Request query parameters.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _logger: Logger¶
The same logging handler that the client has, it also exists here for convenience.
- _patch(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PATCH request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _path: str | None = None¶
Path fragment to append to the base url already stored within the client.
- _post(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP POST request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _put(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PUT request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: ~typing.Literal[None] = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Response[source]¶
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[list[~restfly.types.Model]], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) list[Model]
- _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model] | type[list[~restfly.types.Model]] | None = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model | list[Model] | Response
Construct and send an HTTP POST request.
- Parameters:
method (HTTPMethods) – The HTTP method used for the request.
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
stream (bool)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _stream(method, path='', *, params=None, content=None, data=None, files=None, headers=None, json=None, xml=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP request and stream the response back. This is an alternative method to making a call to _request that also supports closing of the response through the use of a context manager.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object with streaming enabled.
- Return type:
Iterator[Response]
Async Python API¶
- class restfly.AsyncAPIClient(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, limits=Limits(max_connections=100, max_keepalive_connections=20, keepalive_expiry=5.0), max_redirects=20, event_hooks=None, base_url=None, transport=None, trust_env=True, default_encoding='utf-8', vendor='unknown', product='unknown', build='unknown', retry_max=5, json_load_kwargs=None, json_dump_kwargs=None, xml_load_kwargs=None, xml_dump_kwargs=None, error_map=None, error_class=None)[source]¶
- Parameters:
auth (AuthTypes | None)
params (QueryParamTypes | None)
headers (HeaderTypes | None)
cookies (CookieTypes | None)
verify (SSLContext | str | bool)
cert (CertTypes | None)
http1 (bool)
http2 (bool)
proxy (ProxyTypes | None)
mounts (dict[str, AsyncBaseTransport | None] | None)
timeout (TimeoutTypes)
follow_redirects (bool)
limits (Limits)
max_redirects (int)
event_hooks (dict[str, list[EventHook]] | None)
base_url (str | None)
transport (AsyncBaseTransport | None)
trust_env (bool)
default_encoding (str | Callable[[bytes], str])
vendor (str)
product (str)
build (str)
retry_max (int)
json_load_kwargs (dict[str, Any] | None)
json_dump_kwargs (dict[str, Any] | None)
xml_load_kwargs (dict[str, Any] | None)
xml_dump_kwargs (dict[str, Any] | None)
error_map (dict[int, ErrorStatus] | None)
error_class (type[APIError] | None)
- _base_url: str = ''¶
The base URL fragment to prefix all API calls with.
- _client: AsyncClient¶
HTTPX Client Session object
- async _deauthenticate()[source]¶
De-authentication stub. De-authentication is automatically run as part of leaving context within the context manager.
Example
>>> class ExampleAPISession(APISession): ... def _deauthenticate(self): ... self.delete('session/token')
- async _delete(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP DELETE request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _error_map: defaultdict[int, ErrorStatus]¶
The error map determining how to handle non-OK status codes. Represented by the integer status code along with an ErrorStatus data-class object detailing how to handle the response. Any overloads to the base error map should be provided here and this attribute will be then be replaced at initialization with the merging of the default map, this attribute, and anything passed to the constructor. The resulting error map will be used during operation of the APIClass object.
- async _get(path='', *, response_model=None, response_model_kwargs=None, request_model_kwargs=None, params=None, headers=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP GET request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
params (QueryParamTypes | None) – Request query parameters.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
request_model_kwargs (dict[str, Any] | None)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _json_dump_kwargs: dict[str, Any]¶
Client-level Pydantic BaseModel.model_dump kwargs
- _json_load_kwargs: dict[str, Any]¶
Client-level Pydantic BaseModel.model_validate kwargs
- _lib_name: str = 'RESTFly'¶
Library name
- _lib_version: str = '2'¶
Library version
- _logger: Logger¶
Logger for the client
- async _patch(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PATCH request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _post(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP POST request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _put(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PUT request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: ~typing.Literal[None] = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Response[source]¶
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[list[~restfly.types.Model]], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) list[Model]
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model] | type[list[~restfly.types.Model]] | None = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model | list[Model] | Response
Construct and send an HTTP request.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
stream (bool)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _request_hook(request)[source]¶
The Request hook used for debug logging.
- Parameters:
request (Request) – The request object.
- Return type:
None
- _request_pre_process(method, url, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, request_model_kwargs=None, cookies=None, timeout=<httpx._client.UseClientDefault object>, extensions=None)¶
Performs preflight pre-processing of the request in preparation to be sent to HTTPX. Most notably this method is what handles any potential model marshalling into the request format. The output is passed as the kwargs into HTTPXs request builder.
- Parameters:
method (HTTPMethods) – The HTTP Method.
url (str) – The HTTP url (this can be either a partial or a full URL).
params (QueryParamTypes | None) – Query parameters.
content (RequestContent | None) – Raw request content.
data (RequestData | None) – The HTTP request body.
files (RequestFiles | None) – Any files to upload with the request.
json (Model | object | None) – Overrides the content and data attributes with JSON-formatted data.
xml (XMLModel | str | bytes | None) – Overrides the content and data attributes with XML-formatted data.
headers (dict[str, str] | None) – Any additional headers to pass into the request.
request_model_kwargs (dict[str, Any] | None) – The pydantic/pydantic-xml kwargs to be passed to the model as part of marshalling the data into the expected format.
cookies (CookieTypes | None) – The cookies to pass to the request.
timeout (TimeoutTypes | UseClientDefault) – The HTTP request timeout.
extensions (RequestExtensions | None) – Any request extensions passed as part of the request.
- Returns:
The kwargs dictionary to be passed to the request builder.
- Return type:
dict[str, Any]
- async _response_hook(response)[source]¶
The Response hook used for informational logging.
- Parameters:
response (Response) – The response object.
- Return type:
None
- _retry_max: int = 5¶
Maximum number of retries to attempt before giving up.
- async _retry_request(response)[source]¶
Processes the request from the response for the purpose of retrying it again.
- Parameters:
response (Response) – The response object
- Return type:
Request
- _stream(method, path='', *, params=None, content=None, data=None, files=None, headers=None, json=None, xml=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP request and stream the response back. This is an alternative method to making a call to _request that also supports closing of the response through the use of a context manager.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object with streaming enabled.
- Return type:
AsyncIterator[Response]
- _xml_dump_kwargs: dict[str, Any]¶
Client-level Pydantic-XML BaseXmlModel.to_xml kwargs
- _xml_load_kwargs: dict[str, Any]¶
Client-level Pydantic-XML BaseXmlModel.from_xml kwargs
- class restfly.AsyncAPIEndpoint(client)[source]¶
- Parameters:
client (AsyncAPIClient | AsyncAPIEndpoint)
- _client: AsyncAPIClient¶
The client object that this endpoint is associated with. Provided here in order to interact with other endpoints that may be grafted to the client.
- async _delete(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP DELETE request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _get(path='', *, response_model=None, response_model_kwargs=None, request_model_kwargs=None, params=None, headers=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP GET request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
params (QueryParamTypes | None) – Request query parameters.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
request_model_kwargs (dict[str, Any] | None)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _logger: Logger¶
The same logging handler that the client has, it also exists here for convenience.
- async _patch(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PATCH request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _path: str | None = None¶
Path fragment to append to the base url already stored within the client.
- async _post(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP POST request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _put(path='', *, params=None, content=None, data=None, files=None, json=None, xml=None, headers=None, response_model=None, response_model_kwargs=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP PUT request.
- Parameters:
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: ~typing.Literal[None] = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Response[source]¶
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[list[~restfly.types.Model]], params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) list[Model]
- async _request(method: ~typing.Literal['GET', 'OPTIONS', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'], path: str = '', *, response_model: type[~restfly.types.Model] | type[list[~restfly.types.Model]] | None = None, params: QueryParamTypes | None = None, content: str | bytes | ~typing.Iterable[bytes] | ~typing.AsyncIterable[bytes] | None = None, data: ~typing.Mapping[str, ~typing.Any] | None = None, files: ~typing.Mapping[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]] | ~typing.Sequence[~typing.Tuple[str, ~typing.IO[bytes] | bytes | str | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None] | ~typing.Tuple[str | None, ~typing.IO[bytes] | bytes | str, str | None, ~typing.Mapping[str, str]]]] | None = None, json: ~restfly.types.Model | ~typing.Any | None = None, xml: ~restfly.types.XMLModel | str | bytes | None = None, response_model_kwargs: dict[str, ~typing.Any] | None = None, request_model_kwargs: dict[str, ~typing.Any] | None = None, headers: dict[str, str] | None = None, cookies: CookieTypes | None = None, auth: AuthTypes | UseClientDefault | None = <httpx._client.UseClientDefault object>, follow_redirects: bool | ~httpx._client.UseClientDefault = <httpx._client.UseClientDefault object>, timeout: TimeoutTypes | UseClientDefault = <httpx._client.UseClientDefault object>, extensions: ~typing.Mapping[str, ~typing.Any] | None = None, max_retries: int | None = None, error_map: dict[int, ~restfly._errors.ErrorStatus] | None = None, stream: bool = False) Model | list[Model] | Response
Construct and send an HTTP request.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
response_model (type[Model] | type[list[Model]] | None) – Pydantic model to coerce the response into.
response_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of un-marshalling the response data.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
stream (bool)
- Returns:
Returns the HTTPX Response object if no response_model is specified. If a response_model _is_ specified, then the response will be coerced into the response model and the instance of the model will be returned.
- Return type:
Model | list[Model] | Response
- _stream(method, path='', *, params=None, content=None, data=None, files=None, headers=None, json=None, xml=None, request_model_kwargs=None, cookies=None, auth=<httpx._client.UseClientDefault object>, follow_redirects=<httpx._client.UseClientDefault object>, timeout=<httpx._client.UseClientDefault object>, extensions=None, max_retries=None, error_map=None)¶
Construct and send an HTTP request and stream the response back. This is an alternative method to making a call to _request that also supports closing of the response through the use of a context manager.
- Parameters:
method (HTTPMethods) – The HTTP method used to make the call.
path (str) – URL to query.
request_model_kwargs (dict[str, Any] | None) – Keyword arguments to pass to Pydantic/Pydantic-XML as part of marshalling the body of the data into the request.
params (QueryParamTypes | None) – Request query parameters.
content (RequestContent | None) – Raw body of the request.
data (RequestData | None) – URL form-encoded body for the request.
json (Model | Any | None) – Data object to marshal into JSON. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.xml (XMLModel | str | bytes | None) – Data object to marshal into XML. Content passed with this parameter will also set the
Content-Typeheader toapplication/json.files (RequestFiles | None) – A dictionary of upload files to include in the body of the request.
headers (dict[str, str] | None) – Request-specific headers.
cookies (CookieTypes | None) – Request-specific cookies.
auth (AuthTypes | UseClientDefault | None) – Request-specific authentication.
follow_redirects (bool | UseClientDefault) – Should the client follow any redirects?
timeout (TimeoutTypes | UseClientDefault) – Request-specific timeout settings.
extensions (RequestExtensions | None) – Any additional httpx extensions to pass to the client.
max_retries (int | None) – The maximum number of retries to attempt before giving up. Overloads the client default.
error_map (dict[int, ErrorStatus] | None) – Replaces the client error map with this one instead.
- Returns:
Returns the HTTPX Response object with streaming enabled.
- Return type:
AsyncIterator[Response]
APIModels¶
- class restfly.APIModel[source]¶
- _setattr_handler(name, value)¶
Get a handler for setting an attribute on the model instance.
- Returns:
A handler for setting an attribute on the model instance. Used for memoization of the handler. Memoizing the handlers leads to a dramatic performance improvement in __setattr__ Returns None when memoization is not safe, then the attribute is set directly.
- Parameters:
name (str)
value (Any)
- Return type:
Callable[[BaseModel, str, Any], None] | None
- async async_save()[source]¶
Saves (updates) the current state of the object back to the API.
- Returns:
Updated copy of the object from the upstream API.
- Return type:
Self
- copy(*, include=None, exclude=None, update=None, deep=False)¶
Returns a copy of the model.
- !!! warning “Deprecated”
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
`python {test="skip" lint="skip"} data = self.model_dump(include=include, exclude=exclude, round_trip=True) data = {**data, **(update or {})} copied = self.model_validate(data) `- Parameters:
include (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to include in the copied model.
exclude (AbstractSetIntStr | MappingIntStrAny | None) – Optional set or mapping specifying which fields to exclude in the copied model.
update (Dict[str, Any] | None) – Optional dictionary of field-value pairs to override field values in the copied model.
deep (bool) – If True, the values of fields that are Pydantic models will be deep-copied.
- Returns:
A copy of the model with included, excluded and updated fields as specified.
- Return type:
Self
- model_config = {}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod model_construct(_fields_set=None, **values)¶
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.
- !!! note
model_construct() generally respects the model_config.extra setting on the provided model. That is, if model_config.extra == ‘allow’, then all extra passed values are added to the model instance’s __dict__ and __pydantic_extra__ fields. If model_config.extra == ‘ignore’ (the default), then all extra passed values are ignored. Because no validation is performed with a call to model_construct(), having model_config.extra == ‘forbid’ does not result in an error if extra values are passed, but they will be ignored.
- Parameters:
_fields_set (set[str] | None) – A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the [model_fields_set][pydantic.BaseModel.model_fields_set] attribute. Otherwise, the field names from the values argument will be used.
values (Any) – Trusted or pre-validated data dictionary.
- Returns:
A new instance of the Model class with validated data.
- Return type:
Self
- model_copy(*, update=None, deep=False)¶
- !!! abstract “Usage Documentation”
[model_copy](../concepts/models.md#model-copy)
Returns a copy of the model.
- !!! note
The underlying instance’s [__dict__][object.__dict__] attribute is copied. This might have unexpected side effects if you store anything in it, on top of the model fields (e.g. the value of [cached properties][functools.cached_property]).
- Parameters:
update (Mapping[str, Any] | None) – Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.
deep (bool) – Set to True to make a deep copy of the model.
- Returns:
New model instance.
- Return type:
Self
- model_dump(*, mode='python', include=None, exclude=None, context=None, by_alias=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, exclude_computed_fields=False, round_trip=False, warnings=True, fallback=None, serialize_as_any=False, polymorphic_serialization=None)¶
- !!! abstract “Usage Documentation”
[model_dump](../concepts/serialization.md#python-mode)
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode (Literal['json', 'python'] | str) – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include (set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to include in the output.
exclude (set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – A set of fields to exclude from the output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool | None) – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
exclude_computed_fields (bool) – Whether to exclude computed fields. While this can be useful for round-tripping, it is usually recommended to use the dedicated round_trip parameter instead.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
fallback (Callable[[Any], Any] | None) – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
polymorphic_serialization (bool | None) – Whether to use model and dataclass polymorphic serialization for this call.
- Returns:
A dictionary representation of the model.
- Return type:
dict[str, Any]
- model_dump_json(*, indent=None, ensure_ascii=False, include=None, exclude=None, context=None, by_alias=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, exclude_computed_fields=False, round_trip=False, warnings=True, fallback=None, serialize_as_any=False, polymorphic_serialization=None)¶
- !!! abstract “Usage Documentation”
[model_dump_json](../concepts/serialization.md#json-mode)
Generates a JSON representation of the model using Pydantic’s to_json method.
- Parameters:
indent (int | None) – Indentation to use in the JSON output. If None is passed, the output will be compact.
ensure_ascii (bool) – If True, the output is guaranteed to have all incoming non-ASCII characters escaped. If False (the default), these characters will be output as-is.
include (set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to include in the JSON output.
exclude (set[int] | set[str] | Mapping[int, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | Mapping[str, set[int] | set[str] | Mapping[int, IncEx | bool] | Mapping[str, IncEx | bool] | bool] | None) – Field(s) to exclude from the JSON output.
context (Any | None) – Additional context to pass to the serializer.
by_alias (bool | None) – Whether to serialize using field aliases.
exclude_unset (bool) – Whether to exclude fields that have not been explicitly set.
exclude_defaults (bool) – Whether to exclude fields that are set to their default value.
exclude_none (bool) – Whether to exclude fields that have a value of None.
exclude_computed_fields (bool) – Whether to exclude computed fields. While this can be useful for round-tripping, it is usually recommended to use the dedicated round_trip parameter instead.
round_trip (bool) – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings (bool | Literal['none', 'warn', 'error']) – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
fallback (Callable[[Any], Any] | None) – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.
serialize_as_any (bool) – Whether to serialize fields with duck-typing serialization behavior.
polymorphic_serialization (bool | None) – Whether to use model and dataclass polymorphic serialization for this call.
- Returns:
A JSON string representation of the model.
- Return type:
str
- property model_extra: dict[str, Any] | None¶
Get extra fields set during validation.
- Returns:
A dictionary of extra fields, or None if config.extra is not set to “allow”.
- property model_fields_set: set[str]¶
Returns the set of fields that have been explicitly set on this model instance.
- Returns:
- A set of strings representing the fields that have been set,
i.e. that were not filled from defaults.
- classmethod model_json_schema(by_alias=True, ref_template='#/$defs/{model}', schema_generator=<class 'pydantic.json_schema.GenerateJsonSchema'>, mode='validation', *, union_format='any_of')¶
Generates a JSON schema for a model class.
- Parameters:
by_alias (bool) – Whether to use attribute aliases or not.
ref_template (str) – The reference template.
union_format (Literal['any_of', 'primitive_type_array']) –
The format to use when combining schemas from unions together. Can be one of:
’any_of’: Use the [anyOf](https://json-schema.org/understanding-json-schema/reference/combining#anyOf)
keyword to combine schemas (the default). - ‘primitive_type_array’: Use the [type](https://json-schema.org/understanding-json-schema/reference/type) keyword as an array of strings, containing each type of the combination. If any of the schemas is not a primitive type (string, boolean, null, integer or number) or contains constraints/metadata, falls back to any_of.
schema_generator (type[GenerateJsonSchema]) – To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications
mode (Literal['validation', 'serialization']) – The mode in which to generate the schema.
- Returns:
The JSON schema for the given model class.
- Return type:
dict[str, Any]
- classmethod model_parametrized_name(params)¶
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
- Parameters:
params (tuple[type[Any], ...]) – Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.
- Returns:
String representing the new class where params are passed to cls as type variables.
- Raises:
TypeError – Raised when trying to generate concrete names for non-generic models.
- Return type:
str
- model_post_init(context)[source]¶
Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.
- Parameters:
context (Any)
- Return type:
Any
- classmethod model_rebuild(*, force=False, raise_errors=True, _parent_namespace_depth=2, _types_namespace=None)¶
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
- Parameters:
force (bool) – Whether to force the rebuilding of the model schema, defaults to False.
raise_errors (bool) – Whether to raise errors, defaults to True.
_parent_namespace_depth (int) – The depth level of the parent namespace, defaults to 2.
_types_namespace (MappingNamespace | None) – The types namespace, defaults to None.
- Returns:
Returns None if the schema is already “complete” and rebuilding was not required. If rebuilding _was_ required, returns True if rebuilding was successful, otherwise False.
- Return type:
bool | None
- classmethod model_validate(obj, *, strict=None, extra=None, from_attributes=None, context=None, by_alias=None, by_name=None)¶
Validate a pydantic model instance.
- Parameters:
obj (Any) – The object to validate.
strict (bool | None) – Whether to enforce types strictly.
extra (Literal['allow', 'ignore', 'forbid'] | None) – Whether to ignore, allow, or forbid extra data during model validation. See the [extra configuration value][pydantic.ConfigDict.extra] for details.
from_attributes (bool | None) – Whether to extract data from object attributes.
context (Any | None) – Additional context to pass to the validator.
by_alias (bool | None) – Whether to use the field’s alias when validating against the provided input data.
by_name (bool | None) – Whether to use the field’s name when validating against the provided input data.
- Raises:
ValidationError – If the object could not be validated.
- Returns:
The validated model instance.
- Return type:
Self
- classmethod model_validate_json(json_data, *, strict=None, extra=None, context=None, by_alias=None, by_name=None)¶
- !!! abstract “Usage Documentation”
[JSON Parsing](../concepts/json.md#json-parsing)
Validate the given JSON data against the Pydantic model.
- Parameters:
json_data (str | bytes | bytearray) – The JSON data to validate.
strict (bool | None) – Whether to enforce types strictly.
extra (Literal['allow', 'ignore', 'forbid'] | None) – Whether to ignore, allow, or forbid extra data during model validation. See the [extra configuration value][pydantic.ConfigDict.extra] for details.
context (Any | None) – Extra variables to pass to the validator.
by_alias (bool | None) – Whether to use the field’s alias when validating against the provided input data.
by_name (bool | None) – Whether to use the field’s name when validating against the provided input data.
- Returns:
The validated Pydantic model.
- Raises:
ValidationError – If json_data is not a JSON string or the object could not be validated.
- Return type:
Self
- classmethod model_validate_strings(obj, *, strict=None, extra=None, context=None, by_alias=None, by_name=None)¶
Validate the given object with string data against the Pydantic model.
- Parameters:
obj (Any) – The object containing string data to validate.
strict (bool | None) – Whether to enforce types strictly.
extra (Literal['allow', 'ignore', 'forbid'] | None) – Whether to ignore, allow, or forbid extra data during model validation. See the [extra configuration value][pydantic.ConfigDict.extra] for details.
context (Any | None) – Extra variables to pass to the validator.
by_alias (bool | None) – Whether to use the field’s alias when validating against the provided input data.
by_name (bool | None) – Whether to use the field’s name when validating against the provided input data.
- Returns:
The validated Pydantic model.
- Return type:
Self
Iterators¶
- class restfly.APIIterator(client, **kw)[source]¶
The API iterator provides a scalable way to work through result sets of any size. The iterator will walk through each page of data, returning one record at a time. If it reaches the end of a page of records, then it will request the next page of information and then continue to return records from the next page (and the next, and the next) until the counter reaches the total number of records that the API has reported.
Note that this Iterator is used as a base model for all of the iterators, and while the mechanics of each iterator may vary, they should all behave to the user in a similar manner.
- Parameters:
client (APIClient)
- _get_page()[source]¶
A method to be overloaded in order to instruct the iterator how to retrieve the next page of data.
Example
>>> class ExampleIterator(APIIterator): ... def _get_page(self): ... self.total = 100 ... items = range(10) ... self.page = [{'id': i + self._offset} for i in items] ... self._offset += self._limit
- Return type:
None
- _increment_counters()[source]¶
Handles incrementing all of the counters that are controlling the next item to be retrieved.
- Return type:
None
- count: int = 0¶
Current count of objects that have been returned.
- get(key, default=None)[source]¶
Retrieves an item from the the current page based off of the key.
- Parameters:
key (int) – The index of the item to retrieve.
default (obj) – The returned object if the item does not exist.
- Return type:
Any
Examples
>>> a = APIIterator() >>> a.get(2) None
- max_items: int | None = None¶
The maximum number of objects to return before terminating.
- max_pages: int | None = None¶
The maximum number of pages to request before terminating.
- num_pages: int = 0¶
The number of pages that have been requested.
- page: list[Any]¶
The current page of data.
- page_count: int = 0¶
Current count of objects from the current page that have been returned.
- total: int | None = None¶
The total number of objects that could be returned.
- class restfly.AsyncAPIIterator(client, **kw)[source]¶
The API iterator provides a scalable way to work through result sets of any size. The iterator will walk through each page of data, returning one record at a time. If it reaches the end of a page of records, then it will request the next page of information and then continue to return records from the next page (and the next, and the next) until the counter reaches the total number of records that the API has reported.
Note that this Iterator is used as a base model for all of the iterators, and while the mechanics of each iterator may vary, they should all behave to the user in a similar manner.
- Parameters:
client (AsyncAPIClient)
- _client: AsyncAPIClient¶
The API Client object to use for calling the API.
- async _get_page()[source]¶
A method to be overloaded in order to instruct the iterator how to retrieve the next page of data.
Example
>>> class ExampleIterator(APIIterator): ... def _get_page(self): ... self.total = 100 ... items = range(10) ... self.page = [{'id': i + self._offset} for i in items] ... self._offset += self._limit
- Return type:
None
- _increment_counters()[source]¶
Handles incrementing all of the counters that are controlling the next item to be retrieved.
- Return type:
None
- count: int = 0¶
Current count of objects that have been returned.
- async get(key, default=None)[source]¶
Retrieves an item from the the current page based off of the key.
- Parameters:
key (int) – The index of the item to retrieve.
default (obj) – The returned object if the item does not exist.
- Return type:
Any
Examples
>>> a = APIIterator() >>> a.get(2) None
- max_items: int | None = None¶
The maximum number of objects to return before terminating.
- max_pages: int | None = None¶
The maximum number of pages to request before terminating.
- num_pages: int = 0¶
The number of pages that have been requested.
- page: list[Any]¶
The current page of data.
- page_count: int = 0¶
Current count of objects from the current page that have been returned.
- total: int | None = None¶
The total number of objects that could be returned.
Error Handling¶
- class restfly.APIError(response, template, obj=None)[source]¶
The Base API Error class to be thrown in the event that a non-OK status code is returned.
- Parameters:
response (Response)
template (str)
obj (BaseModel | None)
- add_note()¶
Exception.add_note(note) – add a note to the exception
- obj: BaseModel | None¶
Coerced data obj of the response (if any)
- response: Response¶
HTTPX Response object of the exception
- status_code: int¶
Status code of the HTTP Response
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class restfly.RetryError(url, method, attempts)[source]¶
RetryError is thrown when too many retries have been made to the endpoint and we have been forced to stop attempting to call the API endpoint.
- Parameters:
url (str)
method (str)
attempts (int)
- add_note()¶
Exception.add_note(note) – add a note to the exception
- with_traceback()¶
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class restfly.ErrorStatus(retry=False, template='[{response.status_code}] Response from {request.method} {request.url}', model=None, exception=<class 'restfly._errors.APIError'>, backoff=1.0, jitter=0.5)[source]¶
Defines the attributes associated to each non-OK status code.
- Parameters:
retry (bool) – Should the request be retried?
template (str) – The log/exception to be sent. This string template will accept both the request and response objects.
model (type[BaseModel] | None) – The Pydantic model (if any) to coerce the response body into.
exception (type[APIError]) – The Exception class to throw.
backoff (float) – How many seconds to wait before retrying? This field will be overloaded if the client detects a Retry-After header and will use the response value instead of this if it exists.
jitter (float) – If this value is set to a non-zero value, then when calculating the amount of time to wait, the client will randomly select a value between 0 and this value and append it to the wait before retying. Normally we will want this set to something in order to ensure that we stagger retries to the API to prevent overwhelming it.