For keeping alive connection you should use persistent connection.
So if you check main document:
http://burnash.github.io/gspread/#gspread.Client
You will see the gspread.login
method is instance of Client
. and Client
can accept http
headers.
http://burnash.github.io/gspread/#gspread.httpsession.HTTPSession
Now add this header in your connection : Connection: Keep-Alive
import gspread
headers = gspread.httpsession.HTTPSession(headers={'Connection':'Keep-Alive'})
con = gspread.Client(auth=('you@gmail.com','password'),http_session=headers)
con.login()
con.open_by_key('....')
Then when you get print of session headers:
print con.session.headers
Out[5]: {'Authorization': u'GoogleLogin auth=xxxxxxx', 'Connection': 'Keep-Alive'}
For persistent connection details have a look into these links:
http://en.wikipedia.org/wiki/HTTP_persistent_connection
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
For codes details of gspread httpsession
have a look into:
https://github.com/burnash/gspread/blob/master/gspread/httpsession.py