Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proxy settings and new tables endpoint #8

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions fred/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ class Fred(object):
:arg str realtime_start: The start of the real-time period. Format "YYYY-MM-DD"
:arg str realtime_end: The end of the real-time period. Format "YYYY-MM-DD"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set HTTP(S) proxy handler. Format: {'http': '127.0.0.1:1081'}
"""
def __init__(self,api_key=c.api_key,response_type=c.response_type, ssl_verify=c.ssl_verify):
def __init__(self,api_key=c.api_key,response_type=c.response_type,ssl_verify=c.ssl_verify,proxy=c.proxy):
## Set root URL
self.url_root = 'https://api.stlouisfed.org/fred'
## Set default API key
Expand All @@ -34,9 +35,11 @@ def __init__(self,api_key=c.api_key,response_type=c.response_type, ssl_verify=c.
self.response_type = response_type if response_type else None
## Set SSL Verify
self.ssl_verify = ssl_verify
## Set HTTP(S) proxy
self.proxy = proxy
## Initiate clients
self.category = CategoriesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify)
self.release = ReleasesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify)
self.series = ESeriesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify)
self.tag = TagsClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify)
self.source = SourcesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify)
self.category = CategoriesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify,self.proxy)
self.release = ReleasesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify,self.proxy)
self.series = ESeriesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify,self.proxy)
self.tag = TagsClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify,self.proxy)
self.source = SourcesClient(weakref.proxy(self),self.api_key,self.url_root,self.response_type,self.ssl_verify,self.proxy)
18 changes: 12 additions & 6 deletions fred/clients/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def details(self,category_id=None,response_type=None,params=None):
:arg str response_type: File extension of response. Options are 'xml', 'json',
'dict','df','numpy','csv','tab,'pipe'. Required.
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path='/category?'
params['category_id'] = category_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end')
Expand All @@ -36,12 +37,13 @@ def children(self,category_id=None,response_type=None,params=None):
:arg str realtime_start: The start of the real-time period. Format "YYYY-MM-DD"
:arg str realtime_end: The end of the real-time period. Format "YYYY-MM-DD"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path='/category/children?'
params['category_id'] = category_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end')
Expand All @@ -59,12 +61,13 @@ def related(self,category_id=None,response_type=None,params=None):
:arg str realtime_start: The start of the real-time period. Format "YYYY-MM-DD"
:arg str realtime_end: The end of the real-time period. Format "YYYY-MM-DD"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/category/related?'
params['category_id'] = category_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit','offset',
Expand All @@ -91,12 +94,13 @@ def series(self,category_id=None,response_type=None,params=None):
:arg str tag_names: Tag names used to match series. Separate with semicolon as in "income;bea"
:arg str exclude_tag_names: Tag names used to exclude series. Separate with semicolon as in "income;bea"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/category/series?'
params['category_id'] = category_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit','offset',
Expand Down Expand Up @@ -125,12 +129,13 @@ def tags(self,category_id=None,response_type=None,params=None):
:arg str tag_group_id: Tag ID to filter tags by. Options are 'freq', 'gen', 'geo', 'geot', 'rls', 'seas', 'src'
:arg str search_text: The words to find matching tags with. For example 'mortgage rates'
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/category/tags?'
params['category_id'] = category_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit','offset',
Expand Down Expand Up @@ -160,10 +165,11 @@ def related_tags(self,category_id=None,tag_names=None,response_type=None,params=
:arg str tag_group_id: Tag ID to filter tags by. Options are 'freq', 'gen', 'geo', 'geot', 'rls', 'seas', 'src'
:arg str search_text: The words to find matching tags with. For example 'mortgage rates'
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path='/category/related_tags?'
params['category_id'], params['tag_names'] = category_id, tag_names
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response
29 changes: 19 additions & 10 deletions fred/clients/eseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def details(self,series_id=None,response_type=None,params=None):
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end')
Expand All @@ -39,12 +39,13 @@ def categories(self,series_id=None,response_type=None,params=None):
:arg str realtime_start: The start of the real-time period. Format "YYYY-MM-DD"
:arg str realtime_end: The end of the real-time period. Format "YYYY-MM-DD"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path='/series/categories?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end')
Expand All @@ -59,12 +60,13 @@ def release(self,series_id=None,response_type=None,params=None):
:arg str realtime_start: The start of the real-time period. Format "YYYY-MM-DD"
:arg str realtime_end: The end of the real-time period. Format "YYYY-MM-DD"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path='/series/release?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end',
Expand All @@ -84,12 +86,13 @@ def tags(self,series_id=None,response_type=None,params=None):
'popularity', 'created', 'name', 'group_id'
:arg str sort_order: Sort results for attribute values specified by order_by. Options are 'asc','desc'
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/tags?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit',
Expand All @@ -111,12 +114,13 @@ def updates(self,series_id=None,response_type=None,params=None):
:arg str filter_value: Limit results by geographic type of economic data series. Options are 'macro',
'regional', and 'all'
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/updates?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit',
Expand All @@ -137,12 +141,13 @@ def vintage_dates(self,series_id=None,response_type=None,params=None):
:arg int offset: Data offset. Options >=0
:arg str sort_order: Sort results by vintage_date. Options are 'asc','desc'
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/vintagedates?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end','limit',
Expand Down Expand Up @@ -174,12 +179,13 @@ def observations(self,series_id=None,response_type=None,params=None):
:arg int output_type: Output type. Options are 1, 2, 3, 4
:arg str vintage_dates: Date(s) in history. Format "YYYY-MM-DD". Example for multiple dates "2000-01-01,2005-02-24,..."
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/observations?'
params['series_id'] = series_id
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('search_type','realtime_start','realtime_end',
Expand Down Expand Up @@ -207,12 +213,13 @@ def search(self,search_text=None,response_type=None,params=None):
:arg str tag_names: Tag names used to match series. Separate with semicolon as in "income;bea"
:arg str exclude_tag_names: Tag names used to exclude series. Separate with semicolon as in "income;bea"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/search?'
params['search_text'] = search_text
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end',
Expand All @@ -237,12 +244,13 @@ def search_tags(self,series_search_text=None,response_type=None,params=None):
:arg str tag_group_id: Tag ID to filter tags by. Options are 'freq', 'gen', 'geo', 'geot', 'rls', 'seas', 'src'
:arg str tag_search_text: The words to find matching tags with.
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/search/tags?'
params['series_search_text'] = series_search_text
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response

@query_params('realtime_start','realtime_end',
Expand All @@ -268,10 +276,11 @@ def search_related_tags(self,series_search_text=None,tag_names=None,response_typ
:arg str tag_search_text: The words to find matching tags with.
:arg str exclude_tag_names: Tag names to exclude. Separate with semicolon as in "income;bea"
:arg bool ssl_verify: To verify HTTPs.
:arg dict proxy: Set proxy dictionary.
"""
path = '/series/search/related_tags?'
params['series_search_text'], params['tag_names'] = series_search_text, tag_names
response_type = response_type if response_type else self.response_type
if response_type != 'xml': params['file_type'] = 'json'
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify)
response = _get_request(self.url_root,self.api_key,path,response_type,params,self.ssl_verify,self.proxy)
return response
Loading