Using Sessions in Python Requests
Author: Newtum
This guide explains how to use Session objects in the Python Requests library to persist parameters and cookies across multiple requests to the same host.
What is a Session Object?
A Session object allows you to persist certain parameters across requests. It also persists cookies, which is useful for maintaining a logged-in state. When you make multiple requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase.
Example of a Session
Here's how to create a session and make requests with it. Notice that cookies set by the first request are automatically sent in the second request.
Persisting Parameters
You can also set default headers or query parameters for all requests made with a session.