-
Notifications
You must be signed in to change notification settings - Fork 69
/
delphi_epidata.py
723 lines (660 loc) · 25.5 KB
/
delphi_epidata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
"""
A module for DELPHI's Epidata API.
https://github.com/cmu-delphi/delphi-epidata
Notes:
- Requires the `requests` module.
- Compatible with Python 2 and 3.
"""
# External modules
import requests
import asyncio
from tenacity import retry, stop_after_attempt
from aiohttp import ClientSession, TCPConnector, BasicAuth
from pkg_resources import get_distribution, DistributionNotFound
# Obtain package version for the user-agent. Uses the installed version by
# preference, even if you've installed it and then use this script independently
# by accident.
try:
_version = get_distribution("delphi-epidata").version
except DistributionNotFound:
_version = "0.script"
_HEADERS = {"user-agent": "delphi_epidata/" + _version + " (Python)"}
class EpidataException(Exception):
pass
class EpidataBadRequestException(EpidataException):
pass
REGIONS_EPIWEEKS_REQUIRED = "`regions` and `epiweeks` are both required"
ISSUES_LAG_EXCLUSIVE = "`issues` and `lag` are mutually exclusive"
LOCATIONS_EPIWEEKS_REQUIRED = "`locations` and `epiweeks` are both required"
# Because the API is stateless, the Epidata class only contains static methods
class Epidata:
"""An interface to DELPHI's Epidata API."""
# API base url
BASE_URL = "https://api.delphi.cmu.edu/epidata"
auth = None
client_version = _version
# Helper function to cast values and/or ranges to strings
@staticmethod
def _listitem(value):
"""Cast values and/or range to a string."""
if isinstance(value, dict) and "from" in value and "to" in value:
return str(value["from"]) + "-" + str(value["to"])
else:
return str(value)
# Helper function to build a list of values and/or ranges
@staticmethod
def _list(values):
"""Turn a list/tuple of values/ranges into a comma-separated string."""
if not isinstance(values, (list, tuple)):
values = [values]
return ",".join([Epidata._listitem(value) for value in values])
@staticmethod
@retry(reraise=True, stop=stop_after_attempt(2))
def _request_with_retry(endpoint, params={}):
"""Make request with a retry if an exception is thrown."""
request_url = f"{Epidata.BASE_URL}/{endpoint}"
req = requests.get(request_url, params, auth=Epidata.auth, headers=_HEADERS)
if req.status_code == 414:
req = requests.post(request_url, params, auth=Epidata.auth, headers=_HEADERS)
# handle 401 and 429
req.raise_for_status()
return req
@staticmethod
def _request(endpoint, params={}):
"""Request and parse epidata.
We default to GET since it has better caching and logging
capabilities, but fall back to POST if the request is too
long and returns a 414.
"""
try:
result = Epidata._request_with_retry(endpoint, params)
except Exception as e:
return {"result": 0, "message": "error: " + str(e)}
if params is not None and "format" in params and params["format"] == "csv":
return result.text
else:
try:
return result.json()
except requests.exceptions.JSONDecodeError:
return {"result": 0, "message": "error decoding json: " + result.text}
# Raise an Exception on error, otherwise return epidata
@staticmethod
def check(resp):
"""Raise an Exception on error, otherwise return epidata."""
if resp["result"] != 1:
msg, code = resp["message"], resp["result"]
raise EpidataException(f"Error fetching epidata: {msg}. (result={int(code)})")
return resp["epidata"]
# Build a `range` object (ex: dates/epiweeks)
@staticmethod
def range(from_, to_):
"""Build a `range` object (ex: dates/epiweeks)."""
if to_ <= from_:
from_, to_ = to_, from_
return {"from": from_, "to": to_}
# Fetch FluView data
@staticmethod
def fluview(regions, epiweeks, issues=None, lag=None, auth=None):
"""Fetch FluView data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(ISSUES_LAG_EXCLUSIVE)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
if auth is not None:
params["auth"] = auth
# Make the API call
return Epidata._request("fluview", params)
# Fetch FluView metadata
@staticmethod
def fluview_meta():
"""Fetch FluView metadata."""
return Epidata._request("fluview_meta")
# Fetch FluView clinical data
@staticmethod
def fluview_clinical(regions, epiweeks, issues=None, lag=None):
"""Fetch FluView clinical data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("fluview_clinical", params)
# Fetch FluSurv data
@staticmethod
def flusurv(locations, epiweeks, issues=None, lag=None):
"""Fetch FluSurv data."""
# Check parameters
if locations is None or epiweeks is None:
raise EpidataBadRequestException(LOCATIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("flusurv", params)
# Fetch PAHO Dengue data
@staticmethod
def paho_dengue(regions, epiweeks, issues=None, lag=None):
"""Fetch PAHO Dengue data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("paho_dengue", params)
# Fetch ECDC ILI data
@staticmethod
def ecdc_ili(regions, epiweeks, issues=None, lag=None):
"""Fetch ECDC ILI data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("ecdc_ili", params)
# Fetch KCDC ILI data
@staticmethod
def kcdc_ili(regions, epiweeks, issues=None, lag=None):
"""Fetch KCDC ILI data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("kcdc_ili", params)
# Fetch Google Flu Trends data
@staticmethod
def gft(locations, epiweeks):
"""Fetch Google Flu Trends data."""
# Check parameters
if locations is None or epiweeks is None:
raise EpidataBadRequestException(LOCATIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("gft", params)
# Fetch Google Health Trends data
@staticmethod
def ght(auth, locations, epiweeks, query):
"""Fetch Google Health Trends data."""
# Check parameters
if auth is None or locations is None or epiweeks is None or query is None:
raise EpidataBadRequestException(
"`auth`, `locations`, `epiweeks`, and `query` are all required"
)
# Set up request
params = {
"auth": auth,
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
"query": query,
}
# Make the API call
return Epidata._request("ght", params)
# Fetch HealthTweets data
@staticmethod
def twitter(auth, locations, dates=None, epiweeks=None):
"""Fetch HealthTweets data."""
# Check parameters
if auth is None or locations is None:
raise EpidataBadRequestException("`auth` and `locations` are both required")
if not ((dates is None) ^ (epiweeks is None)):
raise EpidataBadRequestException("exactly one of `dates` and `epiweeks` is required")
# Set up request
params = {
"auth": auth,
"locations": Epidata._list(locations),
}
if dates is not None:
params["dates"] = Epidata._list(dates)
if epiweeks is not None:
params["epiweeks"] = Epidata._list(epiweeks)
# Make the API call
return Epidata._request("twitter", params)
# Fetch Wikipedia access data
@staticmethod
def wiki(articles, dates=None, epiweeks=None, hours=None, language="en"):
"""Fetch Wikipedia access data."""
# Check parameters
if articles is None:
raise EpidataBadRequestException("`articles` is required")
if not ((dates is None) ^ (epiweeks is None)):
raise EpidataBadRequestException("exactly one of `dates` and `epiweeks` is required")
# Set up request
params = {
"articles": Epidata._list(articles),
"language": language,
}
if dates is not None:
params["dates"] = Epidata._list(dates)
if epiweeks is not None:
params["epiweeks"] = Epidata._list(epiweeks)
if hours is not None:
params["hours"] = Epidata._list(hours)
# Make the API call
return Epidata._request("wiki", params)
# Fetch CDC page hits
@staticmethod
def cdc(auth, epiweeks, locations):
"""Fetch CDC page hits."""
# Check parameters
if auth is None or epiweeks is None or locations is None:
raise EpidataBadRequestException("`auth`, `epiweeks`, and `locations` are all required")
# Set up request
params = {
"auth": auth,
"epiweeks": Epidata._list(epiweeks),
"locations": Epidata._list(locations),
}
# Make the API call
return Epidata._request("cdc", params)
# Fetch Quidel data
@staticmethod
def quidel(auth, epiweeks, locations):
"""Fetch Quidel data."""
# Check parameters
if auth is None or epiweeks is None or locations is None:
raise EpidataBadRequestException("`auth`, `epiweeks`, and `locations` are all required")
# Set up request
params = {
"auth": auth,
"epiweeks": Epidata._list(epiweeks),
"locations": Epidata._list(locations),
}
# Make the API call
return Epidata._request("quidel", params)
# Fetch NoroSTAT data (point data, no min/max)
@staticmethod
def norostat(auth, location, epiweeks):
"""Fetch NoroSTAT data (point data, no min/max)."""
# Check parameters
if auth is None or location is None or epiweeks is None:
raise EpidataBadRequestException("`auth`, `location`, and `epiweeks` are all required")
# Set up request
params = {
"auth": auth,
"location": location,
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("norostat", params)
# Fetch NoroSTAT metadata
@staticmethod
def meta_norostat(auth):
"""Fetch NoroSTAT metadata."""
# Check parameters
if auth is None:
raise EpidataBadRequestException("`auth` is required")
# Set up request
params = {
"auth": auth,
}
# Make the API call
return Epidata._request("meta_norostat", params)
# Fetch NIDSS flu data
@staticmethod
def nidss_flu(regions, epiweeks, issues=None, lag=None):
"""Fetch NIDSS flu data."""
# Check parameters
if regions is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"regions": Epidata._list(regions),
"epiweeks": Epidata._list(epiweeks),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
# Make the API call
return Epidata._request("nidss_flu", params)
# Fetch NIDSS dengue data
@staticmethod
def nidss_dengue(locations, epiweeks):
"""Fetch NIDSS dengue data."""
# Check parameters
if locations is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("nidss_dengue", params)
# Fetch Delphi's forecast
@staticmethod
def delphi(system, epiweek):
"""Fetch Delphi's forecast."""
# Check parameters
if system is None or epiweek is None:
raise EpidataBadRequestException("`system` and `epiweek` are both required")
# Set up request
params = {
"system": system,
"epiweek": epiweek,
}
# Make the API call
return Epidata._request("delphi", params)
# Fetch Delphi's digital surveillance sensors
@staticmethod
def sensors(auth, names, locations, epiweeks):
"""Fetch Delphi's digital surveillance sensors."""
# Check parameters
if names is None or locations is None or epiweeks is None:
raise EpidataBadRequestException(
"`names`, `locations`, and `epiweeks` are all required"
)
# Set up request
params = {
"names": Epidata._list(names),
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
if auth is not None:
params["auth"] = auth
# Make the API call
return Epidata._request("sensors", params)
# Fetch Delphi's dengue digital surveillance sensors
@staticmethod
def dengue_sensors(auth, names, locations, epiweeks):
"""Fetch Delphi's digital surveillance sensors."""
# Check parameters
if auth is None or names is None or locations is None or epiweeks is None:
raise EpidataBadRequestException(
"`auth`, `names`, `locations`, and `epiweeks` are all required"
)
# Set up request
params = {
"auth": auth,
"names": Epidata._list(names),
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("dengue_sensors", params)
# Fetch Delphi's wILI nowcast
@staticmethod
def nowcast(locations, epiweeks):
"""Fetch Delphi's wILI nowcast."""
# Check parameters
if locations is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("nowcast", params)
# Fetch Delphi's dengue nowcast
@staticmethod
def dengue_nowcast(locations, epiweeks):
"""Fetch Delphi's dengue nowcast."""
# Check parameters
if locations is None or epiweeks is None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"locations": Epidata._list(locations),
"epiweeks": Epidata._list(epiweeks),
}
# Make the API call
return Epidata._request("dengue_nowcast", params)
# Fetch API metadata
@staticmethod
def meta():
"""Fetch API metadata."""
return Epidata._request("meta")
# Fetch Delphi's COVID-19 Surveillance Streams
@staticmethod
def covidcast(
data_source,
signals,
time_type,
geo_type,
time_values,
geo_value,
as_of=None,
issues=None,
lag=None,
**kwargs,
):
"""Fetch Delphi's COVID-19 Surveillance Streams"""
# also support old parameter name
if signals is None and "signal" in kwargs:
signals = kwargs["signal"]
# Check parameters
if None in (data_source, signals, time_type, geo_type, time_values, geo_value):
raise EpidataBadRequestException(
"`data_source`, `signals`, `time_type`, `geo_type`, "
"`time_values`, and `geo_value` are all required"
)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"data_source": data_source,
"signals": Epidata._list(signals),
"time_type": time_type,
"geo_type": geo_type,
"time_values": Epidata._list(time_values),
}
if isinstance(geo_value, (list, tuple)):
params["geo_values"] = ",".join(geo_value)
else:
params["geo_value"] = geo_value
if as_of is not None:
params["as_of"] = as_of
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
if "format" in kwargs:
params["format"] = kwargs["format"]
if "fields" in kwargs:
params["fields"] = kwargs["fields"]
# Make the API call
return Epidata._request("covidcast", params)
# Fetch Delphi's COVID-19 Surveillance Streams metadata
@staticmethod
def covidcast_meta():
"""Fetch Delphi's COVID-19 Surveillance Streams metadata"""
return Epidata._request("covidcast_meta")
# Fetch COVID hospitalization data
@staticmethod
def covid_hosp(states, dates, issues=None, as_of=None):
"""Fetch COVID hospitalization data."""
# Check parameters
if states is None or dates is None:
raise EpidataBadRequestException("`states` and `dates` are both required")
# Set up request
params = {
"states": Epidata._list(states),
"dates": Epidata._list(dates),
}
if issues is not None:
params["issues"] = Epidata._list(issues)
if as_of is not None:
params["as_of"] = as_of
# Make the API call
return Epidata._request("covid_hosp_state_timeseries", params)
# Fetch COVID hospitalization data for specific facilities
@staticmethod
def covid_hosp_facility(hospital_pks, collection_weeks, publication_dates=None):
"""Fetch COVID hospitalization data for specific facilities."""
# Check parameters
if hospital_pks is None or collection_weeks is None:
raise EpidataBadRequestException(
"`hospital_pks` and `collection_weeks` are both required"
)
# Set up request
params = {
"hospital_pks": Epidata._list(hospital_pks),
"collection_weeks": Epidata._list(collection_weeks),
}
if publication_dates is not None:
params["publication_dates"] = Epidata._list(publication_dates)
# Make the API call
return Epidata._request("covid_hosp_facility", params)
# Lookup COVID hospitalization facility identifiers
@staticmethod
def covid_hosp_facility_lookup(state=None, ccn=None, city=None, zip=None, fips_code=None):
"""Lookup COVID hospitalization facility identifiers."""
# Set up request
params = {}
if state is not None:
params["state"] = state
elif ccn is not None:
params["ccn"] = ccn
elif city is not None:
params["city"] = city
elif zip is not None:
params["zip"] = zip
elif fips_code is not None:
params["fips_code"] = fips_code
else:
raise EpidataBadRequestException(
"one of `state`, `ccn`, `city`, `zip`, or `fips_code` is required"
)
# Make the API call
return Epidata._request("covid_hosp_facility_lookup", params)
# Fetch Delphi's COVID-19 Nowcast sensors
@staticmethod
def covidcast_nowcast(
data_source,
signals,
sensor_names,
time_type,
geo_type,
time_values,
geo_value,
as_of=None,
issues=None,
lag=None,
**kwargs,
):
"""Fetch Delphi's COVID-19 Nowcast sensors"""
# Check parameters
# fmt: off
if None in (data_source, signals, time_type, geo_type, time_values, geo_value, sensor_names):
# fmt: on
raise EpidataBadRequestException(
"`data_source`, `signals`, `sensor_names`, `time_type`, `geo_type`, "
"`time_values`, and `geo_value` are all required"
)
if issues is not None and lag is not None:
raise EpidataBadRequestException(REGIONS_EPIWEEKS_REQUIRED)
# Set up request
params = {
"data_source": data_source,
"signals": Epidata._list(signals),
"sensor_names": Epidata._list(sensor_names),
"time_type": time_type,
"geo_type": geo_type,
"time_values": Epidata._list(time_values),
}
if isinstance(geo_value, (list, tuple)):
params["geo_values"] = ",".join(geo_value)
else:
params["geo_value"] = geo_value
if as_of is not None:
params["as_of"] = as_of
if issues is not None:
params["issues"] = Epidata._list(issues)
if lag is not None:
params["lag"] = lag
if "format" in kwargs:
params["format"] = kwargs["format"]
# Make the API call
return Epidata._request("covidcast_nowcast", params)
@staticmethod
def async_epidata(endpoint, param_list, batch_size=50):
"""Make asynchronous Epidata calls for a list of parameters."""
request_url = f"{Epidata.BASE_URL}/{endpoint}"
async def async_get(params, session):
"""Helper function to make Epidata GET requests."""
async with session.get(request_url, params=params) as response:
response.raise_for_status()
return await response.json(), params
async def async_make_calls(param_combos):
"""Helper function to asynchronously make and aggregate Epidata GET requests."""
tasks = []
connector = TCPConnector(limit=batch_size)
if isinstance(Epidata.auth, tuple):
auth = BasicAuth(login=Epidata.auth[0], password=Epidata.auth[1], encoding="utf-8")
else:
auth = Epidata.auth
async with ClientSession(connector=connector, headers=_HEADERS, auth=auth) as session:
for param in param_combos:
task = asyncio.ensure_future(async_get(param, session))
tasks.append(task)
responses = await asyncio.gather(*tasks)
return responses
loop = asyncio.get_event_loop()
future = asyncio.ensure_future(async_make_calls(param_list))
responses = loop.run_until_complete(future)
return responses