@@ -113,17 +113,32 @@ class Airtable(object):
113
113
API_LIMIT = 1.0 / 5 # 5 per second
114
114
API_URL = posixpath .join (API_BASE_URL , VERSION )
115
115
116
- def __init__ (self , base_key , table_name , api_key = None ):
116
+ def __init__ (self , base_key , table_name , api_key = None , timeout = None ):
117
117
"""
118
- If api_key is not provided, :any:`AirtableAuth` will attempt
119
- to use ``os.environ['AIRTABLE_API_KEY']``
118
+ Instantiates a new Airtable instance
119
+
120
+ >>> table = Airtable('basekey', "tablename")
121
+
122
+ Args:
123
+ base_key(``str``): Airtable base identifier
124
+ table_name(``str``): Airtable table name. Value will be url encoded, so
125
+ use value as shown in Airtable.
126
+
127
+ Keyword Args:
128
+ api_key (``str``, optional): Optional API key. If not provided,
129
+ it will attempt to use ``os.environ['AIRTABLE_API_KEY']``
130
+ timeout (``int``, ``Tuple[int, int]``, optional): Optional timeout
131
+ parameters to be used in request. `See requests timeout docs.
132
+ <https://requests.readthedocs.io/en/master/user/advanced/#timeouts>`_
133
+
120
134
"""
121
135
session = requests .Session ()
122
136
session .auth = AirtableAuth (api_key = api_key )
123
137
self .session = session
124
138
self .table_name = table_name
125
139
url_safe_table_name = quote (table_name , safe = "" )
126
140
self .url_table = posixpath .join (self .API_URL , base_key , url_safe_table_name )
141
+ self .timeout = timeout
127
142
128
143
def _process_params (self , params ):
129
144
"""
@@ -166,7 +181,9 @@ def record_url(self, record_id):
166
181
return posixpath .join (self .url_table , record_id )
167
182
168
183
def _request (self , method , url , params = None , json_data = None ):
169
- response = self .session .request (method , url , params = params , json = json_data )
184
+ response = self .session .request (
185
+ method , url , params = params , json = json_data , timeout = self .timeout
186
+ )
170
187
return self ._process_response (response )
171
188
172
189
def _get (self , url , ** params ):
@@ -212,7 +229,8 @@ def get_iter(self, **options):
212
229
... print(record)
213
230
[{'fields': ... }, ...]
214
231
215
- Keyword Args:
232
+
233
+ Keyword Args:
216
234
max_records (``int``, optional): The maximum total number of
217
235
records that will be returned. See :any:`MaxRecordsParam`
218
236
view (``str``, optional): The name or ID of a view.
@@ -250,7 +268,8 @@ def get_all(self, **options):
250
268
>>> airtable.get_all(maxRecords=50)
251
269
[{'fields': ... }, ...]
252
270
253
- Keyword Args:
271
+
272
+ Keyword Args:
254
273
max_records (``int``, optional): The maximum total number of
255
274
records that will be returned. See :any:`MaxRecordsParam`
256
275
view (``str``, optional): The name or ID of a view.
0 commit comments