Skip to content

Commit ead5e76

Browse files
committed
chore(api): Add max_workers param
1 parent 7da4285 commit ead5e76

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

censys/search/v2/api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,21 @@ def __iter__(self) -> Iterator[List[dict]]:
176176
"""
177177
return self
178178

179-
def view_all(self) -> Dict[str, dict]:
179+
def view_all(self, max_workers: int = 20) -> Dict[str, dict]:
180180
"""View each document returned from query.
181181
182182
Please note that each result returned by the query will be looked up using the view method.
183183
184184
Returns:
185185
Dict[str, dict]: Dictionary mapping documents to that document's result set.
186+
max_workers (int): The number of workers to use. Defaults to 20.
186187
"""
187188
threads = []
188189
results = {}
189190

190191
document_key = INDEX_TO_KEY.get(self.api.INDEX_NAME, "ip")
191192

192-
with ThreadPoolExecutor(max_workers=20) as executor:
193+
with ThreadPoolExecutor(max_workers) as executor:
193194
for hit in self.__call__():
194195
document_id = hit[document_key]
195196
threads.append(executor.submit(self.api.view, document_id))
@@ -251,6 +252,7 @@ def bulk_view(
251252
self,
252253
document_ids: List[str],
253254
at_time: Optional[Datetime] = None,
255+
max_workers: int = 20,
254256
) -> Dict[str, dict]:
255257
"""Bulk view documents from current index.
256258
@@ -261,6 +263,7 @@ def bulk_view(
261263
document_ids (List[str]): The IDs of the documents you are requesting.
262264
at_time ([str, datetime.date, datetime.datetime]):
263265
Optional; Fetches a document at a given point in time.
266+
max_workers (int): The number of workers to use. Defaults to 20.
264267
265268
Returns:
266269
Dict[str, dict]: Dictionary mapping document IDs to that document's result set.
@@ -271,7 +274,7 @@ def bulk_view(
271274

272275
threads = []
273276
documents = {}
274-
with ThreadPoolExecutor(max_workers=20) as executor:
277+
with ThreadPoolExecutor(max_workers) as executor:
275278
for document_id in document_ids:
276279
threads.append(executor.submit(self.view, document_id, at_time))
277280

0 commit comments

Comments
 (0)