iemap_mi package

iemap_mi.iemap_mi module

class iemap_mi.iemap_mi.IemapMI[source]

Bases: object

IemapMI is a class designed to interact with the Iemap Management Interface (IEMI) API. It provides functionalities to authenticate users, handle projects, and gather statistical data.

token

JWT token for authenticated API access. Initially None until authentication.

Type:

Optional[str]

project_handler

Handles project-related operations.

Type:

ProjectHandler

stat_handler

Handles statistical data operations.

Type:

IemapStat

__init__()[source]

Initializes the IemapMI instance with default values.

authenticate()[source]

Authenticates a user with the IEMI API and stores the JWT token.

handle_exception()[source]

Static method to handle exceptions in asyncio event loops.

print_version()[source]

Static method to print the version of the IemapMI module.

async authenticate(username, password)[source]

Authenticate the user and obtain a JWT token.

Parameters:
  • username (str) – Username for authentication.

  • password (str) – Password for authentication.

Return type:

None

static handle_exception(loop, context)[source]

Handle exceptions in asyncio.

Parameters:
  • loop (asyncio.AbstractEventLoop) – The event loop.

  • context (Dict[str, Any]) – The exception context.

Return type:

None

static print_version()[source]

Print the version of the IemapMI module.

Return type:

None

iemap_mi.iemap_stat module

class iemap_mi.iemap_stat.IemapStat(token=None)[source]

Bases: object

async get_stats()[source]

Get statistics from the API.

Returns:

Response containing statistics data.

Return type:

StatsResponse

iemap_mi.models module

class iemap_mi.models.AffiliationCount(**data)[source]

Bases: BaseModel

Represents the count of affiliations.

affiliation

The name of the affiliation.

Type:

str

n

The number of projects/files for the affiliation.

Type:

int

affiliation: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

n: int
class iemap_mi.models.Agent(**data)[source]

Bases: BaseModel

Represents the agent used in the process.

name

The name of the agent.

Type:

str

version

The version of the agent.

Type:

Optional[str]

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
version: Optional[str]
class iemap_mi.models.AgentModel(**data)[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
version: Optional[str]
class iemap_mi.models.AuthData(**data)[source]

Bases: BaseModel

Represents the authentication data.

username

The username for authentication.

Type:

str

password

The password for authentication.

Type:

str

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

password: Annotated[str]
username: Annotated[str]
class iemap_mi.models.CreateProjectResponse(**data)[source]

Bases: BaseModel

Represents the response after creating a new project.

inserted_id

The ID of the newly inserted project document.

Type:

str

inserted_id: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class iemap_mi.models.FileInfo(**data)[source]

Bases: BaseModel

file_hash: str
file_name: str
file_size: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

uploaded: bool
class iemap_mi.models.FileModel(**data)[source]

Bases: BaseModel

createdAt: datetime
extention: str
hash: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
size: Union[str, float]
updatedAt: datetime
class iemap_mi.models.FlattenedProjectBase(**data)[source]

Bases: BaseModel

identifier: Optional[str]
iemap_id: str
material: MaterialModel
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parameters: List[Dict[str, Any]]
process: Process
project: ProjectBase
properties: List[Dict[str, Any]]
provenance: Provenance
class iemap_mi.models.FlattenedProjectHashEmail(**data)[source]

Bases: FlattenedProjectBase

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

provenance: ProvenanceHashEmail
class iemap_mi.models.IEMAPProject(**data)[source]

Bases: BaseModel

Represents the request data to create a new project.

project

The project details.

Type:

Project

material

The material details.

Type:

Material

process

The process details.

Type:

Process

parameters

List of parameters used in the project.

Type:

List[Parameter]

properties

List of properties of the project.

Type:

List[Property]

material: Material
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parameters: List[Parameter]
process: Process
project: Project
properties: List[Property]
class iemap_mi.models.Input(**data)[source]

Bases: BaseModel

cell: List[List[float]]
lattice: Lattice
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sites: List[List[float]]
species: List[str]
class iemap_mi.models.Lattice(**data)[source]

Bases: BaseModel

a: str
alpha: str
b: str
beta: str
c: str
gamma: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class iemap_mi.models.Material(**data)[source]

Bases: BaseModel

Represents the material used in the project.

formula

The chemical formula of the material.

Type:

str

formula: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class iemap_mi.models.MaterialModel(**data)[source]

Bases: BaseModel

elements: List[str]
formula: str
input: Optional[Input]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

output: Optional[Output]
class iemap_mi.models.Output(**data)[source]

Bases: BaseModel

cell: List[List[float]]
lattice: Lattice
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

sites: List[List[float]]
species: List[str]
class iemap_mi.models.Parameter(**data)[source]

Bases: BaseModel

Represents a parameter used in the project.

name

The name of the parameter.

Type:

str

value

The value of the parameter.

Type:

float

unit

The unit of the parameter.

Type:

str

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
unit: str
value: float
class iemap_mi.models.ParameterModel(**data)[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
unit: Optional[str]
value: Any
class iemap_mi.models.Process(**data)[source]

Bases: BaseModel

Represents the process used in the project.

method

The method used in the process.

Type:

str

agent

The agent used in the process.

Type:

Agent

isExperiment

Indicates if the process is an experiment.

Type:

bool

agent: Agent
isExperiment: bool
method: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class iemap_mi.models.ProcessModel(**data)[source]

Bases: BaseModel

agent: AgentModel
isExperiment: bool
method: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class iemap_mi.models.Project(**data)[source]

Bases: BaseModel

Represents a project.

name

The name of the project.

Type:

str

label

The label of the project.

Type:

str

description

The description of the project.

Type:

str

description: str
label: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class iemap_mi.models.ProjectBase(**data)[source]

Bases: BaseModel

description: Optional[str]
label: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class iemap_mi.models.ProjectModel(**data)[source]

Bases: BaseModel

description: str
label: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
class iemap_mi.models.ProjectQueryModel(**data)[source]

Bases: BaseModel

files: List[FileModel]
iemap_id: str
material: MaterialModel
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

parameters: List[ParameterModel]
process: ProcessModel
project: ProjectModel
properties: List[PropertyModel]
provenance: ProvenanceQueryModel
class iemap_mi.models.ProjectResponse(**data)[source]

Bases: BaseModel

Represents the response from the project list endpoint.

skip

Number of documents to skip.

Type:

int

page_size

Number of results to return in a single page.

Type:

int

page_number

Actual page number returned.

Type:

int

page_tot

Total number of pages available.

Type:

int

number_docs

Total number of documents in collection.

Type:

int

data

List of all projects saved in the database.

Type:

List[Any]

data: List[Any]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

number_docs: int
page_number: int
page_size: int
page_tot: int
skip: int
class iemap_mi.models.Property(**data)[source]

Bases: BaseModel

Represents a property of the project.

name

The name of the property.

Type:

str

value

The value of the property.

Type:

str

unit

The unit of the property.

Type:

str

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
unit: str
value: str
class iemap_mi.models.PropertyModel(**data)[source]

Bases: BaseModel

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
unit: Optional[str]
value: Any
class iemap_mi.models.Provenance(**data)[source]

Bases: BaseModel

affiliation: str
createdAt: Optional[datetime]
email: EmailStr
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

updatedAt: Optional[datetime]
class iemap_mi.models.ProvenanceHashEmail(**data)[source]

Bases: BaseModel

affiliation: str
createdAt: Optional[datetime]
email: str
classmethod hash_email_field(value)[source]

Automatically hash the email field.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

updatedAt: Optional[datetime]
class iemap_mi.models.ProvenanceQueryModel(**data)[source]

Bases: BaseModel

affiliation: str
createdAt: datetime
email: str
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

updatedAt: datetime
class iemap_mi.models.StatsData(**data)[source]

Bases: BaseModel

Represents the statistics data.

totalProj

Total number of projects.

Type:

int

totalUsers

Total number of users.

Type:

int

countProj

List of project counts by affiliation.

Type:

List[AffiliationCount]

countFiles

List of file counts by affiliation.

Type:

List[AffiliationCount]

totalUsersRegistered

Total number of registered users.

Type:

int

countFiles: List[AffiliationCount]
countProj: List[AffiliationCount]
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

totalProj: int
totalUsers: int
totalUsersRegistered: int
class iemap_mi.models.StatsResponse(**data)[source]

Bases: BaseModel

Represents the response from the statistics endpoint.

data

The statistics data.

Type:

StatsData

data: StatsData
model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

iemap_mi.project_handler module

class iemap_mi.project_handler.ProjectHandler(token=None)[source]

Bases: object

async add_file_to_project(project_id, file_path, file_name=None)[source]

Add a file to a project.

Parameters:
  • project_id (str) – The ID of the project to add the file to.

  • file_path (str) – The path to the file to be uploaded.

  • file_name (Optional[str]) – The name of the file. Defaults to None.

Returns:

Response from the API.

Return type:

Dict[str, Any]

static build_project_payload(data)[source]

Build and validate a JSON payload for the “/api/v1/project/add” endpoint.

This method constructs a JSON payload for creating a new project, applies Pydantic validation, and provides easy-to-read error messages in case of validation failures.

Parameters:

data (Dict[str, Any]) – A dictionary containing the project details.

Returns:

A validated dictionary representation of the project payload.

Returns an empty dictionary if validation fails.

Return type:

Dict[str, Any]

Raises:

ValidationError – If the provided data is not valid according to the Pydantic model.

Example

>>> data = {
...     "project": {
...         "name": "Materials for Batteries",
...         "label": "MB",
...         "description": "IEMAP - eco-sustainable synthesis of ionic liquids as innovative solvents for lithium/sodium batteries"
...     },
...     "material": {
...         "formula": "C11H20N2F6S2O4"
...     },
...     "process": {
...         "method": "Karl-Fischer titration",
...         "agent": {
...             "name": "Karl-Fischer titrator Mettler Toledo",
...             "version": None
...         },
...         "isExperiment": True
...     },
...     "parameters": [
...         {
...             "name": "time",
...             "value": 20,
...             "unit": "s"
...         },
...         {
...             "name": "weight",
...             "value": 0.5,
...             "unit": "gr"
...         }
...     ],
...     "properties": [
...         {
...             "name": "Moisture content",
...             "value": "<2",
...             "unit": "ppm"
...         }
...     ]
... }
>>> valid_payload = ProjectHandler.build_project_payload(data)
>>> if valid_payload:
...     print("Payload is valid and ready to be submitted.")
... else:
...     print("Payload is invalid.")
async create_project(project_data)[source]

Create a new project.

Parameters:

project_data (IEMAPProject) – Data for the new project.

Returns:

Response containing the inserted ID of the new project.

Return type:

CreateProjectResponse

async get_projects(page_size=10, page_number=1)[source]

Get paginated list of projects.

Parameters:
  • page_size (int) – Number of results to return in a single page. Defaults to 10.

  • page_number (int) – Actual page number returned. Defaults to 1.

Returns:

Paginated list of projects.

Return type:

ProjectResponse

async static query_projects(response_model=None, id=None, fields_output='all', affiliation=None, project_name=None, provenance_email=None, material_formula=None, material_all_elements=None, material_any_element=None, iemap_id=None, isExperiment=None, simulationCode=None, experimentInstrument=None, simulationMethod=None, experimentMethod=None, parameterName=None, parameterValue=None, propertyName=None, propertyValue=None, fields=None, limit=100, skip=0, sort=None, start_date=None, end_date=None)[source]

Query projects with specified parameters. This method is a static method and does not require an instance of the class to be called. No authentication is required to call this method.

Parameters:
  • response_model (Optional[str]) – Response model.

  • id (Optional[str]) – Project ID.

  • fields_output (Optional[str]) – Fields to output. Defaults to ‘all’.

  • affiliation (Optional[str]) – Affiliation.

  • project_name (Optional[str]) – Project name.

  • provenance_email (Optional[str]) – Provenance email.

  • material_formula (Optional[str]) – Material formula.

  • material_all_elements (Optional[str]) – All elements in material.

  • material_any_element (Optional[str]) – Any element in material.

  • iemap_id (Optional[str]) – IEMAP ID.

  • isExperiment (Optional[bool]) – Is experiment.

  • simulationCode (Optional[str]) – Simulation code.

  • experimentInstrument (Optional[str]) – Experiment instrument.

  • simulationMethod (Optional[str]) – Simulation method.

  • experimentMethod (Optional[str]) – Experiment method.

  • parameterName (Optional[str]) – Parameter name.

  • parameterValue (Optional[str]) – Parameter value.

  • propertyName (Optional[str]) – Property name.

  • propertyValue (Optional[str]) – Property value.

  • fields (Optional[str]) – Fields.

  • limit (int) – Limit. Defaults to 100.

  • skip (int) – Skip. Defaults to 0.

  • sort (Optional[str]) – Sort.

  • start_date (Optional[str]) – Start date.

  • end_date (Optional[str]) – End date.

Returns:

Query response.

Return type:

ProjectQueryResponse

iemap_mi.settings module

class iemap_mi.settings.APISettings[source]

Bases: object

ADD_FILE_TO_PROJECT = 'https://iemap.enea.it/rest/api/v1/project/add/file/'
AI_GEOCGNN = 'https://iemap.enea.it/ai/'
AUTH_JWT_LOGIN = 'https://iemap.enea.it/rest/auth/jwt/login'
BASE_URL = 'https://iemap.enea.it/rest'
PROJECT_ADD = 'https://iemap.enea.it/rest/api/v1/project/add'
PROJECT_LIST = 'https://iemap.enea.it/rest/api/v1/project/list/'
PROJECT_QUERY = 'https://iemap.enea.it/rest/api/v1/project/query/'
STATS = 'https://iemap.enea.it/rest/api/v1/stats'

iemap_mi.utils module

iemap_mi.utils.flatten_project_data(project)[source]

Flatten the project data for better compatibility with pandas DataFrame.

Return type:

Dict[str, Any]

iemap_mi.utils.get_headers(token)[source]

Generate headers for HTTP requests.

Parameters:

token (Optional[str]) – JWT token for authentication.

Returns:

Headers for HTTP requests.

Return type:

Dict[str, str]

Module contents