If you like to use Python to retrieve data from the Datastream Web Services API (DSWS), you can use the package PyDSWS. It is a simple Python wrapper I’ve built. You do need to have a Datastream subscription and a username/password to use this package. Please note that this is an unofficial/unsupported package and it is still under development. The package has basic functionality and most of the error handling still needs to be done. The source code can be found on GitHub.
Installation
First, install the Python package. Installation:
pip install PyDSWS
PyDSWS is written in Python 3. It has the following dependencies:
- pandas
- requests
Retrieve Datastream data with Python
An example how to retrieve closing prices for Vodafone.
- import the ‘PyDSWS’ package
- authenticate with your username and password
- use the ‘get_data’ function
import PyDSWS ds = PyDSWS.Datastream(username='XXXXXXX', password='XXXXXXX') df = ds.get_data('VOD') print(df)
Please find below examples on how to set parameters for the requests.
Firstly, for static data:
ds.get_data(tickers='VOD', fields='P', date='2017-01-01')
Secondly, for time series:
ds.get_data(tickers='VOD', fields='P,MV,VO', start='-10D', end='-0D', freq='D')
*for multiple tickers/fields, just use a comma. In this example: fields=’P,MV,VO’
Finally, the output is a Pandas DataFrame:
Instrument VOD Field P MV VO Date 2017-11-21 229.75 61283.06 55100.4 2017-11-22 228.75 61016.34 79602.5 2017-11-23 225.40 60122.75 35724.1 2017-11-24 225.50 60149.44 42918.0 2017-11-27 224.60 59909.38 50355.3 2017-11-28 226.45 60402.83 49027.0 2017-11-29 225.25 60082.74 61618.1 2017-11-30 224.30 59829.99 95423.4 2017-12-01 224.00 59749.96 54855.4 2017-12-04 225.55 60163.41 47524.1 2017-12-05 225.25 60083.38 43846.7
In addition, in order to get usage statistics call:
ds.get_usage()
Likewise, the output is a Pandas DataFrame:
Instrument STATS Field User Hits Requests Datatypes Datapoints Start Date End Date Date 2019-06-26 ZMTXXXX 564 362 1319 1283696 2019-06-01 2019-07-01
Please check http://datastream.thomsonreuters.com/DswsClient/Docs/Default.aspx for further documentation. Furthermore, you can use the Datastream Navigator to look up codes and data types: http://product.datastream.com/navigator/
Development
If you discover any issues with regards to this project, please feel free to create an Issue on GitHub. If you have coding suggestions that you would like to provide for review, please create a Pull Request.
Acknowledgements
The packages used other packages as example. Most importantly, thanks to Vladimir Filimonov for his work on https://github.com/vfilimonov/pydatastream, and Charles Cara for https://github.com/CharlesCara/DatastreamDSWS2R
Conclusion: Datastream Python
To conclude: the Datastream WebServices API and Python can work together nicely. Are you also using the Eikon API? If not, you might want to take a look at Eikon Data API & Python – A Quickstart.
Finally, you have any questions regarding the PyDSWS package, please feel free to reach out. Happy coding!