{"id":6005,"library":"mp-api","title":"Materials Project API Client","description":"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.","status":"active","version":"0.46.0","language":"en","source_language":"en","source_url":"https://github.com/materialsproject/api","tags":["materials science","api client","materials project","chemistry","physics","data"],"install":[{"cmd":"pip install mp-api","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The `mp-api` client replaces the legacy MPRester previously found in `pymatgen`. Users should migrate to the new import path for current functionality.","wrong":"from pymatgen.matproj.rest import MPRester","symbol":"MPRester","correct":"from mp_api.client import MPRester"}],"quickstart":{"code":"import os\nfrom mp_api.client import MPRester\n\n# Set your Materials Project API key as an environment variable\n# Example: export MP_API_KEY=\"YOUR_API_KEY_HERE\"\n# You can find your API key on your Materials Project profile dashboard.\n\napi_key = os.environ.get('MP_API_KEY', '')\n\nif not api_key:\n    print(\"Error: MP_API_KEY environment variable not set. Please set it to your Materials Project API key.\")\nelse:\n    try:\n        with MPRester(api_key) as mpr:\n            # Fetch summary data for silicon (material_id: mp-149)\n            material_id = \"mp-149\"\n            docs = mpr.materials.summary.search(material_ids=[material_id])\n            if docs:\n                print(f\"Material ID: {docs[0].material_id}\")\n                print(f\"Formula: {docs[0].formula_pretty}\")\n                print(f\"Band gap: {docs[0].band_gap} eV\")\n            else:\n                print(f\"No data found for material ID: {material_id}\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update your import statements and client instantiation to use `from mp_api.client import MPRester`. Ensure `mp-api` is installed and updated.","message":"The `mp-api` library is the successor to the legacy `MPRester` client previously embedded in `pymatgen`. Users of the old `pymatgen.matproj.rest.MPRester` should migrate to `from mp_api.client import MPRester` to access the latest API features and maintain compatibility.","severity":"breaking","affected_versions":"<0.30.5 (for `mp-api` integration requirements with `mpcontribs-client`), N/A (for `pymatgen`'s legacy API)"},{"fix":"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\")`.","message":"An API key is mandatory for using the Materials Project API client. Failing to provide a valid key, either as a direct argument to `MPRester` or via the `MP_API_KEY` environment variable, will result in authentication errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Contact the Materials Project team if your API usage is expected to be extensive.","message":"For heavy or high-volume API usage, it is recommended to notify the Materials Project team by emailing `heavy.api.use@materialsproject.org`. This helps them anticipate server load and can prevent potential rate-limiting or service interruptions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"The Materials Project API and its underlying data models (`emmet-core`) are continuously evolving. While the `mp-api` client is designed to abstract away many changes, occasional discrepancies or unexpected behavior can arise, especially if comparing with direct REST API calls or when using older versions of related data model libraries.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}