Skip to content
This repository was archived by the owner on Apr 30, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ quandl.ApiConfig.api_version = '2015-04-09'

`quandl.ApiConfig.api_version` is optional however it is strongly recommended to avoid issues with rate-limiting. For premium databases, datasets and datatables `quandl.ApiConfig.api_key` will need to be set to identify you to our API. Please see [API Documentation](https://www.quandl.com/docs/api) for more detail.


### Local API Key file
Save local key to `$HOME/.quandl_apikey` file
```
import quandl
quandl.save_key("supersecret")
print(quandl.ApiConfig.api_key)
```

Load the API Key without exposing the key in the script or notebook
```
import quandl
quandl.read_key()
print(quandl.ApiConfig.api_key)
```

Set a custom location for the API key file, e.g. store the externally outside a docker container
```
import quandl
quandl.save_key("ourcorporateapikey", filename="/srv/data/somecontainer/.corporatequandlapikey")
```
and call within the docker container with mount point at `/data`
```
import quandl
quandl.read_key(filepath="/data/.corporatequandlapikey")
```


## Retrieving Data

There are two methods for retrieving data in Python: the Quick method and the Detailed method. The latter is more suitable to application programming. Both methods work with Quandl's two types of data structures: time-series (dataset) data and non-time series (datatable).
Expand Down
2 changes: 1 addition & 1 deletion quandl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from .api_config import ApiConfig
from .api_config import ApiConfig, save_key, read_key

from .errors.quandl_error import *

Expand Down
29 changes: 29 additions & 0 deletions quandl/api_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,32 @@ class ApiConfig:
api_base = 'https://www.quandl.com/api/v3'
api_version = None
page_limit = 100


def save_key(apikey, filename=None):
if filename is None:
import pathlib
filename = str(pathlib.Path.home()) + "/.quandl_apikey"

fileptr = open(filename, 'w')
fileptr.write(apikey)
fileptr.close()
ApiConfig.api_key = apikey


def read_key(filename=None):
if filename is None:
import pathlib
filename = str(pathlib.Path.home()) + "/.quandl_apikey"

try:
fileptr = open(filename, 'r')
apikey = fileptr.read()
fileptr.close()

if apikey:
ApiConfig.api_key = apikey
else:
raise Exception("File '{:s}' is empty.".format(filename))
except ValueError:
raise Exception("File '{:s}' not found.".format(filename))