Home / Class/ Session Class — requests Architecture

Session Class — requests Architecture

Architecture documentation for the Session class in sessions.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29["Session"]
  29cd946c_8c0d_e37c_acb9_dfb2b83bf42b["SessionRedirectMixin"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|extends| 29cd946c_8c0d_e37c_acb9_dfb2b83bf42b
  075eaa90_3b36_3d32_fc50_b57c7c8fe638["Request"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|extends| 075eaa90_3b36_3d32_fc50_b57c7c8fe638
  ea1101aa_233b_1206_7b38_a38f0fe92a52["sessions.py"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|defined in| ea1101aa_233b_1206_7b38_a38f0fe92a52
  9e3b60ed_3668_f4e9_fa2a_9db7ae000c2e["__init__()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 9e3b60ed_3668_f4e9_fa2a_9db7ae000c2e
  e8887eba_1426_ba94_b83b_399c43b091f4["__enter__()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| e8887eba_1426_ba94_b83b_399c43b091f4
  0bcd8663_4576_1572_5342_b1e3ef5845a3["__exit__()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 0bcd8663_4576_1572_5342_b1e3ef5845a3
  a4eb532d_c481_9e3e_ad07_8d203ffafd2d["prepare_request()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| a4eb532d_c481_9e3e_ad07_8d203ffafd2d
  71102afa_b9d8_769c_e8b8_1db9a083fa11["request()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 71102afa_b9d8_769c_e8b8_1db9a083fa11
  e5f3beee_4f0d_bcf5_4af9_52d8658ab65f["get()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| e5f3beee_4f0d_bcf5_4af9_52d8658ab65f
  9871a555_0da1_d5d5_d97d_66898dd8de45["options()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 9871a555_0da1_d5d5_d97d_66898dd8de45
  781cb9a0_9aa4_57cf_36f3_47230c76fd28["head()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 781cb9a0_9aa4_57cf_36f3_47230c76fd28
  84326225_e63b_ea25_d8a2_1582fe90acf9["post()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 84326225_e63b_ea25_d8a2_1582fe90acf9
  52502a1e_98bf_2e99_032b_c4c4a3af6e1d["put()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 52502a1e_98bf_2e99_032b_c4c4a3af6e1d
  939bd7e3_2435_7109_47cf_270053aae7ef["patch()"]
  b4dad953_9227_8b3f_4041_3f8f1f9f0b29 -->|method| 939bd7e3_2435_7109_47cf_270053aae7ef

Relationship Graph

Source Code

src/requests/sessions.py lines 357–817

class Session(SessionRedirectMixin):
    """A Requests session.

    Provides cookie persistence, connection-pooling, and configuration.

    Basic Usage::

      >>> import requests
      >>> s = requests.Session()
      >>> s.get('https://httpbin.org/get')
      <Response [200]>

    Or as a context manager::

      >>> with requests.Session() as s:
      ...     s.get('https://httpbin.org/get')
      <Response [200]>
    """

    __attrs__ = [
        "headers",
        "cookies",
        "auth",
        "proxies",
        "hooks",
        "params",
        "verify",
        "cert",
        "adapters",
        "stream",
        "trust_env",
        "max_redirects",
    ]

    def __init__(self):
        #: A case-insensitive dictionary of headers to be sent on each
        #: :class:`Request <Request>` sent from this
        #: :class:`Session <Session>`.
        self.headers = default_headers()

        #: Default Authentication tuple or object to attach to
        #: :class:`Request <Request>`.
        self.auth = None

        #: Dictionary mapping protocol or protocol and host to the URL of the proxy
        #: (e.g. {'http': 'foo.bar:3128', 'http://host.name': 'foo.bar:4012'}) to
        #: be used on each :class:`Request <Request>`.
        self.proxies = {}

        #: Event-handling hooks.
        self.hooks = default_hooks()

        #: Dictionary of querystring data to attach to each
        #: :class:`Request <Request>`. The dictionary values may be lists for
        #: representing multivalued query parameters.
        self.params = {}

        #: Stream response content default.
        self.stream = False

        #: SSL Verification default.
        #: Defaults to `True`, requiring requests to verify the TLS certificate at the
        #: remote end.
        #: If verify is set to `False`, requests will accept any TLS certificate
        #: presented by the server, and will ignore hostname mismatches and/or
        #: expired certificates, which will make your application vulnerable to
        #: man-in-the-middle (MitM) attacks.
        #: Only set this to `False` for testing.
        self.verify = True

        #: SSL client certificate default, if String, path to ssl client
        #: cert file (.pem). If Tuple, ('cert', 'key') pair.
        self.cert = None

        #: Maximum number of redirects allowed. If the request exceeds this
        #: limit, a :class:`TooManyRedirects` exception is raised.
        #: This defaults to requests.models.DEFAULT_REDIRECT_LIMIT, which is
        #: 30.
        self.max_redirects = DEFAULT_REDIRECT_LIMIT

        #: Trust environment settings for proxy configuration, default

Domain

Frequently Asked Questions

What is the Session class?
Session is a class in the requests codebase, defined in src/requests/sessions.py.
Where is Session defined?
Session is defined in src/requests/sessions.py at line 357.
What does Session extend?
Session extends SessionRedirectMixin, Request.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free