New API vs Legacy API

Dear Members,

I am using new API to access data.

Code to access data is:

Search result with new API [ ] is :

How to get search result in the following format?(this was from leagcy API [mpr.query() ] )


Dear @Jameer

The results from the new API are MPDataDoc objects rather than dict objects that the old API would return. MPDataDoc objects can be converted to dict objects using the MPDataDoc.dict() method.

So for your example, we can do the following:

from mp_api.client import MPRester
from emmet.core.summary import HasProps
import pandas as pd

with MPRester(API_KEY) as mpr:
    docs =[HasProps.dielectric], fields =["material_id","band_gap", "structure"])

# Convert docs to dict
docs_dict = [doc.dict(exclude={"fields_not_requested"}) for doc in docs]

# Put in a dataframe
df = pd.DataFrame(docs_dict)

Let me know if this solves your problem.

  • Anthony

Dear Anthony

It is working. Thanks a lot

1 Like

Thanks @AntObi!

1 Like