1# Thread Safety 2 3This page contains important information about the thread safety of this library. 4 5## The httplib2.Http() objects are not thread-safe 6 7The google-api-python-client library is built on top of the [httplib2](https://github.com/httplib2/httplib2) library, which is not thread-safe. Therefore, if you are running as a multi-threaded application, each thread that you are making requests from must have its own instance of `httplib2.Http()`. 8 9The easiest way to provide threads with their own `httplib2.Http()` instances is to either override the construction of it within the service object or to pass an instance via the http argument to method calls. 10 11```python 12import google.auth 13import googleapiclient 14import google_auth_httplib2 15import httplib2 16from googleapiclient import discovery 17 18# Create a new Http() object for every request 19def build_request(http, *args, **kwargs): 20 new_http = google_auth_httplib2.AuthorizedHttp(credentials, http=httplib2.Http()) 21 return googleapiclient.http.HttpRequest(new_http, *args, **kwargs) 22authorized_http = google_auth_httplib2.AuthorizedHttp(credentials, http=httplib2.Http()) 23service = discovery.build('api_name', 'api_version', requestBuilder=build_request, http=authorized_http) 24 25# Pass in a new Http() manually for every request 26service = discovery.build('api_name', 'api_version') 27http = google_auth_httplib2.AuthorizedHttp(credentials, http=httplib2.Http()) 28service.stamps().list().execute(http=http) 29``` 30