Introduction
The Macrobond Data API for Python uses either the Macrobond Web REST API or the Macrobond Client data API to obtain time series with values and metadata. The API consists of a set of functions in common between the underlying APIs as well as specialized functions unique to each implementation.
You get time series directly as Pandas series.
Requirements
This API can be used only with Data+ license.
Macrobond Data API for Python officially supports Python 3.6+.
Installation
Macrobond Data API for Python is available on PyPI:
python -m pip install macrobond-data-api
Keyring
When using WebClient it is recommended to use the system keyring. Keyring should only be necessary if you have a license which includes the Web API. If you have Data+ license it shouldn't be needed.
This can be done easily by running the include script using this command:
python -c "from macrobond_data_api.util import *; save_credentials_to_keyring()"
Supported keyrings:
- macOS Keychain
- Freedesktop Secret Service supports many DE including GNOME (requires secretstorage)
- KDE4 & KDE5 KWallet (requires dbus)
- Windows Credential Locker
Error: failed testing username and password
raise self.oauth_error_class( authlib.integrations.base_client.errors.OAuthError: invalid_client: Error: failed testing username and password
This error usually derives from two situations:
- You do not have the proper Macrobond license to use it – the Keyring should only be necessary if you have a license which includes the Web API.
Using Python, R, EViews or MATLAB API you must use the COM API - you do not need to enter any passwords in them as they are fetched from the Macrobond application. - The credentials are being mistyped. When using Windows Command Prompt to set up the Keyring it might be confusing as nothing shows up when you type the password - this is normal security mechanism. Also, by default, you cannot copy and paste in the password field, it must be typed manually.
- To be able to copy the password in the Command Prompt you must enable it in the Command Prompt Properties. To do that, open Command Prompt, right-click on the title bar and select Properties. In here enable 'Use Crtl+Shift+C/V as Copy/Paste'.
- To be able to copy the password in the Command Prompt you must enable it in the Command Prompt Properties. To do that, open Command Prompt, right-click on the title bar and select Properties. In here enable 'Use Crtl+Shift+C/V as Copy/Paste'.
Working with Python wrapper
Learn more about the Commonly used metadata in Macrobond.
Download one series (Basic usage)
import macrobond_data_api as mb_api usgdp = mb_api.get_one_series("usgdp") print(usgdp)
Download one series (Advanced usage)
#web from macrobond_data_api.web import WebClient with WebClient('client id', 'client secret') as api: series = api.get_one_series('usgdp') print(series) #com from macrobond_data_api.com import ComClient with ComClient() as api: series = api.get_one_series('usgdp') print(series)
Extensive guide - more examples
We have prepared examples in Jupyter Notebooks to help you start using Python wrapper. See them on our Github.