API Reference¶
These are the most common structures that will be included in nearly every project.
Sync Client¶
- defadd_subclient
- defclose
- defdelete
- defget
- defload_extension
- defpatch
- defpost
- defput
- defreload_extension
- defremove_subclient
- defrequest
- defstream_file
- deftree
- defunload_extension
- defupload_file
- class arya_api_framework.SyncClient(*args, **kwargs)¶
The core API framework client for synchronous API integration.
Warning
All of the configuration for this class and its subclasses are done through subclass parameters. This means that the
__init__method can be used for any extra setup for your specific use-case. The parameters shown below are for subclass parameters only.Example:¶class MyClient( SyncClient, uri="https://exampleurl.com", parameters={"arg1": "abc"} ): ...
- Keyword Arguments
This is a keyword only argument.
The base URI that will prepend all requests made using the client.
Warning
This should always be passed. If it is not given, an
errors.ClientErrorexception will be raised.headers¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
The default headers to pass with every request. Can be overridden by individual requests. Defaults to
None.cookies¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
The default cookies to pass with every request. Can be overridden by individual requests. Defaults to
None.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
The default parameters to pass with every request. Can be overridden by individual requests. Defaults to
None.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
interror codes toBaseModeltypes to use when that error code is received. Defaults toNoneand raises default exceptions for error codes.bearer_token¶ (Optional[Union[
str, pydantic.SecretStr]]) –This is a keyword only argument.
A
bearer_tokenthat will be sent with requests in theAuthorizationheader. Defaults toNonerate_limit¶ (Optional[Union[
int,float]]) –This is a keyword only argument.
The number of requests to allow over
rate_limit_intervalseconds. Defaults toNonerate_limit_interval¶ (Optional[Union[
int,float]]) –This is a keyword only argument.
The period of time, in seconds, over which to apply the rate limit per every
rate_limitrequests. Defaults to1second.
- closed¶
This is a read-only attribute.
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
- extensions¶
This is a read-only attribute.
A mapping of extensions by name to extension.
- Type
Mapping[
str,types.ModuleType]
- subclients¶
This is a read-only attribute.
A mapping of sub-clients by name to sub-client.
- uri¶
This is a read-only attribute.
The base URI that will prepend all requests made using the client.
- Type
Optional[
yarl.URL]
- uri_root¶
This is a read-only attribute.
The root origin of the
urigiven to the client.- Type
Optional[
yarl.URL]
- uri_path¶
This is a read-only attribute.
The path from the
uri_rootto theuripath.- Type
Optional[
yarl.URL]
- headers¶
The default headers that will be passed into every request, unless overridden.
- Type
Optional[
dict]
- bearer_token¶
The token used for the
Authorizationfield of theheadersattribute. Sets theAuthorizationheader toBearer {bearer_token}.- Type
Optional[
str]
- 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 either aBaseModelthat should be used to represent them, or a function to be used as a handler for errors of that type.Note
By default, an internal exception mapping is used. See Exception Hierarchy.
- Type
Optional[
dict]
- rate_limit¶
This is a read-only attribute.
The number of requests per
rate_limit_intervalthe client is allowed to send.
- rate_limit_interval¶
This is a read-only attribute.
The interval, in seconds, over which to apply a rate limit for
rate_limitrequests per interval.
- is_rate_limited¶
This is a read-only attribute.
Whether or not the client has a rate limit set.
- Type
- request(method, path='', /, *, body=None, data=None, files=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a request to the
pathspecified using the internalrequests.Session.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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.This is a keyword only argument.
A mapping of
strfile names to file objects to send in the request.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- upload_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalrequests.Session, which will upload a givenfile.Tip
To stream larger file uploads, use the
stream_file()method.- Parameters
- Keyword Arguments
headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- stream_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalrequests.Session, 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]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- get(path='', *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a GET request to the
pathspecified using the internalrequests.Session.- Parameters
This is a positional only argument.
The path, relative to the client’s
uri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the GET request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the GET request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the GET request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- post(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a POST request to the
pathspecified using the internalrequests.Session.- Parameters
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- patch(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a PATCH request to the
pathspecified using the internalrequests.Session.- Parameters
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- put(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a PUT request to the
pathspecified using the internalrequests.Session.- Parameters
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) – Request-specific cookies to send with the request. Defaults toNoneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- delete(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This method enforces data validation.
This method can enforce rate limits.
Sends a DELETE request to the
pathspecified using the internalrequests.Session.- Parameters
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw response object instead of parsing the results as a JSON response, or loading it to a
BaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,requests.Response]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseobject.
- close()¶
Closes the current
requests.Session, if not already closed.Unloads any loaded extensions and
SubClients.
- add_subclient(subclient)¶
Loads a
SubClientas a child route of the primary client. Loaded sub-clients can be viewed throughsubclients.Note
- Any
SubClientmust meet a few requirements in order to be added to a parent: The SubClient cannot already be loaded to a different parent.
The SubClient cannot already be loaded to the current parent.
The SubClient cannot be loaded to itself as a parent.
- Parameters
subclient¶ (
SubClient) – The sub-client to add as a child of the parent client tree.- Raises
ValueError – Raised if the
subclientis not aSubClient.errors.SubClientError – Raised if the
subclientis added as a child of itself.errors.SubClientAlreadyLoaded – Raised if the
subclientis already loaded to the current client.errors.SubClientParentSet – Raised if the
subclientalready has aparentset.
- Any
- load_extension(name, *, package=None)¶
Loads an extension.
An extension is a separate python module (file) that contains a sub-group of requests.
Any extension module should include a function
setupdefined as the entry point for loading the extension, which takes a single argument of aclient, either aSyncClientor anAsyncClient.Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be imported. This usually means that the extension file could not be found.
ExtensionAlreadyLoaded – The extension is already loaded to the client.
ExtensionEntryPointError – The extension has no
setupfunction in it.ExtensionFailed – The extension threw an error while executing the
setupfunction.
- reload_extension(name, *, package=None)¶
Unloads, and then loads an extension.
This is the same as an
unload_extension()followed by aload_extension(). If the reload fails, the client will roll-back to the previous working extension version.Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be found. This usually means that the extension file could not be found.
ExtensionNotLoaded – The extension is not loaded to the client, and therefore cannot be unloaded.
- remove_subclient(name)¶
Removes a loaded child
SubClientfrom the primary client. Loaded sub-clients can be viewed throughsubclients.
- tree(serialized=False, indent=None)¶
Gets meta-information about the client and all
SubClientsregistered to the client. This includes information about endpoints attached to individual request methods using the@apiclientand@endpoint()decorators.- Parameters
serialized¶ (
bool) – Whether or not to serialized the resulting tree into a string. Defaults toFalse.indent¶ (
int) – The indentation to use for pretty printing serialized data. Only applies ifserializedisTrue. This parameter is directly passed to thejson.dumps()indentparameter. Defaults toNone, returning a single-line string.
- Returns
Union[
dict,str] – The client tree dictionary, or the serialized client tree dictionary.
- unload_extension(name, *, package=None)¶
Unloads an extension.
Any sub-clients added in an extension will be removed from that extension when it is unloaded.
Optionally, an extension module can have a
teardownfunction which will be called as a module is unloaded, which receives a single argument of aclient, either aSyncClientor anAsyncClient, similar tosetupfromload_extension().Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be found. This usually means that the extension file could not be found.
ExtensionNotLoaded – The extension is not loaded to the client, and therefore cannot be unloaded.
Async Client¶
- defadd_subclient
- asyncclose
- asyncdelete
- asyncget
- defload_extension
- asyncpatch
- asyncpost
- asyncput
- defreload_extension
- defremove_subclient
- asyncrequest
- asyncstream_file
- deftree
- defunload_extension
- asyncupload_file
- class arya_api_framework.AsyncClient(*args, **kwargs)¶
The core API framework client for asynchronous API integration.
Warning
All of the configuration for this class and its subclasses are done through subclass parameters. This means that the
__init__method can be used for any extra setup for your specific use-case. The parameters shown below are for subclass parameters only.Example:¶class MyClient( AsyncClient, uri="https://exampleurl.com", parameters={"arg1": "abc"} ): ...
- Keyword Arguments
This is a keyword only argument.
The base URI that will prepend all requests made using the client.
Warning
This should always be passed. If it is not given, an
errors.ClientErrorexception will be raised.headers¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
The default headers to pass with every request. Can be overridden by individual requests. Defaults to
None.cookies¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
The default cookies to pass with every request. Can be overridden by individual requests. Defaults to
None.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
The default parameters to pass with every request. Can be overridden by individual requests. Defaults to
None.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
interror codes toBaseModeltypes to use when that error code is received. Defaults toNoneand raises default exceptions for error codes.bearer_token¶ (Optional[Union[
str, pydantic.SecretStr]]) –This is a keyword only argument.
A
bearer_tokenthat will be sent with requests in theAuthorizationheader. Defaults toNonerate_limit¶ (Optional[Union[
int,float]]) –This is a keyword only argument.
The number of requests to allow over
rate_limit_intervalseconds. Defaults toNonerate_limit_interval¶ (Optional[Union[
int,float]]) –This is a keyword only argument.
The period of time, in seconds, over which to apply the rate limit per every
rate_limitrequests. Defaults to1second.
- closed¶
This is a read-only attribute.
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
- extensions¶
This is a read-only attribute.
A mapping of extensions by name to extension.
- Type
Mapping[
str,types.ModuleType]
- subclients¶
This is a read-only attribute.
A mapping of sub-clients by name to sub-client.
- uri¶
This is a read-only attribute.
The base URI that will prepend all requests made using the client.
- Type
Optional[
yarl.URL]
- uri_root¶
This is a read-only attribute.
The root origin of the
urigiven to the client.- Type
Optional[
yarl.URL]
- uri_path¶
This is a read-only attribute.
The path from the
uri_rootto theuripath.- Type
Optional[
yarl.URL]
- 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¶
This is a read-only attribute.
The number of requests per
rate_limit_intervalthe client is allowed to send.
- rate_limit_interval¶
This is a read-only attribute.
The interval, in seconds, over which to apply a rate limit for
rate_limitrequests per interval.
- is_rate_limited¶
This is a read-only attribute.
Whether or not the client has a rate limit set.
- Type
- await request(method, path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await upload_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await stream_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await get(path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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
This is a positional only argument.
The path, relative to the client’s
uri, to send the request to. If this is set toNone, the request will be sent to the client’suri.- Keyword Arguments
headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the GET request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the GET request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the GET request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await post(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await patch(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await put(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await delete(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
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
This is a positional only argument.
The path, relative to the client’s
uri, 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]]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[Union[
dict,BaseModel]]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
aiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawaiohttp.ClientResponseobject.
- await close()¶
Closes the current
aiohttp.ClientSession, if not already closed.Unloads any loaded extensions and
SubClients.
- add_subclient(subclient)¶
Loads a
SubClientas a child route of the primary client. Loaded sub-clients can be viewed throughsubclients.Note
- Any
SubClientmust meet a few requirements in order to be added to a parent: The SubClient cannot already be loaded to a different parent.
The SubClient cannot already be loaded to the current parent.
The SubClient cannot be loaded to itself as a parent.
- Parameters
subclient¶ (
SubClient) – The sub-client to add as a child of the parent client tree.- Raises
ValueError – Raised if the
subclientis not aSubClient.errors.SubClientError – Raised if the
subclientis added as a child of itself.errors.SubClientAlreadyLoaded – Raised if the
subclientis already loaded to the current client.errors.SubClientParentSet – Raised if the
subclientalready has aparentset.
- Any
- load_extension(name, *, package=None)¶
Loads an extension.
An extension is a separate python module (file) that contains a sub-group of requests.
Any extension module should include a function
setupdefined as the entry point for loading the extension, which takes a single argument of aclient, either aSyncClientor anAsyncClient.Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be imported. This usually means that the extension file could not be found.
ExtensionAlreadyLoaded – The extension is already loaded to the client.
ExtensionEntryPointError – The extension has no
setupfunction in it.ExtensionFailed – The extension threw an error while executing the
setupfunction.
- reload_extension(name, *, package=None)¶
Unloads, and then loads an extension.
This is the same as an
unload_extension()followed by aload_extension(). If the reload fails, the client will roll-back to the previous working extension version.Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be found. This usually means that the extension file could not be found.
ExtensionNotLoaded – The extension is not loaded to the client, and therefore cannot be unloaded.
- remove_subclient(name)¶
Removes a loaded child
SubClientfrom the primary client. Loaded sub-clients can be viewed throughsubclients.
- tree(serialized=False, indent=None)¶
Gets meta-information about the client and all
SubClientsregistered to the client. This includes information about endpoints attached to individual request methods using the@apiclientand@endpoint()decorators.- Parameters
serialized¶ (
bool) – Whether or not to serialized the resulting tree into a string. Defaults toFalse.indent¶ (
int) – The indentation to use for pretty printing serialized data. Only applies ifserializedisTrue. This parameter is directly passed to thejson.dumps()indentparameter. Defaults toNone, returning a single-line string.
- Returns
Union[
dict,str] – The client tree dictionary, or the serialized client tree dictionary.
- unload_extension(name, *, package=None)¶
Unloads an extension.
Any sub-clients added in an extension will be removed from that extension when it is unloaded.
Optionally, an extension module can have a
teardownfunction which will be called as a module is unloaded, which receives a single argument of aclient, either aSyncClientor anAsyncClient, similar tosetupfromload_extension().Registered extensions can be seen through the
extensionsproperty.- Parameters
name¶ (
str) – The name of the extension to load. This should be in the same format as a normal python import. For example, if you wanted to reference theextensions/submodule.pymodule, you would set thenameparameter toextensions.submodule.- Keyword Arguments
package¶ (Optional[
str]) – The name of the package to load relative imports from. For example, if anameparameter is given as.submoduleto reference theextensions/submodule.pyextension, thepackageparameter would beextensions. Defaults toNone.- Raises
ExtensionNotFound – The extension could not be found. This usually means that the extension file could not be found.
ExtensionNotLoaded – The extension is not loaded to the client, and therefore cannot be unloaded.
Sub Client¶
- defdelete
- defget
- defon_loaded
- defon_unloaded
- defpatch
- defpost
- defput
- defrequest
- defstream_file
- deftree
- defupload_file
- class arya_api_framework.SubClient(*args, **kwargs)¶
The secondary API framework client for itemizing and keeping code clean.
By creating “SubClients” that are subclassed from this class, it is possible to add modules to the overall API structure in a relatively simply way.
Additionally, sub-clients can be nested, allowing for a tree structure that can encompass an entire API interface. For more information on modular development with the library, see the SubClient Guide.
Warning
All of the configuration for this class and its subclasses are done through subclass parameters. This means that the
__init__method is free reign for you to use as you see fit. The parameters shown below are specifically for subclass parameters only.Example:¶class MySubClient(SubClient, name='sub_client_module', relative_path='/example'): pass
- Parameters
name¶ (Optional[
str]) – The name to use for the class internally. This name must be a valid variable name. By using this, the name of each individual sub-client can be managed more directly then through the class name, maintaining proper code guidelines while also being user-friendly. By default, this is set toNone, and thenameparameter will reference the name of the class.relative_path¶ (Optional[
str]) – The relative path from the root URI of the entire API client. For example, if the root URI ishttps://example.com/api, aSubClientwith arelative_pathset to/getwill access thehttps://example.com/api/getroute for all endpoints within that sub-client. Additionally, nested sub-clients will reference their relative paths according to the parent sub-client.
- name¶
This is a read-only attribute.
The name of the sub-client. This is either the
namesubclass parameter, or the__name__attribute of the class itself.- Type
- qualified_name¶
This is a read-only attribute.
The full name of the sub-client, showing its location in the overall API structure using the
.method, likesubclient1.subclient2.this_subclient.- Type
- relative_path¶
This is a read-only attribute.
A yarl URL that contains a relative url path from the
parentclient or sub-client. This is set in therelative_pathsubclass parameter, or set to the parent URI by default.- Type
- full_relative_path¶
This is a read-only attribute.
A yarl URL that contains the relative path from the base client’s
SyncClient.uriattribute.- Type
- qualified_path¶
This is a read-only attribute.
A yarl URL that contains the full URL path to the resource, includig the root URL.
- Type
- parent¶
This is a read-only attribute.
The parent client of the sub-client. This gets set automatically when calling
add_subclient(). This is set toNoneby default, and gets reset toNoneif the module or client is ever unloaded.- Type
Union[
SyncClient,AsyncClient,SubClient]
- subclients¶
This is a read-only attribute.
A mapping of
nametoSubClientfor all registered sub-clients of the current client. Registry is updated automatically when callingadd_subclient()orremove_subclient().
- request(method, path='', /, *, body=None, data=None, files=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.request()orAsyncClient.request(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The request method to use for the request (see HTTP Request Methods).
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.
- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.This is a keyword only argument.
A mapping of
strfile names to file objects to send in the request.headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- upload_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.upload_file()orAsyncClient.upload_file(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path to the file to upload.
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.
- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- stream_file(file, path='', /, *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.stream_file()orAsyncClient.stream_file(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path to the file to upload.
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.
- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- get(path='', *, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.get()orAsyncClient.get(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.- Keyword Arguments
headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- post(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.post()orAsyncClient.post(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- patch(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.patch()orAsyncClient.patch(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- put(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.put()orAsyncClient.put(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- delete(path='', /, *, body=None, data=None, headers=None, cookies=None, parameters=None, response_format=None, timeout=300, error_responses=None, raw=False)¶
This function could be a coroutine.
This method enforces data validation.
This method can enforce rate limits.
This calls either
SyncClient.delete()orAsyncClient.delete(), depending on whether the core client of the application is either of those types. For specifics, view those documentations.- Parameters
This is a positional only argument.
The path, relative to the client’s
relative_path, to send the request to. If this is not provided, the sub-client’sfull_relative_pathis used.- Keyword Arguments
body¶ (Optional[Union[
dict,BaseModel]) –This is a keyword only argument.
Optional data to send as a JSON structure in the body of the request. Defaults to
None.data¶ (Optional[
Any]) –This is a keyword only argument.
Optional data of any type to send in the body of the request, without any pre-processing. Defaults to
None.headers¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific headers to send with the request. Defaults to
Noneand uses the default clientheaders.cookies¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific cookies to send with the request. Defaults to
Noneand uses the default clientcookies.parameters¶ (Optional[
dict,BaseModel]) –This is a keyword only argument.
Request-specific query string parameters to send with the request. Defaults to
Noneand uses the default clientparameters.response_format¶ (Optional[Type[
Response]]) –This is a keyword only argument.
The model to use as the response format. This offers direct data validation and easy object-oriented implementation. Defaults to
None, and the request will return a JSON structure.This is a keyword only argument.
The length of time, in seconds, to wait for a response to the request before raising a timeout error. Defaults to
300seconds, or 5 minutes.error_responses¶ (Optional[
dict]) –This is a keyword only argument.
A mapping of
intstatus 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.This is a keyword only argument.
Whether or not to return the raw
requests.Responseoraiohttp.ClientResponseobject instead of parsing the results as a JSON response, or loading it to aBaseModel.New in version 0.3.5.
- Returns
Optional[Union[
dict,Response,aiohttp.ClientResponse]] – The request response JSON, loaded into theresponse_formatmodel if provided, or as a rawdictotherwise. IfrawisTrue, returns a rawrequests.Responseoraiohttp.ClientResponseobject.
- on_loaded()¶
A hook that is called when the
SubClientis added to a parent. Has no implementation at default, so this is for any extra internal setup that a sub-client might need to do after gaining access to the parent client tree.
- on_unloaded()¶
A hook that is called when the
SubClientis removed from a parent. Has no implementation at default.
- tree(serialized=False, indent=None, _root=True)¶
Gets meta-information about the sub-client and all
SubClientsregistered to the client. This includes information about endpoints attached to individual request methods using the@apiclientand@endpoint()decorators.- Parameters
serialized¶ (
bool) – Whether or not to serialized the resulting tree into a string. Defaults toFalse.indent¶ (
int) – The indentation to use for pretty printing serialized data. Only applies ifserializedisTrue. This parameter is directly passed to thejson.dumps()indentparameter. Defaults toNone, returning a single-line string.
- Returns
Union[
dict,str] – The client tree dictionary, or the serialized client tree dictionary.
Data Models¶
Here are a collection of basic data structures to be used when making requests with the API clients.
Basic Models¶
The basic pydantic model that incorporates data validation. This usage of this model for requests is one of the reasons why this library is useful.
- clsBaseModel.construct (inherited)
- clsBaseModel.from_orm (inherited)
- clsBaseModel.parse_file (inherited)
- clsBaseModel.parse_obj (inherited)
- clsBaseModel.parse_raw (inherited)
- clsBaseModel.schema (inherited)
- clsBaseModel.schema_json (inherited)
- defcopy (inherited)
- defdict (inherited)
- defjson (inherited)
- class arya_api_framework.BaseModel¶
- This class inherits from pydantic.BaseModel.
These models include data validation on the attributes given to them, and allow for very direct control over response formats. Additionally, they allow to easily creating database-like structures, and outputting the data in a variety of formats.
- __config__¶
The configuration class for the model.
Tip
See this example for information on how to create the model config.
- Type
- dict(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False)¶
- This method inherits from pydantic.BaseModel.dict.
Generate a
dictrepresentation of the model, optionally specifying which fields to include or exclude. Look to the pydantic documentation for further details.- Keyword Arguments
include¶ (Optional[Union[Set[
str]],dict]]) – Fields to include in the returned dictionary. See this example.exclude¶ (Optional[Union[Set[
str]],dict]]) – Fields to exclude from the returned dictionary. See this example.by_alias¶ (Optional[
bool]) – Whether field aliases should be used as keys in the resulting dictionary. Defaults toFalseexclude_unset¶ (Optional[
bool]) –Whether or not fields that were not specifically set upon creation of the model should be included in the dictionary. Defaults to
False.Warning
This was previously referred to as
skip_defaults. This parameter is still accepted, but has been deprecated and is not recommended.exclude_defaults¶ (Optional[
bool]) – Whether or not to include fields that are set to their default values. Even if a field is given a value when the model is instanced, if that value is equivalent to the default, it will not be included. Defaults toFalse.exclude_none¶ (Optional[
bool]) – Whether of not to include fields which are equal toNone. Defaults toFalse.
- Returns
- json(*, include=None, exclude=None, by_alias=False, skip_defaults=None, exclude_unset=False, exclude_defaults=False, exclude_none=False, encoder=None, models_as_dict=True, **dumps_kwargs)¶
- This method inherits from pydantic.BaseModel.json.
Serializes the model to a JSON string. Typically will call
dict()and then serialize the result. As such, the parameters are very similar, except for a few extra options.Tip
You can set the
models_as_dictoption toFalseto implement custom serialization for a model. See this example for more info.Tip
It is possible to implement custom encoders for specific types within an individual model. This is helpful to avoid having to create an entire encoder for the
encoderargument. See this example for more info.- Keyword Arguments
include¶ (Optional[Union[Set[
str]],dict]]) – Fields to include in the returned dictionary. See this example.exclude¶ (Optional[Union[Set[
str]],dict]]) – Fields to exclude from the returned dictionary. See this example.by_alias¶ (Optional[
bool]) – Whether field aliases should be used as keys in the resulting dictionary. Defaults toFalseexclude_unset¶ (Optional[
bool]) –Whether or not fields that were not specifically set upon creation of the model should be included in the dictionary. Defaults to
False.Warning
This was previously referred to as
skip_defaults. This parameter is still accepted, but has been deprecated and is not recommended.exclude_defaults¶ (Optional[
bool]) – Whether or not to include fields that are set to their default values. Even if a field is given a value when the model is instanced, if that value is equivalent to the default, it will not be included. Defaults toFalse.exclude_none¶ (Optional[
bool]) – Whether of not to include fields which are equal toNone. Defaults toFalse.encoder¶ (Optional[Callable[Any, Any]]) – A custom encoder function that is given to
json.dumps(). By default, a custom pydantic encoder is used, which can serialize many common types that the defaultjsoncannot normally handle, like adatetime.models_as_dict¶ (Optional[
bool]) – Whether or not to serialize other models that are contained within the fields of the target model to json. This defaults toTrue.**dumps_kwargs¶ – Any extra keyword arguments are passed to
json.dumps()directly, such as theindentargument, which will pretty-print the resultingstr, using indentations ofindentspaces.
- Returns
str– A JSON serialized string.
- copy(*, include=None, exclude=None, update=None, deep=False)¶
- This method inherits from pydantic.BaseModel.copy.
Returns a duplicate of the model. This is very handy for use with immutable models.
- Keyword Arguments
include¶ (Optional[Union[Set[
str]],dict]]) – Fields to include in the returned dictionary. See this example.exclude¶ (Optional[Union[Set[
str]],dict]]) – Fields to exclude from the returned dictionary. See this example.update¶ (Optional[
dict]) – A dictionary of values to update when creating the copied model. Very similar in concept todict.update().deep¶ (Optional[
bool]) – Whether to make a deep copy of the object, or a shallow copy. Defaults toFalse.
- Returns
BaseModel– A copied instance of the model.
- classmethod parse_obj(obj)¶
- This classmethod inherits from pydantic.BaseModel.parse_obj.
Instantiates a model from a given
dict.
- classmethod parse_raw(b, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- This classmethod inherits from pydantic.BaseModel.parse_raw.
Takes a
strorbytesand parses it to a JSON structure, then passes that toparse_obj()to load it into the model. This can also handle loadingpickledata directly via thecontent_typeargument.- Parameters
b¶ (Union[
str,bytes]) – The content to load into the model. This should be either a JSON serializedstr, or apickle.dumps()object.- Keyword Arguments
content_type¶ (Optional[
str]) – The content type of thebdata passed. Should either beapplication/jsonorapplication/pickle, if provided. Defaults to`None.encoding¶ (Optional[
str]) – If abytesobject is passed with a content type ofjson, it must be decoded using the same method it was encoded in. This defaults toutf8.proto¶ (Optional[
pydantic.Protocol]) – Another method of more directly specifying thecontent_typeof the data passed. This should bepydantic.Protocol.jsonorpydantic.Protocol.pickleif given. Otherwise, if neither thecontent_typeor this argument are passed, this is defaulted toProtocol.json.allow_pickle¶ (Optional[
bool]) – Whether or not to allow reading of pickled input. If thecontent_typeorprotocolare set to apickledata type, this must be set toTrue. Defaults toFalse
- Raises
pydantic.ValidationError – Raised if the
bcannot be used to instantiate the model, or if thecontent_typeis set toaplication/picklewithout settingallow_pickletoTrue.pickle.UnpicklingError – Raised when Pickle fails to load an object.
- Returns
- classmethod parse_file(path, *, content_type=None, encoding='utf8', proto=None, allow_pickle=False)¶
- This classmethod inherits from pydantic.BaseModel.parse_file.
Takes a file path and parses it to a JSON structure, then passes that to
parse_raw()to load it into the model. This can also handle loadingpickledata directly via thecontent_typeargument.- Parameters
path¶ (Union[
str,pathlib.Path]) – A path to a file to load into the model.- Keyword Arguments
content_type¶ (Optional[
str]) – The content type of the date in the file at the givenpath. Should either beapplication/jsonorapplication/pickle, if provided. Defaults toNone.encoding¶ (Optional[
str]) – If abytesobject is passed with a content type ofjson, it must be decoded using the same method it was encoded in. This defaults toutf8.proto¶ (Optional[
pydantic.Protocol]) – Another method of more directly specifying thecontent_typeof the data passed. This should bepydantic.Protocol.jsonorpydantic.Protocol.pickleif given. Otherwise, if neither thecontent_typeor this argument are passed, this is defaulted toProtocol.json.allow_pickle¶ (Optional[
bool]) – Whether or not to allow reading of pickled input. If thecontent_typeorprotocolare set to apickledata type, this must be set toTrue. Defaults toFalse
- Raises
pydantic.ValidationError – Raised if the
pathcannot be used to instantiate the model.FileNotFoundError – Raised when the
pathprovided could not be used to open a file.TypeError – Raised when trying to decode with pickle without setting
allow_pickletoTrue.
- Returns
- classmethod from_orm(obj)¶
- This classmethod inherits from pydantic.BaseModel.from_orm.
Instantiates the model from a given ORM class using ORM mode.
Warning
In order to use
from_orm(), the config propertyorm_modemust be set toTrue.- Parameters
obj¶ (Any) – The ORM object to construct the model from.
- Raises
pydantic.ValidationError – Raised if the model could not be instantiated from the given ORM
obj.pydantic.ConfigError – Raised when the model does not have the
orm_modeset toTruein the config.
- Returns
BaseModel– An instantiated model from the given ORM instance.
- classmethod schema(by_alias=True, ref_template='#/definitions/{model}')¶
- This classmethod inherits from pydantic.BaseModel.schema.
Converts the model into a dictionary schema.
- Parameters
by_alias¶ (Optional[
bool]) – Whether or not to use aliased names for fields when outputting the data schema. See this example for creating field aliases. Defaults toTrue.ref_template¶ (Optional[
str]) –The string template to use when outputting sub-models to the schema. The template should include
{model}somewhere in it as a placeholder for the name of the sub-model. Defaults to#/definitions/{model}.Note
When outputting the schema structure, all sub-models of the model will be output under the top-level JSON key
definitions, and then referenced using theref_templatetemplate provided inside the parent model.
- Returns
dict– The model represented as a python dictionary.
- classmethod schema_json(*, by_alias=True, ref_template='#/definitions/{model}', **dumps_kwargs)¶
- This classmethod inherits from pydantic.BaseMode.schema_json.
Converts the model to a JSON serialized string.
Tip
Any extra keyword arguments passed to this method will be given to the
json.dumps()function as keyword arguments. Using this, for example, means that you could pass theindexargument, and cause the output string to be pretty-printed with indentation.- Keyword Arguments
by_alias¶ (Optional[
bool]) – Whether or not to use aliased names for fields when outputting the data schema. See this example for creating field aliases. Defaults toTrue.ref_template¶ (Optional[
str]) –The string template to use when outputting sub-models to the schema. The template should include
{model}somewhere in it as a placeholder for the name of the sub-model. Defaults to#/definitions/{model}.Note
When outputting the schema structure, all sub-models of the model will be output under the top-level JSON key
definitions, and then referenced using theref_templatetemplate provided inside the parent model.
- Returns
- classmethod construct(_fields_set=None, **values)¶
- This classmethod inherits from pydantic.BaseMode.construct.
Creates the model without running any validation. This can come in handy for slightly more performant code when creating models with data that has already been validated. Using
construct()is usually around30xfaster than creating a model with complete validation. See an example here.Warning
This method is capable of creating invalid data in the model, so it should only be used if the data has already been validated, or comes from another trusted source.
- Parameters
_fields_set¶ (Optional[
set]) – Asetofstrfield names to pass to the model’s__fields_set__attribute.**kwargs¶ –
Any other keyword arguments given to the method will be processed as field names.
Tip
In many cases, you will likely have a
dictthat you want to pass, and you can do so by usingBaseModel.construct(**my_dict). To create a model from another model, you can useBaseModel.construct(**model_instance.dict()).
Response Models¶
These models are used to define what a response that you receive is expected to look like.
- clsBaseModel.construct (inherited)
- clsBaseModel.from_orm (inherited)
- clsBaseModel.parse_file (inherited)
- clsBaseModel.parse_obj (inherited)
- clsBaseModel.parse_raw (inherited)
- clsBaseModel.schema (inherited)
- clsBaseModel.schema_json (inherited)
- defcopy (inherited)
- defdict (inherited)
- defjson (inherited)
- class arya_api_framework.Response¶
- This class inherits from BaseModel.
The basic class that all response models for a request should subclass. This class provides a few basic fields that are used in recording request responses.
Example
# Create your response structure: class MyAPIResponse(Response): index: int first_name: str last_name: str # Pass this into your requests: response = my_client.get(..., response_model=MyAPIResponse) # Sync response = await my_client.get(..., response_mode=MyApiResponse) # Async # >>> response.dict() { "request_base_": "url", "request_received_at_": datetime.datetime(...), "id": 123, "first_name": "First", "last_name": "Last" }
Note
The
uriandtimeattributes of this response method will not be included in any output methods for the model. They are purely intended for programmatic usage.- time¶
The time that the response was received at.
- Type
- clsBaseModel.construct (inherited)
- clsBaseModel.from_orm (inherited)
- clsBaseModel.parse_file (inherited)
- clsBaseModel.parse_obj (inherited)
- clsBaseModel.parse_raw (inherited)
- clsBaseModel.schema (inherited)
- clsBaseModel.schema_json (inherited)
- defcopy (inherited)
- defdict (inherited)
- defend
- defis_paginating
- defjson (inherited)
- defnext
- defprevious
- defstart
- class arya_api_framework.PaginatedResponse¶
- This class inherits from Response.
This offers a few extra options for a request response to enable easier response pagination.
Often times when receiving a response for an API query which might include a significant amount of data (such as a list of products from an online shop), the API will limit the response to a set number of items. Taking this into account, this class can take advantage of the data structure to automatically give the necessary information about navigating this pagination.
Warning
This is an
abstractclass, which means that any subclasses must implement all methods from this class.- abstractmethod is_paginating()¶
A method that is intended to determine whether any given response is paginated or not.
If your response is always paginating, this should simply return
True. Likewise, if the response is never paginating, returnFalse. Otherwise, some logic should be implemented to determine whether the response is paginated.- Returns
bool– Whether the response is paginated.
- abstractmethod next()¶
This will return an identifier for how to navigate to the next page in the paginated response.
For example, if a response has a
page_numberfield, you would returnself.page_number + 1. However, this can also be any return type, to allow for URLs to be returned directly, or some other implementation.Tip
This method, as well as
previous,end, andstartfor navigating pagination, should callis_paginating()and returnNoneif the response is not paginating.if not self.is_paginating(): return
- Returns
Optional[Any] – Some identifier for navigating to the next page in the pagination.
- abstractmethod previous()¶
This will return an identifier for how to navigate to the previous page in the paginated response.
For example, if a response has a
page_numberfield, you would returnself.page_number - 1. However, this can also be any return type, to allow for URLs to be returned directly, or some other implementation.- Returns
Optional[Any] – Some identifier for navigating to the previous page in the pagination.
- abstractmethod end()¶
This will return an identifier for how to navigate to the last page in the paginated response.
For example, if a response has a
page_countfield, you would want to returnself.page_count. However, this can also be any return type, to allow for URLs to be returned directly, or some other implementation.- Returns
Optional[Any] – Some identifier for navigating to the last page in the pagination.
- abstractmethod start()¶
This will return an identifier for how to navigate to the first page in the paginated response.
For example, if you were tracking pagination by numbering each page, you would simply return
1for the first page.- Returns
Optional[Any] – Some identifier for navigating to the first page in the pagination.
Enums¶
- enum arya_api_framework.constants.HTTPMethod(value)¶
A collection of all possible HTTP request methods.
Valid values are as follows:
- ANY = <HTTPMethod.ANY: 'ANY'>¶
Indicates that an endpoint accepts any request method.
Utility Functions¶
- arya_api_framework.utils.flatten_obj(obj)¶
Flattens a given object into a
dict.This is mainly used for arguments where a
dictor aBaseModelcan be accepted as parameters.
- arya_api_framework.utils.merge_dicts(base_dict, update_dict)¶
Merges the base dict with the update dict, overriding any of the base dict’s values with the updated values from the update dict.
- arya_api_framework.utils.validate_type(obj, target, err=True)¶
Validates that a given parameter is of a type, or is one of a collection of types.
- Parameters
- Returns
bool– A boolean representing whether the type was validated.
- @arya_api_framework.utils.apiclient¶
Decorates any
SyncClient,AsyncClient, orSubClientto automatically read any methods decorated with an@endpointdecorator. Thetreemethod is then populated using this metadata.Example:¶@apiclient class MyClient(SyncClient, uri='https://example.com/api'): @endpoint( path='/', name='Get Example', href='https://example.com/api/docs/', method='GET' ) def example(self): return self.get()
>>> client = MyClient() >>> print(client.tree(serialize=True, indent=2)) { "root": { "__info__": { "uri": "https://example.com/api", "uri_root": "https://example.com" }, "__endpoints__": { "example": { "path": "/", "name": "Get Example", "href": "https://example.com/api/docs/", "methods": [ "GET" ] } }, "__subclients__": {} } }
- @arya_api_framework.utils.endpoint(path, name=None, description=None, href=None, method=HTTPMethod.ANY, methods=None)¶
Attaches metadata to a request method in a
SyncClient,AsyncClient, orSubClient. In order for this data to be applied to the client properly, the client must be decorated with a@apiclientdecorator.Note
To access the metadata attached to a method with
@endpoint, use thetreemethod of anySyncClient,AsyncClient, orSubClient.- Parameters
path (
str) – The relative path of the endpoint from the root URI of the client.name (Optional[
str]) – The name of the endpoint. If this is not provided, the function name is used.href (Optional[
str]) – A link to documentation for this endpoint. This will usually link to an API’s documentation.method (Optional[Union[
constants.HTTPMethod,str]]) – The request method that the endpoint makes use of.methods (Optional[List[Union[
constants.HTTPMethod,str]]]) –The request methods that an endpoint can make use of.