Skip to content

Commit 5430535

Browse files
committed
init: add read_key() convenience
Currently the data link library allows users to define a simple credential file where the api key is anticipated, but requires an explicit call to read_key(). Introduce convenience logic to set the api key in global configuration, if the file exist. Update documentation in support of read_key() convenience. Signed-off-by: Jamie Couture <jamie.couture@nasdaq.com>
1 parent fe273db commit 5430535

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,23 @@ nasdaqdatalink.ApiConfig.verify_ssl = False
3838

3939
### Local API Key file
4040

41-
The default configuration file location is `~/.nasdaq/data_link_apikey`.
41+
The default configuration file location is `~/.nasdaq/data_link_apikey`. The
42+
client will attempt to load this file if it exists. Note: if the file exists
43+
and empty, a ValueError will be thrown.
4244

43-
Save api key locally:
45+
Save your api key locally:
4446
```
4547
import nasdaqdatalink
4648
nasdaqdatalink.save_key("supersecret")
4749
print(nasdaqdatalink.ApiConfig.api_key)
4850
```
4951

50-
Load the API Key without exposing the key in the script or notebook
51-
52-
```
53-
import nasdaqdatalink
54-
nasdaqdatalink.read_key()
55-
print(nasdaqdatalink.ApiConfig.api_key)
56-
```
57-
58-
Set a custom location for the API key file, e.g. store the externally outside a docker container
52+
Set a custom location for the API key file:
5953
```
6054
import nasdaqdatalink
6155
nasdaqdatalink.save_key("ourcorporateapikey", filename="/srv/data/somecontainer/.corporatenasdaqdatalinkapikey")
6256
```
63-
and call within the docker container with mount point at `/data`
57+
Requires an explicit read_key() call with the absolute path:
6458
```
6559
import nasdaqdatalink
6660
nasdaqdatalink.read_key(filepath="/data/.corporatenasdaqdatalinkapikey")

nasdaqdatalink/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@
1515
from .export_table import export_table
1616
from .get_table import get_table
1717
from .get_point_in_time import get_point_in_time
18+
19+
20+
if api_config.default_config_file_exists():
21+
read_key()

nasdaqdatalink/api_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ def default_config_filename():
3636
return os.path.expanduser(config_file)
3737

3838

39+
def default_config_file_exists():
40+
config_filename = default_config_filename()
41+
return os.path.isfile(config_filename)
42+
43+
3944
def save_key(apikey, filename=None):
4045
if filename is None:
4146
filename = default_config_filename()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy