Hello all,
I’m a newbie here requesting guidance on how to import MPRester client.
I followed the instructions given here Getting Started - Materials Project Documentation, and installed the package using pip.
But how do I import the MPRester client? There’s a string of commands listed but where do I key them in? Powershell or Python 10.3 that I have installed?
Much appreciate if someone can guide me any forum threads with such topic. Thanks.
Hi @Murphy_Chan
Thank for you question! You can enter those commands in a python file, e.g. api.py
, and execute the python file by doing python api.py
. Alternatively you can enter the lines in a jupyter notebook and run the cells.
Check out this video from one of our past workshops on using the API, which gives a step-by-step tutorial.
Thanks
Ruoxi
Hello Ruoxi,
Thank you for sharing. I’m still lost.
a) I opened python IDLE, created a new .py file, entered the commands with api key and saved it as api.py in documents folder. Not sure if that’s the right path.
b) Tried to execute it using python api.py but shows attached error.
I also watched the video and Cocalc seemed easy. But I’m still having trouble setup, e.g. do I need to install api again etc. Anyway I will stick to python IDLE for now.
Hi @Murphy_Chan,
it looks like you’re trying to run the python command from within a python shell/interpreter. Try to run it from the command line (bash shell) directly.
HTH
Patrick
Hello Patrick,
Thank you. I think I get it. I modified the api.py file and tried to run an example query. But there seems to be an error,
I attached my api.py to let you see what could I missed.

Hello,
I managed to run properly with the sample.
But where do I read my output in this case?
In your example code, the API client is retrieving the data and storing it in the docs
variable. You will have to add code to either print it to the console (e.g. print(docs)
, or dump it to a file.
– Jason