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

Commit f1565e7

Browse files
committed
Update tests and readme
1 parent 1d2b600 commit f1565e7

File tree

75 files changed

+1466
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1466
-370
lines changed

README.md

Lines changed: 131 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# First Street Foundation API Access Documentation (Python)
22
The First Street Foundation API Access (Python) is a wrapper used to bulk extract flood data from the First Street Foundation API
33

4-
## Installation
4+
# Installation
55
**NOTE**: This project requires [Python](https://www.python.org/downloads/) 3.6+ to run.
66
1. Go to the Python page (https://www.python.org/downloads/) and download then install Python version 3. **Make sure that the checkbox is checked for Python to be added to the PATH**
77

@@ -33,7 +33,7 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
3333

3434
![Screenshot](doc/images/1.3.1.png)
3535

36-
5. [Optional] Open or close and re-open a new console and create and activate a new virtual environment in the project directory:
36+
5. [Optional] Open a new console or close and re-open a console and create and activate a new virtual environment in the project directory:
3737
```sh
3838
python -m venv /path/to/new/virtual/environment
3939
@@ -66,7 +66,7 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
6666
├── venv
6767
├── my_script.py
6868
69-
## Method 1: Through the Command Line
69+
# Method 1: Through the Command Line
7070
**[Reminder] Keep your API key safe, and do not share it with others!**
7171
7272
1. [Required] Set an Environmental Variable with the `variable_name` as `FSF_API_KEY` and the `variable_value` with the `API_KEY`.
@@ -85,40 +85,19 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
8585

8686
![Screenshot](doc/images/3.2.1.png)
8787

88+
##### Command Line Argument Details:
8889

89-
## Method 2: Through the Client
90-
**[Reminder] Keep your API key safe, and do not share it with others!**
90+
- `-p/--product PRODUCT`: [REQUIRED] The product to call from the API
9191

92-
1. Create a new Python script (by using notepad or any other text editor) and initialize a First Street Foundation API Client.
93-
```python
94-
# Contents of my_script.py
95-
import firststreet
96-
fs = firststreet.FirstStreet("api-key")
97-
```
98-
99-
2. Call one of the methods described below in the `Products` section with the required arguments. See the `Examples` section for more examples.
100-
```python
101-
fs.<product>.<product_subtype>(<fsids: list>, <lookup_type: string>, <csv: boolean>)
102-
```
103-
104-
![Screenshot](doc/images/2.2.1.png)
105-
106-
OR
107-
108-
![Screenshot](doc/images/2.2.2.png)
109-
110-
![Screenshot](doc/images/2.2.3.png)
92+
Example: ```-p location.get_detail```
11193

112-
3. Run the python script.
113-
114-
![Screenshot](doc/images/2.3.1.png)
94+
- `[-api_key/--api_key API_KEY]`: [OPTIONAL] If step 1 is skipped or unavailable, this argument can take the `API_KEY` instead.
11595

96+
Example: ```-a XXXXXXXXXXXXXXXXXXX```
97+
98+
- `[-v/--version VERSION]`: [OPTIONAL] The version of the API to call. Defaults to the current version.
11699

117-
##### Command Line Arguments:
118-
119-
- `-p/--product PRODUCT`: [REQUIRED] The product to call from the API
120-
121-
Example: ```-p location.get_detail```
100+
Example: ```-v v1```
122101

123102
- `[-i/--fsids FSIDS]`: [OPTIONAL] The FSIDs to search for with the product
124103

@@ -128,6 +107,14 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
128107

129108
Example: ```-l property```
130109

110+
- `[-limit/--limit LIMIT]`: [OPTIONAL] The max number of connections to make the the API at the same time. Defaults to 100 connections
111+
112+
Example: ```-limit 20```
113+
114+
- `[-log/--log LOG]`: [OPTIONAL] To log info output to the console or not. Defaults to True
115+
116+
Example: ```-l False```
117+
131118
- `[-f/--file FILE]`: [OPTIONAL] A file of FSIDs (one per line) to search for with the product
132119

133120
Example: ```-f sample.txt```
@@ -146,133 +133,112 @@ The First Street Foundation API Access (Python) is a wrapper used to bulk extrac
146133

147134
![Screenshot](doc/images/4.4.2.png)
148135

149-
## Updating the Project to the Newest Version:
150-
If an update is made to this project, you will need to pull the changes from github and reinstall this project.
151-
152-
1. Open `git bash` and create then navigate to the existing project directory. Then navigate into the project directory, and run:
136+
## Method 2: Through the Client
137+
**[Reminder] Keep your API key safe, and do not share it with others!**
153138

154-
```git
155-
git pull
139+
1. Create a new Python script (by using notepad or any other text editor) and initialize a First Street Foundation API Client.
140+
```python
141+
# Contents of my_script.py
142+
import firststreet
143+
fs = firststreet.FirstStreet("api-key")
156144
```
157-
158-
If the response is `Already up to date.`, then you have the latest version of the project already.
159-
160-
![Screenshot](doc/images/6.1.1.png)
161-
162-
2. Open a new console, navigate to the project, and re-run the setup script to re-install the project:
163-
164-
```shell script
165-
cd /path/to/project
166-
167-
.\venv\Scripts\activate
168-
169-
pip install .\fsf_api_access_python\.
145+
#### Client Initialization Details
146+
147+
```python
148+
firststreet.FirstStreet(api_key, [version], [log])
170149
```
150+
151+
#### Arguments
152+
* api_key `string`: The assigned API key to access the API.
153+
* version `string= v1`: The version of the API to access. Defaults to the current version.
154+
* log `bool= True`: Setting for whether to log info or not. Defaults to True.
171155

172-
![Screenshot](doc/images/6.1.2.png)
173-
174-
3. The project should now be updated to the newest version.
175-
176-
## CSV File Output:
177-
Any product above can be additionally exported to a CSV file for further usage if the csv boolean is set during the product call, or any call using the command line. The extracted can be found in the `data_csv` directory of the project folder (if at least one CSV has been extracted).
178-
179-
180-
### CSV File Name:
181-
The file name will be in the format of `YYYY_MM_DD_HH_mm_SS_product_subtype_lookup.csv`.
182-
183-
Ex:
184-
- `2020_06_10_17_29_49_adaptation_detail.csv`
185-
- `2020_06_10_17_33_56_adaptation_summary_property.csv`
186-
187-
### CSV File Content
188-
The contents of the CSV file will follow similar formats as the `First Street Foundation API - V1.0 Overview and Dictionary`, but all lists will be expanded to a flat file. For any values that are null or not available, `<NA>` will be used.
189-
190-
Ex:
191-
```csv
192-
fsid,year,returnPeriod,bin,low,mid,high
193-
7935,2020,20,20,<NA>,2,<NA>
194-
7935,2020,20,50,<NA>,1,<NA>
195-
7935,2020,20,55,<NA>,2,<NA>
196-
7935,2020,20,65,<NA>,2,<NA>
197-
7935,2020,20,75,<NA>,2,<NA>
198-
7935,2020,20,95,<NA>,1,<NA>
199-
7935,2020,20,100,<NA>,1,<NA>
200-
...
201-
```
202-
![Screenshot](doc/images/5.2.1.png)
156+
2. Call one of the methods described below in the `Products` section with the required arguments. See the `Examples` section for more examples.
157+
```python
158+
fs.<product>.<product_subtype>(<fsids: list>, <lookup_type: string>, <csv: boolean>)
159+
```
160+
161+
![Screenshot](doc/images/2.2.1.png)
162+
163+
OR
164+
165+
![Screenshot](doc/images/2.2.2.png)
166+
167+
![Screenshot](doc/images/2.2.3.png)
168+
169+
3. Run the python script.
203170

204-
![Screenshot](doc/images/5.2.2.png)
171+
![Screenshot](doc/images/2.3.1.png)
205172

206-
## Products
207-
### Location
173+
# Products
174+
#### Location
208175

209176
The Location API provides `Detail` and `Summary` data for the given FSIDs.
210177

211178
```python
212179
location.<method>
213180
```
214181

215-
* `get_detail`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Location Detail` product for the given IDs, location_type, and optionally creates a csv file
216-
* `get_summary`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Location Summary` product for the given IDs, location_type, and optionally creates a csv file
182+
* `get_detail`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Location Detail` product for the given IDs, location_type, and optionally creates a csv file
183+
* `get_summary`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Location Summary` product for the given IDs, location_type, and optionally creates a csv file
217184

218-
### Probability
185+
#### Probability
219186

220187
The Probability API provides `Depth`, `Chance`, `Cumulative`, `Count` data for the given FSIDs.
221188

222189
```python
223190
probability.<method>
224191
```
225192

226-
* `get_depth`(fsids `list`, csv `bool`) - Returns an array of `Probability Depth` product for the given IDs, and optionally creates a csv file
227-
* `get_chance`(fsids `list`, csv `bool`) - Returns an array of `Probability Chance` product for the given IDs, and optionally creates a csv file
228-
* `get_count_summary`(fsids `list`, csv `bool`) - Returns an array of `Probability Count-Summary` product for the given IDs, and optionally creates a csv file
229-
* `get_cumulative`(fsids `list`, csv `bool`) - Returns an array of `Probability Cumulative` product for the given IDs, and optionally creates a csv file
230-
* `get_count`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Probability Count` product for the given IDs, location_type, and optionally creates a csv file
193+
* `get_depth`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Probability Depth` product for the given IDs, and optionally creates a csv file
194+
* `get_chance`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Probability Chance` product for the given IDs, and optionally creates a csv file
195+
* `get_count_summary`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Probability Count-Summary` product for the given IDs, and optionally creates a csv file
196+
* `get_cumulative`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Probability Cumulative` product for the given IDs, and optionally creates a csv file
197+
* `get_count`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Probability Count` product for the given IDs, location_type, and optionally creates a csv file
231198

232-
### Historic
199+
#### Historic
233200

234201
The Historic API provides `Summary` and `Event` data for the given FSIDs.
235202

236203
```python
237204
historic.<method>
238205
```
239206

240-
* `get_event`(fsids `list`, csv `bool`) - Returns an array of `Historic Event` product for the given historic IDs, and optionally creates a csv file
241-
* `get_summary`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Historic Summary` product for the given IDs, location_type, and optionally creates a csv file
207+
* `get_event`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Historic Event` product for the given historic IDs, and optionally creates a csv file
208+
* `get_summary`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Historic Summary` product for the given IDs, location_type, and optionally creates a csv file
242209

243-
### Adaptation
210+
#### Adaptation
244211

245212
The Adaptation API provides `Summary` and `Project` data for the given FSIDs.
246213

247214
```python
248215
adaptation.<method>
249216
```
250217

251-
* `get_project`(fsids `list`, csv `bool`) - Returns an array of `Adaptation Project` product for the given adaptation IDs, and optionally creates a csv file
252-
* `get_summary`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Adaptation Summary` product for the given IDs, location_type, and optionally creates a csv file
218+
* `get_project`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Adaptation Project` product for the given adaptation IDs, and optionally creates a csv file
219+
* `get_summary`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Adaptation Summary` product for the given IDs, location_type, and optionally creates a csv file
253220

254-
### Fema
221+
#### Fema
255222

256223
The Fema API provides `NFIP` data for the given FSIDs.
257224

258225
```python
259226
fema.<method>
260227
```
261228

262-
* `get_nfip`(fsids `list`, location_type `string`, csv `bool`) - Returns an array of `Fema NFIP` product for the given IDs, location_type, and optionally creates a csv file
229+
* `get_nfip`(fsids `list`, location_type `string`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Fema NFIP` product for the given IDs, location_type, and optionally creates a csv file
263230

264-
### Environmental
231+
#### Environmental
265232

266233
The Environmental API provides `Precipitation` data for the given FSIDs.
267234

268235
```python
269236
environmental.<method>
270237
```
271238

272-
* `get_precipitation`(fsids `list`, csv `bool`) - Returns an array of `Environmental Precipitation` product for the given county IDs, and optionally creates a csv file
273-
239+
* `get_precipitation`(fsids `list`, csv `bool`, [core_limit `int=100`]) - Returns an array of `Environmental Precipitation` product for the given county IDs, and optionally creates a csv file
274240

275-
## Examples
241+
# Examples
276242
**[Reminder] Keep your API key safe, and do not share it with others!**
277243
1. Single FSID Extraction Through the Client:
278244
```python
@@ -373,5 +339,65 @@ environmental.<method>
373339
541262690,1,0,1,0,0
374340
540651172,1,0,1,0,0
375341
```
342+
343+
344+
# CSV File Output:
345+
Any product above can be additionally exported to a CSV file for further usage if the csv boolean is set during the product call, or any call using the command line. The extracted can be found in the `data_csv` directory of the project folder (if at least one CSV has been extracted).
346+
347+
348+
#### CSV File Name:
349+
The file name will be in the format of `YYYY_MM_DD_HH_mm_SS_product_subtype_lookup.csv`.
350+
351+
Ex:
352+
- `2020_06_10_17_29_49_adaptation_detail.csv`
353+
- `2020_06_10_17_33_56_adaptation_summary_property.csv`
354+
355+
#### CSV File Content
356+
The contents of the CSV file will follow similar formats as the `First Street Foundation API - V1.0 Overview and Dictionary`, but all lists will be expanded to a flat file. For any values that are null or not available, `<NA>` will be used.
357+
358+
Ex:
359+
```csv
360+
fsid,year,returnPeriod,bin,low,mid,high
361+
7935,2020,20,20,<NA>,2,<NA>
362+
7935,2020,20,50,<NA>,1,<NA>
363+
7935,2020,20,55,<NA>,2,<NA>
364+
7935,2020,20,65,<NA>,2,<NA>
365+
7935,2020,20,75,<NA>,2,<NA>
366+
7935,2020,20,95,<NA>,1,<NA>
367+
7935,2020,20,100,<NA>,1,<NA>
368+
...
369+
```
370+
![Screenshot](doc/images/5.2.1.png)
371+
372+
![Screenshot](doc/images/5.2.2.png)
373+
374+
# Updating the Project to the Newest Version:
375+
If an update is made to this project, you will need to pull the changes from github and reinstall this project.
376+
377+
1. Open `git bash` and create then navigate to the existing project directory. Then navigate into the project directory, and run:
378+
379+
```git
380+
git pull
381+
```
382+
383+
If the response is `Already up to date.`, then you have the latest version of the project already.
384+
385+
![Screenshot](doc/images/6.1.1.png)
386+
387+
2. Open a new console, navigate to the project, and re-run the setup script to re-install the project:
388+
389+
```shell script
390+
cd /path/to/project
376391
392+
.\venv\Scripts\activate
393+
394+
pip install .\fsf_api_access_python\.
395+
```
396+
397+
![Screenshot](doc/images/6.1.2.png)
398+
399+
3. The project should now be updated to the newest version
400+
401+
402+
377403
[git]: <https://git-scm.com/downloads>

firststreet/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# Author: Kelvin Lai <kelvin@firststreet.org>
33
# Copyright: This module is owned by First Street Foundation
44

5+
# Standard Imports
6+
import logging
7+
58
# Internal Imports
69
from firststreet.api.adaptation import Adaptation
710
from firststreet.api.environmental import Environmental
@@ -19,7 +22,8 @@ class FirstStreet:
1922
2023
Attributes:
2124
api_key (str): A string specifying the API key.
22-
options (dict): A dict that has the url used in the request header
25+
version (str): The version to call the API with
26+
log (bool): To log the outputs on info level
2327
Example:
2428
```python
2529
import os
@@ -32,15 +36,16 @@ class FirstStreet:
3236
MissingAPIError: If the API is not provided
3337
"""
3438

35-
def __init__(self, api_key=None, options=None):
39+
def __init__(self, api_key=None, version=None, log=True):
3640

3741
if not api_key:
3842
raise MissingAPIKeyError('Missing API Key.')
3943

40-
if options is None:
41-
options = {}
44+
if log:
45+
logging.basicConfig(level=logging.INFO,
46+
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
4247

43-
self.http = Http(api_key, options)
48+
self.http = Http(api_key, version)
4449
self.location = Location(self.http)
4550
self.probability = Probability(self.http)
4651
self.historic = Historic(self.http)

0 commit comments

Comments
 (0)