<p dir="auto">So we can do something like this:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="COUCHDB_URL = 'https://mybigusername:myenourmouspassword@mycouchdb.provider.com/databasename/'

s = requests.Session(url_prefix=COUCHDB_URL)
r = s.get('/_all_docs', params=dict(include_docs=True))
r = s.get('/some_document_id')"><pre class="notranslate"><span class="pl-v">COUCHDB_URL</span> <span class="pl-c1">=</span> <span class="pl-s">'https://mybigusername:myenourmouspassword@mycouchdb.provider.com/databasename/'</span>

<span class="pl-s1">s</span> <span class="pl-c1">=</span> <span class="pl-s1">requests</span>.<span class="pl-v">Session</span>(<span class="pl-s1">url_prefix</span><span class="pl-c1">=</span><span class="pl-v">COUCHDB_URL</span>)
<span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-en">get</span>(<span class="pl-s">'/_all_docs'</span>, <span class="pl-s1">params</span><span class="pl-c1">=</span><span class="pl-en">dict</span>(<span class="pl-s1">include_docs</span><span class="pl-c1">=</span><span class="pl-c1">True</span>))
<span class="pl-s1">r</span> <span class="pl-c1">=</span> <span class="pl-s1">s</span>.<span class="pl-en">get</span>(<span class="pl-s">'/some_document_id'</span>)</pre></div>
<p dir="auto">The example uses the CouchDB API and it would almost entirely prevent the need for API wrappers like <a href="https://github.com/adamlofts/couchdb-requests">this</a> (see it storing the url prefix <a href="https://github.com/adamlofts/couchdb-requests/blob/93e83d5e8cf7b0894de33747572789777dee845e/couchdbreq/resource.py#L80">right here</a>). But extensive usage of any REST API would benefit from this.</p>
<p dir="auto">Is it possible to add an optional base url attribute to the Session object ?</p>
<p dir="auto">For example;</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" auth = ('user', 'pass')
 with requests.session(url='http://api.twitter.com', auth=auth) as s:
     resp = s.get('/1/statuses/home_timeline.json')"><pre class="notranslate"><code class="notranslate"> auth = ('user', 'pass')
 with requests.session(url='http://api.twitter.com', auth=auth) as s:
     resp = s.get('/1/statuses/home_timeline.json')
</code></pre></div>