Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active September 15, 2021 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rpivo/8475e160393eb42fa85fb9b43e98893b to your computer and use it in GitHub Desktop.
Save rpivo/8475e160393eb42fa85fb9b43e98893b to your computer and use it in GitHub Desktop.
Working With Session Objects in the Python Requests Library

Working With Session Objects in the Python Requests Library

Taken from the Python Requests docs:

The Session object allows you to persist certain parameters across requests.

s = requests.Session()

This can be useful for working with cookies (maybe tokens, too).

More from the docs:

So if you're making several requests to the same host, the underlying TCP connection will be reused, which can result in a signficant performance increase...

Taken from the Wikipedia page on HTTP persistent connection:

HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using a single TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair. The newer HTTP/2 protocol uses the same idea and takes it further to allow multiple concurrent requests/responses to be multiplexed over a single connection.

Related Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment