Create a Python Client Application
This sample Python application demonstrates communication with the Morgan Stanley API offering. It requires some simple security configuration based on setup with Morgan Stanley.
Configuring the Python Client
Open the sample application below in your favourite text editor and make the following changes to the Client config.json
The client id that will be sent to you from your Morgan Stanley contact
The scope/s that will be sent to from your Morgan Stanley contact
The thumbprint that is from the public_key.cer
The path to the private_key.pem that has been created
Note You may receive a Thumbprint in the formal 12:AB:FC:12, please remove the ":" so the thumbprint would be 12ABFC12
The application is pre-configured to call the "Hello" endpoint (https://api.morganstanley.com/hello/services). Some applications may not have access to this endpoint, therefore please wait to be told what endpoint to use. This endpoint usage (configured to /hello/services) is visible in the python file client-application.py. You may change this endpoint to another of the API endpoints if you wish or if you are told to do so.
The sample code below can be copied into your IDE of choice or alternatively you can download the code here.
Running the Python Client Application
It is important to ensure that you have Python3 on your machine. To check if python is on your machine perform the following:
If the command is not recognised then you will need to install Python on your machine. This can be done by visiting https://www.python.org/downloads/ where you can follow the instructions to download and install python.
Once Python is installed you can run following to launch the application. Please refer to the docs for current best practice on creating a virtual environment https://docs.python.org/3/tutorial/venv.html:
py -m venv virtualenv
py -m pip install -r requirements.txt
py client-application.py config.json
python -m venv virtualenv
pip install -r requirements.txt
python client-application.py config.json.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.