8000 documentation: avoid api key bad practices (#7) · Nasdaq/data-link-python@1920b0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1920b0d

Browse files
authored
documentation: avoid api key bad practices (#7)
Encourage users to rely on setting their api key via an environment variable or a local file instead of following the sample code's bad practice of setting the api key inline. Signed-off-by: Jamie Couture <jamie.couture@nasdaq.com>
1 parent 3478b48 commit 1920b0d

File tree

3 files changed

+13
-33
lines changed

3 files changed

+13
-33
lines changed

FOR_ANALYSTS.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ This quick guide offers convenient ways to retrieve individual datasets or datat
44

55
## Retrieving Data
66

7-
Retrieving data can be achieved easily using these methods `nasdaqdatalink.get` for datasets, `nasdaqdatalink.get_table` for datatables and `nasdaqdatalink.get_point_in_time` for point in time data. In all cases we strongly recommend that you set your api key via:
7+
Retrieving data can be achieved easily using these methods `nasdaqdatalink.get` for datasets, `nasdaqdatalink.get_table` for datatables and `nasdaqdatalink.get_point_in_time` for point in time data.
88

9-
```python
10-
import nasdaqdatalink
11-
nasdaqdatalink.ApiConfig.api_key = 'tEsTkEy123456789'
12-
```
9+
We strongly recommend that you set your api key using [environment variable](README.md#Local-API-Key-Environment-Variable) or [local file options](README.md#Local-API-Key-file).
1310

1411
### Datasets
1512

@@ -43,7 +40,7 @@ The following additional parameters can be specified for a dataset call:
4340

4441
| Option | Explanation | Example | Description |
4542
|--------|-------------|---------|-------------|
46-
| api_key | Your access key | `api_key='tEsTkEy123456789'` | Used to identify who you are and provide more access. Only required if not set via `nasdaqdatalink.ApiConfig.api_key=` |
43+
| api_key | Your access key | `api_key='tEsTkEy123456789'` | Used to identify who you are and provide more access. |
4744
| \<filter / transformation parameter\> | A parameter which filters or transforms the resulting data | `start_date='2010-01-01` | For a full list see our [api docs](https://docs.data.nasdaq.com/docs) |
4845

4946
For more information on how to use and manipulate the resulting data see the [pandas documentation](http://pandas.pydata.org/).
@@ -168,7 +165,7 @@ The following additional parameters can be specified for a datatable call:
168165

169166
| Option | Explanation | Example | Description |
170167
|---|---|---|---|
171-
| api_key | Your access key | `api_key='tEsTkEy123456789'` | Used to identify who you are and provide more access. Only required if not set via `nasdaqdatalink.ApiConfig.api_key=` |
168+
| api_key | Your access key | `api_key='tEsTkEy123456789'` | Used to identify who you are and provide more access. |
172169
| \<filter / transformation parameter\> | A parameter which filters or transforms the resulting data | `start_date='2010-01-01'` | For a full list see our [api docs](https://docs.data.nasdaq.com/docs) |
173170
| paginate | Wether to autoamtically paginate data | `paginate=True` | Will paginate through the first few pages of data automatically and merge them together in a larger output format. |
174171

FOR_DEVELOPERS.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,12 @@ In addition to the Quick methods for retrieving data, some additional commands m
66
* Customizing how data is returned more granularly
77
* Allowing easier iteration of data
88

9-
In each of the following sections it is assumed your Nasdaq Data LInk API key has been set via:
10-
11-
```python
12-
import nasdaqdatalink
13-
nasdaqdatalink.ApiConfig.api_key = 'tEsTkEy123456789'
14-
```
15-
169
## Retrieving Data
1710

1811
In the following sections, `params={}` represents optional query parameters that can be passed into each call. For more detail on available query parameters please see the [API Documentation](https://docs.data.nasdaq.com/docs).
1912

13+
We strongly recommend that you set your api key using [environment variable](README.md#Local-API-Key-Environment-Variable) or [local file options](README.md#Local-API-Key-file).
14+
2015
### Dataset
2116

2217
A dataset's data can be queried through the dataset object. For example:

README.md

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ pip3 install nasdaq-data-link
2727
| retry_backoff_factor | Determines the amount of time in seconds that should be waited before attempting another retry. Note that this factor is exponential so a `retry_backoff_factor` of 0.5 will cause waits of [0.5, 1, 2, 4, etc]. Only used if `use_retries` is True | 0.5
2828
| retry_status_codes | A list of HTTP status codes which will trigger a retry to occur. Only used if `use_retries` is True| [429, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511]
2929

30-
```python
31-
import nasdaqdatalink
32-
nasdaqdatalink.ApiConfig.api_key = 'tEsTkEy123456789'
33-
```
34-
By default, SSL verification is enabled. To bypass SSL verification
30+
By default, SSL verification is enabled. To bypass SSL verification (not recommended), simply:
31+
3532
```python
3633
nasdaqdatalink.ApiConfig.verify_ssl = False
3734
```
@@ -46,20 +43,12 @@ The default configuration file location is `~/.nasdaq/data_link_apikey`. The
4643
client will attempt to load this file if it exists. Note: if the file exists
4744
and empty, a ValueError will be thrown.
4845

49-
Save your api key locally:
50-
```
51-
import nasdaqdatalink
52-
nasdaqdatalink.save_key("supersecret")
53-
print(nasdaqdatalink.ApiConfig.api_key)
54-
```
46+
#### Alternative API Key file location
5547

56-
Set a custom location for the API key file:
57-
```
58-
import nasdaqdatalink
59-
nasdaqdatalink.save_key("ourcorporateapikey", filename="/srv/data/somecontainer/.corporatenasdaqdatalinkapikey")
60-
```
61-
Requires an explicit read_key() call with the absolute path:
62-
```
48+
Since 1.0.0, the `nasdaq-data-link` module will attempt to autoload your API Key. If you prefer to store it in another location, you must
49+
explicitly call `read_key()` with a custom path. See below:
50+
51+
```python
6352
import nasdaqdatalink
6453
nasdaqdatalink.read_key(filepath="/data/.corporatenasdaqdatalinkapikey")
6554
```
@@ -105,7 +94,6 @@ data_link_log = logging.getLogger("nasdaqdatalink")
10594
data_link_log.setLevel(logging.DEBUG)
10695
```
10796

108-
10997
### Detailed Usage
11098

11199
Our API can provide more than just data. It can also be used to search and provide metadata or to programmatically retrieve data. For these more advanced techniques please follow our [Detailed Method Guide](./FOR_DEVELOPERS.md).

0 commit comments

Comments
 (0)
0