Async Client¶
- def__post_init__
- asyncclose
- asyncdelete
- asyncget
- asyncpatch
- asyncpost
- asyncput
- asyncrequest
- asyncstream_file
- asyncupload_file
- class arya_api_framework.AsyncClient(uri=None, *args, headers=None, cookies=None, parameters=None, error_responses=None, bearer_token=None, rate_limit=None, rate_limit_interval=None, **kwargs)¶
The asynchronous API client class. Utilizes the aiohttp module.
- Parameters
The base URI that will prepend all requests made using the client.
Warning
This should always either be passed as an argument here or as a subclass argument. If neither are given, an
errors.AsyncClientErrorexception will be raised.- Keyword Arguments
headers¶ (Optional[Union[
dict,BaseModel]) – The default headers to pass with every request. Can be overridden by individual requests. Defaults toNone.cookies¶ (Optional[Union[
dict,BaseModel]) – The default cookies to pass with every request. Can be overridden by individual requests. Defaults toNone.parameters¶ (Optional[Union[
dict,BaseModel]]) – The default parameters to pass with every request. Can be overridden by individual requests. Defaults toNone.error_responses¶ (Optional[
dict]) – A mapping ofinterror codes toBaseModeltypes to use when that error code is received. Defaults toNoneand raises default exceptions for error codes.bearer_token¶ (Optional[
str, pydantic.SecretStr) – Abearer_tokenthat will be sent with requests in theAuthorizationheader. Defaults toNonerate_limit¶ (Optional[Union[
int,float]]) – The number of requests to allow overrate_limit_intervalseconds. Defaults toNonerate_limit_interval¶ (Optional[Union[
int,float]]) – The period of time, in seconds, over which to apply the rate limit per everyrate_limitrequests. Defaults to1second.
Tip
All of the arguments that can be used when instantiating a client can also be used as subclass parameters:
class MyClient(SyncClient, uri="https://exampleurl.com", parameters={"arg1": "abc"}): pass
Then, when instantiating the client, any arguments passed directly to the class will update the subclass parameters.
- closed¶
Whether of not the internal
requests.Sessionhas been closed. If the session has been closed, the client will not allow any further requests to be made.- Type
- headers¶
The default headers that will be passed into every request, unless overridden.
- Type
Optional[
dict]
- cookies¶
The default cookies that will be passed into every request, unless overridden.
- Type
Optional[
dict]
- parameters¶
The default parameters that will be passed into every request, unless overridden.
- Type
Optional[
dict]
- error_responses¶
A mapping of
interror codes to theBaseModelthat should be used to represent them.Note
By default, an internal exception mapping is used. See Exception Hierarchy.
- Type
Optional[
dict]
- rate_limit¶
The number of requests per
rate_limit_intervalthe client is allowed to send.
- rate_limit_interval¶
The interval, in seconds, over which to apply a rate limit for
rate_limitrequests per interval.
- __post_init__(*args, **kwargs)¶
This method is run after the
__init__method is called, and is passed any extra arguments or keyword arguments that the regular init method did not recognize.Tip
By using this method, it becomes unnecessary to override the
__init__method. Instead, any extra parameters can be provided in this method, which has no implementation at default.Example
This is a quick example showing how one might add a default
apiKeyparameter to their custom API client using the__post_init__()method.class MyAsyncClient(AsyncClient): api_key: str def __post_init__(self, *args, api_key: str = None, **kwargs): self.api_key = api_key self.parameters['apiKey'] = self.api_key client = MyAsyncClient('https://exampleurl.com', api_key='mysecretkey') # >>> client.parameters { "apiKey": "mysecretkey" }
- await request(method, path=None, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a request to the
pathspecified using the internalaiohttp.ClientSession.Note
If the client has been
closed(usingclose()), the request will not be processed. Instead, a warning will be logged, and this method will returnNone.- Parameters
- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) – Optional data to send as a JSON structure in the body of the request. Defaults toNone.data¶ (Optional[
Any]) – Optional data of any type to send in the body of the request, without any pre-processing. Defaults toNone.headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await upload_file(file, path=None, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalaiohttp.ClientSession, which will upload a givenfile.Tip
To stream larger file uploads, use the
stream_file()method.- Parameters
- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await stream_file(file, path=None, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalaiohttp.ClientSession, which will upload a givenfile.Tip
This method is meant to upload larger files in a stream manner, while the
upload_file()method uploads the file without streaming it.- Parameters
- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await get(path=None, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a GET request to the
pathspecified using the internalaiohttp.ClientSession.- Parameters
path¶ (Optional[
str]) – The path, relative to the client’suri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the GET request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the GET request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the GET request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await post(path=None, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalaiohttp.ClientSession.- Parameters
path¶ (Optional[
str]) – The path, relative to the client’suri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) – Optional data to send as a JSON structure in the body of the request. Defaults toNone.data¶ (Optional[
Any]) – Optional data of any type to send in the body of the request, without any pre-processing. Defaults toNone.headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await patch(path=None, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a PATCH request to the
pathspecified using the internalaiohttp.ClientSession.- Parameters
path¶ (Optional[
str]) – The path, relative to the client’suri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) – Optional data to send as a JSON structure in the body of the request. Defaults toNone.data¶ (Optional[
Any]) – Optional data of any type to send in the body of the request, without any pre-processing. Defaults toNone.headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await put(path=None, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a PUT request to the
pathspecified using the internalaiohttp.ClientSession.- Parameters
path¶ (Optional[
str]) – The path, relative to the client’suri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) – Optional data to send as a JSON structure in the body of the request. Defaults toNone.data¶ (Optional[
Any]) – Optional data of any type to send in the body of the request, without any pre-processing. Defaults toNone.headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await delete(path=None, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None)¶
This function is a coroutine.
This method enforces data validation.
This method can enforce rate limits.
Sends a DELETE request to the
pathspecified using the internalaiohttp.ClientSession.- Parameters
path¶ (Optional[
str]) – The path, relative to the client’suri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) – Optional data to send as a JSON structure in the body of the request. Defaults toNone.data¶ (Optional[
Any]) – Optional data of any type to send in the body of the request, without any pre-processing. Defaults toNone.headers¶ (Optional[
dict,BaseModel]) – Request-specific headers to send with the request. Defaults toNoneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) – Request-specific query string parameters to send with the request. Defaults toNoneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) – The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults toNone, and the request will return a JSON structure.timeout¶ (Optional[
int]) – The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) – A mapping ofintstatus codes toBaseModelmodels to use as error responses. Defaults toNone, and uses the defaulterror_responsesattribute. If theerror_responsesis alsoNone, or a status code does not have a specified response format, the default status code exceptions will be raised.
- Returns
Optional[Union[
dict,Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise.
- await close()¶
Closes the current
aiohttp.ClientSession, if not already closed.