mp_api.client.routes.materials.tasks.TaskRester

class mp_api.client.routes.materials.tasks.TaskRester(api_key: str | None = None, endpoint: str | None = None, include_user_agent: bool = True, session: requests.Session | None = None, s3_client: Any | None = None, debug: bool = False, monty_decode: bool = True, use_document_model: bool = True, timeout: int = 20, headers: dict | None = None, mute_progress_bars: bool = False)[source]

Bases: BaseRester[TaskDoc]

Initialize the REST API helper class.

Parameters:
  • api_key – A String API key for accessing the MaterialsProject REST interface. Please obtain your API key at https://www.materialsproject.org/dashboard. If this is None, the code will check if there is a “PMG_MAPI_KEY” setting. If so, it will use that environment variable. This makes easier for heavy users to simply add this environment variable to their setups and MPRester can then be called without any arguments.

  • endpoint – Url of endpoint to access the MaterialsProject REST interface. Defaults to the standard Materials Project REST address at “https://api.materialsproject.org”, but can be changed to other urls implementing a similar interface.

  • include_user_agent – If True, will include a user agent with the HTTP request including information on pymatgen and system version making the API request. This helps MP support pymatgen users, and is similar to what most web browsers send with each page request. Set to False to disable the user agent.

  • session – requests Session object with which to connect to the API, for advanced usage only.

  • s3_client – boto3 S3 client object with which to connect to the object stores.ct to the object stores.ct to the object stores.

  • debug – if True, print the URL for every request

  • monty_decode – Decode the data using monty into python objects

  • use_document_model – If False, skip the creating the document model and return data as a dictionary. This can be simpler to work with but bypasses data validation and will not give auto-complete for available fields.

  • timeout – Time in seconds to wait until a request timeout error is thrown

  • headers – Custom headers for localhost connections.

  • mute_progress_bars – Whether to disable progress bars.

__init__(api_key: str | None = None, endpoint: str | None = None, include_user_agent: bool = True, session: requests.Session | None = None, s3_client: Any | None = None, debug: bool = False, monty_decode: bool = True, use_document_model: bool = True, timeout: int = 20, headers: dict | None = None, mute_progress_bars: bool = False)

Initialize the REST API helper class.

Parameters:
  • api_key – A String API key for accessing the MaterialsProject REST interface. Please obtain your API key at https://www.materialsproject.org/dashboard. If this is None, the code will check if there is a “PMG_MAPI_KEY” setting. If so, it will use that environment variable. This makes easier for heavy users to simply add this environment variable to their setups and MPRester can then be called without any arguments.

  • endpoint – Url of endpoint to access the MaterialsProject REST interface. Defaults to the standard Materials Project REST address at “https://api.materialsproject.org”, but can be changed to other urls implementing a similar interface.

  • include_user_agent – If True, will include a user agent with the HTTP request including information on pymatgen and system version making the API request. This helps MP support pymatgen users, and is similar to what most web browsers send with each page request. Set to False to disable the user agent.

  • session – requests Session object with which to connect to the API, for advanced usage only.

  • s3_client – boto3 S3 client object with which to connect to the object stores.ct to the object stores.ct to the object stores.

  • debug – if True, print the URL for every request

  • monty_decode – Decode the data using monty into python objects

  • use_document_model – If False, skip the creating the document model and return data as a dictionary. This can be simpler to work with but bypasses data validation and will not give auto-complete for available fields.

  • timeout – Time in seconds to wait until a request timeout error is thrown

  • headers – Custom headers for localhost connections.

  • mute_progress_bars – Whether to disable progress bars.

Methods

__init__([api_key, endpoint, ...])

Initialize the REST API helper class.

count([criteria])

Return a count of total documents.

get_data_by_id(document_id[, fields])

get_trajectory(task_id)

Returns a Trajectory object containing the geometry of the material throughout a calculation.

search([task_ids, elements, ...])

Query core task docs using a variety of search criteria.

Attributes

available_fields

primary_key

s3_client

session

suffix

supports_versions

document_model

alias of TaskDoc

get_trajectory(task_id)[source]

Returns a Trajectory object containing the geometry of the material throughout a calculation. This is most useful for observing how a material relaxes during a geometry optimization.

Parameters:

task_id (str) – Task ID

search(task_ids: str | list[str] | None = None, elements: list[str] | None = None, exclude_elements: list[str] | None = None, formula: str | list[str] | None = None, last_updated: tuple[datetime, datetime] | None = None, num_chunks: int | None = None, chunk_size: int = 1000, all_fields: bool = True, fields: list[str] | None = None) list[TaskDoc] | list[dict][source]

Query core task docs using a variety of search criteria.

Parameters:
  • task_ids (str, List[str]) – List of Materials Project IDs to return data for.

  • elements (List[str]) – A list of elements.

  • exclude_elements (List[str]) – A list of elements to exclude.

  • formula (str, List[str]) – A formula including anonymized formula or wild cards (e.g., Fe2O3, ABO3, Si*). A list of chemical formulas can also be passed (e.g., [Fe2O3, ABO3]).

  • last_updated (tuple[datetime, datetime]) – A tuple of min and max UTC formatted datetimes.

  • num_chunks (int) – Maximum number of chunks of data to yield. None will yield all possible.

  • chunk_size (int) – Number of data entries per chunk. Max size is 100.

  • all_fields (bool) – Whether to return all fields in the document. Defaults to True.

  • fields (List[str]) – List of fields in TaskDoc to return data for. Default is material_id, last_updated, and formula_pretty if all_fields is False.

Returns:

([TaskDoc], [dict]) List of task documents or dictionaries.

count(criteria: dict | None = None) int | str

Return a count of total documents.

Parameters:

criteria (dict | None) – As in .search(). Defaults to None

Returns:

Count of total results, or string indicating error

Return type:

(int | str)