mp-api is the official Python client for the Materials Project API, providing programmatic access to the vast Materials Project database. It features the MPRester class for easy data retrieval and is actively maintained with frequent updates to align with the evolving API and new data methodologies.
pip install mp-apiVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate the `MPRester` client using an API key from an environment variable and retrieve basic summary information for a material. You need a Materials Project API key, obtainable from your profile dashboard, to run this example.
Update your import statements and client instantiation to use `from mp_api.client import MPRester`. Ensure `mp-api` is installed and updated.
Obtain your API key from your Materials Project profile dashboard and set it as the `MP_API_KEY` environment variable or pass it directly to `MPRester("YOUR_API_KEY")`.Contact the Materials Project team if your API usage is expected to be extensive.
Keep `mp-api` and related packages (e.g., `emmet-core` if used directly) updated. Consult the official Materials Project documentation and community forums for the latest updates and known issues.
Install the package using pip: `pip install mp-api`. If using an IDE or virtual environment, ensure the correct Python interpreter where `mp-api` is installed is selected.
Obtain your API key from the new Materials Project dashboard (next-gen.materialsproject.org/api) and either pass it directly to `MPRester(api_key="YOUR_API_KEY")` or set it as an environment variable named `MP_API_KEY`.
Implement explicit checks for `None` before attempting to process results (e.g., `if result: ... else: handle_no_data()`). Ensure `mp-api` and its core dependencies like `emmet-core` are updated or compatible.
Update `mp-api` and its core dependencies (`pymatgen`, `emmet-core`, `pydantic`, `pydantic-settings`) to their latest compatible versions using `pip install --upgrade mp-api pymatgen emmet-core pydantic pydantic-settings`. If a specific dependency version is known to be problematic, consider pinning it (e.g., `pip install emmet-core==0.83.0` for older issues or `pip install 'pydantic<2'` for Pydantic v1 compatibility).
No dependency data recorded yet.