Q2 Requests
This module provides an easy interface for asynchronous web requests
The Requests library (https://requests.readthedocs.io/en/master/) is a beautiful and well known interface for making web requests in python. With that said, it doesn’t play nice with the asynchronous features of Antilles. This is a thin wrapper module to achieve the best of both worlds.
To utilize the Requests functionality with an existing requests.Session
object (https://requests.readthedocs.io/en/master/user/advanced/?highlight=session#session-objects)
simply pass the session keyword argument to each HTTP method in this module.
If the “session” argument is omitted from the function call, then it will
use the default, non-session-aware requests method.
- class q2_sdk.core.q2_requests.CallIdLogAdapter(logger, extra=None, merge_extra=False)[source]
Initialize the adapter with a logger and a dict-like object which provides contextual information. This constructor signature allows easy stacking of LoggerAdapters, if so desired.
You can effectively pass keyword arguments as shown in the following example:
adapter = LoggerAdapter(someLogger, dict(p1=v1, p2=”v2”))
By default, LoggerAdapter objects will drop the “extra” argument passed on the individual log calls to use its own instead.
Initializing it with merge_extra=True will instead merge both maps when logging, the individual call extra taking precedence over the LoggerAdapter instance extra
Changed in version 3.13: The merge_extra argument was added.
- process(msg, kwargs)[source]
Process the logging message and keyword arguments passed in to a logging call to insert contextual information. You can either manipulate the message itself, the keyword args or both. Return the message and kwargs modified (or not) to suit your needs.
Normally, you’ll only need to override this one method in a LoggerAdapter subclass for your specific needs.
- async q2_sdk.core.q2_requests.get(logger, url, params=None, session=None, minimal_logging=False, **kwargs)[source]
Sends a GET request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.params – (optional) Dictionary or bytes to be sent in the query string for the
Request
.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response
- async q2_sdk.core.q2_requests.options(logger, url, session=None, minimal_logging=False, **kwargs)[source]
Sends an OPTIONS request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- async q2_sdk.core.q2_requests.post(logger, url, data=None, json=None, session=None, minimal_logging=False, **kwargs)[source]
Sends a POST request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.data – (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the
Request
.json – (optional) json data to send in the body of the
Request
.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response
- async q2_sdk.core.q2_requests.head(logger, url, session=None, minimal_logging=False, **kwargs)[source]
Sends a HEAD request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response
- async q2_sdk.core.q2_requests.put(logger, url, data=None, session=None, minimal_logging=False, **kwargs)[source]
Sends a PUT request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.data – (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the
Request
.json – (optional) json data to send in the body of the
Request
.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response
- async q2_sdk.core.q2_requests.patch(logger, url, data=None, session=None, minimal_logging=False, **kwargs)[source]
Sends a PATCH request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.data – (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the
Request
.json – (optional) json data to send in the body of the
Request
.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response
- async q2_sdk.core.q2_requests.delete(logger, url, session=None, minimal_logging=False, **kwargs)[source]
Sends a DELETE request.
- Parameters:
logger – Reference to calling request’s logger (self.logger in your extension)
url – URL for the new
Request
object.session – (optional)
requests.Session
object to base the request off of.minimal_logging (
bool
) – (optional) flag to turn off debug logging of request header/body/etc.**kwargs – Optional arguments that
request
takes.
- Return type:
Response