Skip to content

Commit 7b0df50

Browse files
authored
Merge pull request #14 from SimFin/DEV-231-Autherntication-with-header-api-key
Dev 231 autherntication with header api key
2 parents 47ca12b + 4078dc6 commit 7b0df50

5 files changed

Lines changed: 191 additions & 17 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# This is also defined in simfin/__init__.py and must be
55
# updated in both places.
6-
MY_VERSION = '0.8.4'
6+
MY_VERSION = '0.9.0'
77

88
setup(
99
name='simfin',

simfin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This is also defined in setup.py and must be updated in both places.
2-
__version__ = "0.8.4"
2+
__version__ = "0.9.0"
33

44
# Expose the following as top-level imports.
55

simfin/download.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121

2222
##########################################################################
2323

24+
def _headers_dataset():
25+
api_key = get_api_key()
26+
if api_key is not None:
27+
return {'Authorization': 'api-key ' + api_key}
28+
else:
29+
raise ValueError('Api-Key is not set')
30+
31+
2432
def _url_dataset(dataset, market=None, variant=None):
2533
"""
2634
Compose the URL for a dataset on the SimFin server.
@@ -46,13 +54,8 @@ def _url_dataset(dataset, market=None, variant=None):
4654
if market is not None:
4755
args += '&market=' + market
4856

49-
# API key.
50-
api_key = get_api_key()
51-
if api_key is not None:
52-
args += '&api-key=' + api_key
53-
5457
# Base URL for the bulk-download API on the SimFin server.
55-
base_url = 'https://simfin.com/api/bulk?'
58+
base_url = 'https://backend.simfin.com/api/bulk-download?'
5659

5760
# Combine base URL and arguments.
5861
url = base_url + args
@@ -107,7 +110,7 @@ def _print_download_progress(downloaded_size, total_size):
107110

108111
##########################################################################
109112

110-
def _download(url, download_path):
113+
def _download(url, headers, download_path):
111114
"""
112115
Download a file from an internet URL and save it to disk.
113116
@@ -130,7 +133,8 @@ def _download(url, download_path):
130133
"""
131134

132135
# Open a streaming connection to the server.
133-
with requests.get(url, stream=True) as response:
136+
with requests.get(url, headers=headers,
137+
stream=True) as response:
134138
# Get the status code for the connection.
135139
status_code = response.status_code
136140

@@ -173,7 +177,7 @@ def _download(url, download_path):
173177

174178
##########################################################################
175179

176-
def _maybe_download(name, url, path, download_path, refresh_days):
180+
def _maybe_download(name, url, headers, path, download_path, refresh_days):
177181
"""
178182
Check if the file in `path` exists on disk or if it is too old, and then
179183
download the file from `url` and save it to disk.
@@ -236,7 +240,7 @@ def _maybe_download(name, url, path, download_path, refresh_days):
236240
if must_download:
237241
# Download the file from the SimFin server.
238242
# This is assumed to succeed unless an exception is raised.
239-
_download(url=url, download_path=download_path)
243+
_download(url=url, headers=headers, download_path=download_path)
240244

241245
if download_path.endswith('zip'):
242246
# Downloaded file must be unzipped into the data-dir.
@@ -285,12 +289,14 @@ def _maybe_download_dataset(refresh_days, **kwargs):
285289
# Full path for the downloaded file.
286290
download_path = _path_download_dataset(**kwargs)
287291

292+
headers = _headers_dataset()
293+
288294
# URL to SimFin's server where the file is located.
289295
url = _url_dataset(**kwargs)
290296

291297
return _maybe_download(name=dataset_name, path=path,
292298
download_path=download_path,
293-
url=url, refresh_days=refresh_days)
299+
url=url, headers=headers, refresh_days=refresh_days)
294300

295301
##########################################################################
296302

@@ -313,8 +319,9 @@ def _maybe_download_info(name, refresh_days):
313319
# URL to SimFin's server where the file is located.
314320
url = _url_info(name=name)
315321

322+
headers = _headers_dataset()
316323
return _maybe_download(name=name, path=path,
317324
download_path=download_path,
318-
url=url, refresh_days=refresh_days)
325+
url=url,headers=headers, refresh_days=refresh_days)
319326

320327
##########################################################################

simfin/names_extra.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
SPS = SALES_PER_SHARE = 'Sales Per Share'
1919

2020
#: Net Income / Number of Shares.
21-
EPS_BASIC = EPS = EARNINGS_PER_SHARE = 'Earnings per Share, Basic'
21+
EPS_BASIC = EPS = EARNINGS_PER_SHARE = 'Earnings Per Share, Basic'
2222

2323
#: Net Income / Number of Shares.
24-
EPS_DILUTED = 'Earnings per Share, Diluted'
24+
EPS_DILUTED = 'Earnings Per Share, Diluted'
2525

2626
#: Total Equity / Number of Shares.
2727
EQ_PS = EQUITY_PER_SHARE = BV_PS = BOOK_VALUE_PER_SHARE = 'Equity Per Share'

0 commit comments

Comments
 (0)