Skip to content
This repository was archived by the owner on Jan 18, 2023. It is now read-only.

Commit 5aaf89c

Browse files
committed
Speed up CSV convert for probability. Add rate limit explicitly to asyncio calls
1 parent c66bdf5 commit 5aaf89c

File tree

16 files changed

+370
-301
lines changed

16 files changed

+370
-301
lines changed

README.md

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,17 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
125125

126126
Example: ```-l property```
127127

128-
- `[-connection_limit/--connection_limit CONNECTION_LIMIT]`: [OPTIONAL] The max number of concurrent connections to make the the API at the same time. This is does not affect the number of FSIDs that can be pulled. Defaults to 100 connections
128+
- `[-connection_limit/--connection_limit CONNECTION_LIMIT]`: [OPTIONAL] The max number of concurrent connections to make to the API at the same time. This is does not affect the number of FSIDs that can be pulled. Defaults to 100 connections
129129

130-
Example: ```-connection_limit 20```
130+
Example: ```-connection_limit 20000```
131+
132+
- `[-rate_limit/--rate_limit RATE_LIMIT]`: [OPTIONAL] The max number of requests during the rate limit period. Defaults to 20000 requests
133+
134+
Example: ```-rate_limit 1```
135+
136+
- `[-rate_period/--rate_period RATE_PERIOD]`: [OPTIONAL] The period of time for the rate limit. Defaults to 1 second
137+
138+
Example: ```-rate_period 20```
131139

132140
- `[-log/--log LOG]`: [OPTIONAL] To log info output to the console or not. Defaults to True
133141

@@ -184,12 +192,15 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
184192
#### [Client Initialization Details](#toc)
185193

186194
```python
187-
firststreet.FirstStreet(api_key, [version], [log])
195+
firststreet.FirstStreet(api_key, [connection_limit], [rate_limit], [rate_period], [version], [log])
188196
```
189197

190198
<a name="client-arguments"></a>
191199
#### [Arguments](#toc)
192200
* api_key `string`: The assigned API key to access the API.
201+
* connection_limit `int=100`: The max number of connections to make
202+
* rate_limit `int=20000`: The max number of requests during the period
203+
* rate_period `int=1`: The period of time for the limit
193204
* version `string= v1`: The version of the API to access. Defaults to the current version.
194205
* log `bool= True`: Setting for whether to log info or not. Defaults to True.
195206

@@ -263,8 +274,8 @@ The Location API provides `Detail` and `Summary` data for the given SearchItems.
263274
location.<method>
264275
```
265276

266-
* `get_detail`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Location Detail` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
267-
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Location Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
277+
* `get_detail`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Location Detail` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
278+
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Location Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
268279

269280
<a name="probability"></a>
270281
#### [Probability](#toc)
@@ -277,11 +288,11 @@ The Probability API provides `Depth`, `Chance`, `Cumulative`, `Count` data for t
277288
probability.<method>
278289
```
279290

280-
* `get_depth`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Depth` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
281-
* `get_chance`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Chance` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
282-
* `get_count_summary`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Count-Summary` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
283-
* `get_cumulative`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Cumulative` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
284-
* `get_count`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Count` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
291+
* `get_depth`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Depth` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
292+
* `get_chance`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Chance` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
293+
* `get_count_summary`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Count-Summary` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
294+
* `get_cumulative`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Cumulative` product for the given IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
295+
* `get_count`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Count` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
285296

286297
<a name="historic"></a>
287298
#### [Historic](#toc)
@@ -294,9 +305,9 @@ The Historic API provides `Summary` and `Event` data for the given SearchItems.
294305
historic.<method>
295306
```
296307

297-
* `get_event`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Event` product for the given historic IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
298-
* `get_events_by_location`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Detail` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
299-
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
308+
* `get_event`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Event` product for the given historic IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
309+
* `get_events_by_location`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Detail` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
310+
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
300311

301312
<a name="adaptation"></a>
302313
#### [Adaptation](#toc)
@@ -309,9 +320,9 @@ The Adaptation API provides `Summary` and `Project` data for the given SearchIte
309320
adaptation.<method>
310321
```
311322

312-
* `get_project`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Project` product for the given adaptation IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
313-
* `get_details_by_location`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Project` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
314-
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
323+
* `get_project`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Project` product for the given adaptation IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
324+
* `get_details_by_location`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Project` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
325+
* `get_summary`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Adaptation Summary` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
315326

316327
<a name="fema"></a>
317328
#### [Fema](#toc)
@@ -324,7 +335,7 @@ The Fema API provides `NFIP` data for the given SearchItems.
324335
fema.<method>
325336
```
326337

327-
* `get_nfip`(search_items `list/file`, location_type `string`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Fema NFIP` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
338+
* `get_nfip`(search_items `list/file`, location_type `string`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Fema NFIP` product for the given IDs, location_type, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
328339

329340
<a name="environmental"></a>
330341
#### [Environmental](#toc)
@@ -337,7 +348,7 @@ The Environmental API provides `Precipitation` data for the given SearchItems.
337348
environmental.<method>
338349
```
339350

340-
* `get_precipitation`(search_items `list/file`, csv `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Environmental Precipitation` product for the given county IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
351+
* `get_precipitation`(search_items `list/file`, csv `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Environmental Precipitation` product for the given county IDs, and optionally creates a csv file. Arguments provided to `extra_param` will be appened to the end of the endpoint call
341352

342353
<a name="tiles"></a>
343354
#### [Tiles](#toc)
@@ -350,8 +361,8 @@ The Flood Tiles product give the ability to customize maps by layering on flood
350361
tile.<method>
351362
```
352363

353-
* `get_probability_depth`(coordinate `tuple of int`, year `int`, return_period `int`, image `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Depth Tile` product for the given coordinates, and optionally creates an image file
354-
* `get_historic_event`(coordinate `tuple of int`, event_id `int`, image `bool`, [connection_limit `int=100`], [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Event Tile` product for the given coordinates, and optionally creates an image file
364+
* `get_probability_depth`(coordinate `tuple of int`, year `int`, return_period `int`, image `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Probability Depth Tile` product for the given coordinates, and optionally creates an image file
365+
* `get_historic_event`(coordinate `tuple of int`, event_id `int`, image `bool`, [output_dir `str='cwd'`], [extra_param `str=None`]) - Returns an array of `Historic Event Tile` product for the given coordinates, and optionally creates an image file
355366

356367
<a name="examples"></a>
357368
# [Examples](#toc)

firststreet/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class FirstStreet:
2323
2424
Attributes:
2525
api_key (str): A string specifying the API key.
26+
connection_limit (int): max number of connections to make
27+
rate_limit (int): max number of requests during the period
28+
rate_period (int): period of time for the limit
2629
version (str): The version to call the API with
2730
log (bool): To log the outputs on info level
2831
Example:
@@ -37,7 +40,7 @@ class FirstStreet:
3740
MissingAPIError: If the API is not provided
3841
"""
3942

40-
def __init__(self, api_key=None, version=None, log=True):
43+
def __init__(self, api_key=None, connection_limit=100, rate_limit=20000, rate_period=1, version=None, log=True):
4144

4245
if not api_key:
4346
raise MissingAPIKeyError('Missing API Key.')
@@ -46,7 +49,7 @@ def __init__(self, api_key=None, version=None, log=True):
4649
logging.basicConfig(level=logging.INFO,
4750
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
4851

49-
self.http = Http(api_key, version)
52+
self.http = Http(api_key, connection_limit, rate_limit, rate_period, version)
5053
self.location = Location(self.http)
5154
self.probability = Probability(self.http)
5255
self.historic = Historic(self.http)

0 commit comments

Comments
 (0)