title: Global requests.Session object drawbacks
body: <p>I recently found global <code>request.Session()</code> declaration. E.g:</p>
  
  <pre class="lang-py prettyprint-override"><code># one of many files
  import requests
  
  g_session = requests.Session()
  
  def some_foo():
      return g_session.post('https://example.com', data={'key': 'value'}
  
  # rest of the code
  </code></pre>
  
  <p>From <a href="https://2.python-requests.org/en/master/user/advanced/#session-objects" rel="nofollow noreferrer">docs</a>:</p>
  
  <blockquote>
    <p>The Session object allows you to persist certain parameters across requests. It also persists cookies across all requests made from the Session instance, and will use urllib3’s connection pooling. So if you’re making several requests to the same host, the underlying TCP connection will be reused, which can result in a significant performance increase (see HTTP persistent connection).</p>
  </blockquote>
  
  <p>So as i understand:</p>
  
  <p><strong>the benefits</strong> are no need to open new connection, and it can be reused</p>
  
  <p><strong>the downsides</strong> are supporting the same connection and keeping memory occupied</p>
  
  <hr>
  
  <p><strong>Is there anything else?</strong></p>
  
  <p>I've never seen such global declaration. Most of the times <em>sessions</em> are used in context manager way, or reuse object in same function/block code, but not globally.</p>
  
  <p><sub>Possible relevant info: it's part of django application.</sub></p>