Using the Materials Project API in Python
Description
Materials Project (MP) is an open-source database for materials science researchers. It provides computational data for various inorganic materials and offers a Python-based API for convenient access. The following description refers to the official documentation; for details not included here, please consult the official documentation.
Signing up and obtaining an API Key
To use the MP API, you must sign up on the MP website. You can register using GitHub, Gmail, or another email address. You can view your API Key on the API tab at the top-right corner of the website.

Installation
You can install via pip or by downloading from GitHub.
# using pip
pip install mp_api
# from github
git clone https://github.com/materialsproject/api
cd api
pip install -e .
Usage
In Python, import the MPRester client to access the desired functionality. Use of the with statement is recommended.
from mp_api.client import MPRester
# Option 1: Pass your API key directly as an argument.
with MPRester("your_api_key_here") as mpr:
# do stuff with mpr...
# Option 2: Use the `MP_API_KEY` environment variable:
# export MP_API_KEY="your_api_key_here"
# Note: You can also configure your API key through pymatgen
with MPRester() as mpr:
# do stuff with mpr ...
