Advanced Usage

Prepared Requests

API operations on OpenApiOperations objects return standard requests.PreparedRequest object, patched to include an execute() method (an instance of RequestExecutor).

This allows the client opportunity to make last minute modifications to a request before it is sent, e.g.:

>>> req = my_client.someAction()
>>> # Make some adjustment to the body:
>>> req.body += r'This has to get appended'

>>> # Fire it off and get a standard requests.Response:
>>> resp = req.execute()

Client Configuration

Custom Sessions

Using a specific session

A particular requests.Session (or compatible) session instance can be passed in at the time of client instantiation, using the session parameter:

>>> my_session = requests.Session()
>>> my_client = MyClientClass(root_url='http://something.com',
...   session=my_session)

Using a custom class

To use a specific class of session object for a client:

>>> my_client = MyClientClass(root_url='http://something.com',
...   config=ClientConfig(session_cls=SpecialSessionClass))

Custom Requests

To use a specific class of request object for a client:

>>> my_client = MyClientClass(root_url='http://something.com',
...   config=ClientConfig(request_cls=SpecialRequestClass))