Module signals_notebook.common_types
Expand source code
import logging
import mimetypes
import os
import re
from base64 import b64encode
from datetime import datetime
from enum import Enum
from typing import Any, Generic, List, Optional, TypeVar, Union
from uuid import UUID
from dateutil.parser import parse
from pydantic import BaseModel, Field, HttpUrl, validator
from pydantic.generics import GenericModel
from signals_notebook.exceptions import EIDError
EntityClass = TypeVar('EntityClass')
AnyModel = TypeVar('AnyModel')
log = logging.getLogger(__name__)
class ChemicalDrawingFormat(str, Enum):
CDXML = 'cdxml'
SVG = 'svg'
MOL = 'mol'
MOL3000 = 'mol-v3000'
SMILES = 'smiles'
class ObjectType(str, Enum):
ENTITY = 'entity'
ADT_ROW = 'adtRow'
COLUMN_DEFINITIONS = 'columnDefinitions'
MATERIAL = 'material'
ASSET_TYPE = 'assetType'
ATTRIBUTE = 'attribute'
STOICHIOMETRY = 'stoichiometry'
PROPERTY = 'property'
USER = 'user'
PROFILE = 'profile'
GROUP = 'group'
ROLE = 'role'
PLATE_ROW = 'plateRow'
ATTRIBUTE_OPTION = 'option'
CHOICE = 'choice'
SUB_EXPERIMENT = 'subexpSummaryRow'
CONTAINER = 'container'
REACTION_PRODUCT = 'reactionProduct'
REACTION_REACTANT = 'reactionReactant'
REACTION_REAGENT = 'reactionReagent'
class EntityType(str, Enum):
NOTEBOOK = 'journal'
EXPERIMENT = 'experiment'
TEXT = 'text'
CHEMICAL_DRAWING = 'chemicalDrawing'
GRID = 'grid'
ASSET = 'asset'
BIO_SEQUENCE = 'bioSequence'
UPLOADED_RESOURCE = 'uploadedResource'
IMAGE_RESOURCE = 'imageResource'
WORD = 'viewonly'
EXCEL = 'excel'
SAMPLE = 'sample'
SAMPLES_CONTAINER = 'samplesContainer'
POWER_POINT = 'presentation'
SPOTFIRE = 'spotfiredxp'
TODO_LIST = 'linkedTaskContainer'
TASK = 'task'
PLATE_CONTAINER = 'plateContainer'
MATERIAL_TABLE = 'materialsTable'
PARALLEL_EXPERIMENT = 'paraexp'
SUB_EXPERIMENT = 'parasubexp'
SUB_EXPERIMENT_SUMMARY = 'paragrid'
SUB_EXPERIMENT_LAYOUT = 'paraLayout'
ADO = 'ado'
REQUEST = 'request'
TASK_CONTAINER = 'taskContainer'
class MaterialType(str, Enum):
LIBRARY = 'assetType'
ASSET = 'asset'
BATCH = 'batch'
class EID(str):
"""Entity ID"""
def __new__(cls, content: Any, validate: bool = True):
if validate:
cls.validate(content)
return str.__new__(cls, content)
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v: Any):
"""Validate Entity ID
Args:
v: Entity ID
Returns:
"""
if not isinstance(v, str):
log.error('%s is not instance of str', v)
raise EIDError(value=v)
try:
_type, _id, *_ = v.split(':')
UUID(_id)
except ValueError:
log.exception('Cannot get id and type from value')
raise EIDError(value=v)
return cls(v, validate=False)
@property
def type(self) -> Union[EntityType, str]:
"""Get entity type
Returns:
One of the entity types
"""
_type, _id, *_ = self.split(':')
try:
return EntityType(_type)
except ValueError:
log.exception('Cannot get type: %s. There is no the same type in program', _type)
return _type
@property
def id(self) -> UUID:
"""Get UUID
Returns:
UUID
"""
_type, _id, *_ = self.split(':')
return UUID(_id)
class MID(str):
"""Material ID"""
_id_pattern = re.compile('[0-9a-f]+', flags=re.IGNORECASE)
def __new__(cls, content: Any, validate: bool = True):
if validate:
cls.validate(content)
return str.__new__(cls, content)
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v: Any):
"""Validate Material ID
Args:
v: Material ID
Returns:
"""
if not isinstance(v, str):
log.error('%s is not instance of str', v)
raise EIDError(value=v)
try:
_type, _id = v.split(':')
MaterialType(_type)
except ValueError:
log.exception('Cannot get id and type from value')
raise EIDError(value=v)
if not cls._id_pattern.fullmatch(_id):
log.error('ID: %s is not the same with %s pattern', _id, cls._id_pattern)
raise EIDError(value=v)
return cls(v, validate=False)
@property
def type(self) -> MaterialType:
"""Get one of the material types
Returns:
MaterialType
"""
_type, _ = self.split(':')
return MaterialType(_type)
@property
def id(self) -> str:
"""Get id of material type
Returns:
str id
"""
_, _id = self.split(':')
return _id
class AttrID(str):
"""Attribute ID"""
def __new__(cls, content: Any, validate: bool = True):
if validate:
cls.validate(content)
return str.__new__(cls, content)
@classmethod
def __get_validators__(cls):
yield cls.validate
@classmethod
def validate(cls, v: Any):
"""Validate Attribute ID
Args:
v: Attribute ID
Returns:
"""
if not isinstance(v, str):
log.error('%s is not instance of str', v)
raise EIDError(value=v)
try:
_type, _id = v.split(':')
int(_id)
except ValueError:
log.exception('Cannot get id and type from value')
raise EIDError(value=v)
if _type != ObjectType.ATTRIBUTE:
log.error('Type: %s is not the same with %s', _type, ObjectType.ATTRIBUTE)
raise EIDError(value=v)
return cls(v, validate=False)
@property
def type(self) -> ObjectType:
"""Get one of the object types
Returns:
ObjectType
"""
_type, _ = self.split(':')
return ObjectType(_type)
@property
def id(self) -> int:
"""Get id of object type
Returns:
int id
"""
_, _id = self.split(':')
return int(_id)
class Links(BaseModel):
self: HttpUrl
first: Optional[HttpUrl] = None
next: Optional[HttpUrl] = None
prev: Optional[HttpUrl] = None
@validator('*', pre=True)
def escape_spaces(cls, v: Optional[str]) -> Optional[str]:
"""Replace all spaces
Args:
v: value
Returns:
value with replaced spaces
"""
if v is not None:
return v.replace(' ', '%20')
return v
class ResponseData(GenericModel, Generic[EntityClass]):
type: ObjectType
eid: Union[EID, MID, AttrID, UUID, str] = Field(alias='id')
links: Optional[Links] = None
body: EntityClass = Field(alias='attributes')
relationships: Optional[dict[str, Any]] = Field(default=None)
meta: Optional[dict[str, Any]] = Field(default=None)
def __init__(self, _context: dict[str, Any] = None, **kwargs):
attributes = kwargs.get('attributes', {})
if _context:
attributes = {**attributes, **_context}
super().__init__(**{**kwargs, 'attributes': attributes})
class Response(GenericModel, Generic[EntityClass]):
links: Optional[Links] = None
data: Union[ResponseData[EntityClass], List[ResponseData[EntityClass]]]
def __init__(self, _context: dict[str, Any] = None, **kwargs):
data = kwargs.get('data', {})
if _context:
if isinstance(data, list):
data = [{'_context': _context, **item} for item in data]
else:
data = {'_context': _context, **data}
super().__init__(**{**kwargs, 'data': data})
class DataObject(GenericModel, Generic[AnyModel]):
data: AnyModel
class DataList(GenericModel, Generic[AnyModel]):
data: List[AnyModel]
class EntityCreationRequestPayload(DataObject[AnyModel], Generic[AnyModel]):
pass
class EntityShortDescription(BaseModel):
type: Union[EntityType, str]
id: EID
class Template(DataObject[EntityShortDescription]):
pass
class Ancestors(DataList[EntityShortDescription]):
pass
class File(BaseModel):
name: str
content: bytes
content_type: str
def __init__(self, f=None, **kwargs):
if f:
name = os.path.basename(f.name)
content = f.read()
content_type, _ = mimetypes.guess_type(name)
super().__init__(name=name, content=content, content_type=content_type)
else:
super().__init__(**kwargs)
@property
def size(self) -> int:
"""Get file size
Returns:
file size
"""
return len(self.content)
@property
def base64(self) -> bytes:
return b64encode(self.content)
@classmethod
def read(cls, file_name: str, mode='rb') -> 'File':
"""Read content of the file
Args:
file_name: file name in string format
mode: specifies the mode in which the file is opened
Returns:
File
"""
with open(file_name, mode) as f:
return cls(f)
def save(self, path: str) -> None:
"""Save content in file
Args:
path: path to the file
Returns:
"""
_path = path
if os.path.isdir(path):
_path = os.path.join(path, self.name)
with open(_path, 'wb') as f:
f.write(self.content)
class DateTime(datetime):
@classmethod
def __get_validators__(cls):
yield cls._validate_date
@staticmethod
def _validate_date(value: Union[str, datetime]) -> datetime:
if isinstance(value, datetime):
return value
return parse(value)
Classes
class Ancestors (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Ancestors(DataList[EntityShortDescription]): pass
Ancestors
- DataList[EntityShortDescription]
- DataList
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Class variables
var data : List[EntityShortDescription]
class AttrID (content: Any, validate: bool = True)
-
Attribute ID
Expand source code
class AttrID(str): """Attribute ID""" def __new__(cls, content: Any, validate: bool = True): if validate: cls.validate(content) return str.__new__(cls, content) @classmethod def __get_validators__(cls): yield cls.validate @classmethod def validate(cls, v: Any): """Validate Attribute ID Args: v: Attribute ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id = v.split(':') int(_id) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) if _type != ObjectType.ATTRIBUTE: log.error('Type: %s is not the same with %s', _type, ObjectType.ATTRIBUTE) raise EIDError(value=v) return cls(v, validate=False) @property def type(self) -> ObjectType: """Get one of the object types Returns: ObjectType """ _type, _ = self.split(':') return ObjectType(_type) @property def id(self) -> int: """Get id of object type Returns: int id """ _, _id = self.split(':') return int(_id)
Ancestors
- builtins.str
Static methods
def validate(v: Any)
-
Validate Attribute ID
Args
v
- Attribute ID
Returns:
Expand source code
@classmethod def validate(cls, v: Any): """Validate Attribute ID Args: v: Attribute ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id = v.split(':') int(_id) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) if _type != ObjectType.ATTRIBUTE: log.error('Type: %s is not the same with %s', _type, ObjectType.ATTRIBUTE) raise EIDError(value=v) return cls(v, validate=False)
Instance variables
var id : int
-
Get id of object type
Returns
int id
Expand source code
@property def id(self) -> int: """Get id of object type Returns: int id """ _, _id = self.split(':') return int(_id)
var type : ObjectType
-
Get one of the object types
Returns
ObjectType
Expand source code
@property def type(self) -> ObjectType: """Get one of the object types Returns: ObjectType """ _type, _ = self.split(':') return ObjectType(_type)
class ChemicalDrawingFormat (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class ChemicalDrawingFormat(str, Enum): CDXML = 'cdxml' SVG = 'svg' MOL = 'mol' MOL3000 = 'mol-v3000' SMILES = 'smiles'
Ancestors
- builtins.str
- enum.Enum
Class variables
var CDXML
var MOL
var MOL3000
var SMILES
var SVG
class DataList (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class DataList(GenericModel, Generic[AnyModel]): data: List[AnyModel]
Ancestors
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
Class variables
var data : List[~AnyModel]
class DataList[EntityShortDescription] (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Ancestors
- DataList
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
Class variables
var Config
var data : List[EntityShortDescription]
class DataObject (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class DataObject(GenericModel, Generic[AnyModel]): data: AnyModel
Ancestors
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
- pydantic.generics.DataObject[_RequestBody]
- pydantic.generics.DataObject[_RequestBody]
- pydantic.generics.DataObject[_RequestBody]
- pydantic.generics.DataObject[_RequestBody]
- pydantic.generics.DataObject[_RequestBody]
- pydantic.generics.DataObject[_SampleRequestBody]
- pydantic.generics.DataObject[_SubExperimentRequestBody]
- DataObject[EntityShortDescription]
- EntityCreationRequestPayload
Class variables
var data : ~AnyModel
class DataObject[EntityShortDescription] (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Ancestors
- DataObject
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
Class variables
var Config
var data : EntityShortDescription
class DateTime (...)
-
datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]])
The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.
Expand source code
class DateTime(datetime): @classmethod def __get_validators__(cls): yield cls._validate_date @staticmethod def _validate_date(value: Union[str, datetime]) -> datetime: if isinstance(value, datetime): return value return parse(value)
Ancestors
- datetime.datetime
- datetime.date
class EID (content: Any, validate: bool = True)
-
Entity ID
Expand source code
class EID(str): """Entity ID""" def __new__(cls, content: Any, validate: bool = True): if validate: cls.validate(content) return str.__new__(cls, content) @classmethod def __get_validators__(cls): yield cls.validate @classmethod def validate(cls, v: Any): """Validate Entity ID Args: v: Entity ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id, *_ = v.split(':') UUID(_id) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) return cls(v, validate=False) @property def type(self) -> Union[EntityType, str]: """Get entity type Returns: One of the entity types """ _type, _id, *_ = self.split(':') try: return EntityType(_type) except ValueError: log.exception('Cannot get type: %s. There is no the same type in program', _type) return _type @property def id(self) -> UUID: """Get UUID Returns: UUID """ _type, _id, *_ = self.split(':') return UUID(_id)
Ancestors
- builtins.str
Static methods
def validate(v: Any)
-
Validate Entity ID
Args
v
- Entity ID
Returns:
Expand source code
@classmethod def validate(cls, v: Any): """Validate Entity ID Args: v: Entity ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id, *_ = v.split(':') UUID(_id) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) return cls(v, validate=False)
Instance variables
var id : uuid.UUID
-
Get UUID
Returns
UUID
Expand source code
@property def id(self) -> UUID: """Get UUID Returns: UUID """ _type, _id, *_ = self.split(':') return UUID(_id)
var type : Union[EntityType, str]
-
Get entity type
Returns
One of the entity types
Expand source code
@property def type(self) -> Union[EntityType, str]: """Get entity type Returns: One of the entity types """ _type, _id, *_ = self.split(':') try: return EntityType(_type) except ValueError: log.exception('Cannot get type: %s. There is no the same type in program', _type) return _type
class EntityCreationRequestPayload (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class EntityCreationRequestPayload(DataObject[AnyModel], Generic[AnyModel]): pass
Ancestors
- DataObject
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
- EntityCreationRequestPayload[_RequestBody]
- EntityCreationRequestPayload[_RequestBody]
- EntityCreationRequestPayload[_RequestBody]
- EntityCreationRequestPayload[_RequestBody]
- EntityCreationRequestPayload[_SubExperimentRequestBody]
- EntityCreationRequestPayload[_RequestBody]
- EntityCreationRequestPayload[_SampleRequestBody]
Class variables
var data : ~AnyModel
class EntityShortDescription (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class EntityShortDescription(BaseModel): type: Union[EntityType, str] id: EID
Ancestors
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var id : EID
var type : Union[EntityType, str]
class EntityType (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class EntityType(str, Enum): NOTEBOOK = 'journal' EXPERIMENT = 'experiment' TEXT = 'text' CHEMICAL_DRAWING = 'chemicalDrawing' GRID = 'grid' ASSET = 'asset' BIO_SEQUENCE = 'bioSequence' UPLOADED_RESOURCE = 'uploadedResource' IMAGE_RESOURCE = 'imageResource' WORD = 'viewonly' EXCEL = 'excel' SAMPLE = 'sample' SAMPLES_CONTAINER = 'samplesContainer' POWER_POINT = 'presentation' SPOTFIRE = 'spotfiredxp' TODO_LIST = 'linkedTaskContainer' TASK = 'task' PLATE_CONTAINER = 'plateContainer' MATERIAL_TABLE = 'materialsTable' PARALLEL_EXPERIMENT = 'paraexp' SUB_EXPERIMENT = 'parasubexp' SUB_EXPERIMENT_SUMMARY = 'paragrid' SUB_EXPERIMENT_LAYOUT = 'paraLayout' ADO = 'ado' REQUEST = 'request' TASK_CONTAINER = 'taskContainer'
Ancestors
- builtins.str
- enum.Enum
Class variables
var ADO
var ASSET
var BIO_SEQUENCE
var CHEMICAL_DRAWING
var EXCEL
var EXPERIMENT
var GRID
var IMAGE_RESOURCE
var MATERIAL_TABLE
var NOTEBOOK
var PARALLEL_EXPERIMENT
var PLATE_CONTAINER
var POWER_POINT
var REQUEST
var SAMPLE
var SAMPLES_CONTAINER
var SPOTFIRE
var SUB_EXPERIMENT
var SUB_EXPERIMENT_LAYOUT
var SUB_EXPERIMENT_SUMMARY
var TASK
var TASK_CONTAINER
var TEXT
var TODO_LIST
var UPLOADED_RESOURCE
var WORD
class File (f=None, **kwargs)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class File(BaseModel): name: str content: bytes content_type: str def __init__(self, f=None, **kwargs): if f: name = os.path.basename(f.name) content = f.read() content_type, _ = mimetypes.guess_type(name) super().__init__(name=name, content=content, content_type=content_type) else: super().__init__(**kwargs) @property def size(self) -> int: """Get file size Returns: file size """ return len(self.content) @property def base64(self) -> bytes: return b64encode(self.content) @classmethod def read(cls, file_name: str, mode='rb') -> 'File': """Read content of the file Args: file_name: file name in string format mode: specifies the mode in which the file is opened Returns: File """ with open(file_name, mode) as f: return cls(f) def save(self, path: str) -> None: """Save content in file Args: path: path to the file Returns: """ _path = path if os.path.isdir(path): _path = os.path.join(path, self.name) with open(_path, 'wb') as f: f.write(self.content)
Ancestors
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var content : bytes
var content_type : str
var name : str
Static methods
def read(file_name: str, mode='rb') ‑> File
-
Read content of the file
Args
file_name
- file name in string format
mode
- specifies the mode in which the file is opened
Returns
File
Expand source code
@classmethod def read(cls, file_name: str, mode='rb') -> 'File': """Read content of the file Args: file_name: file name in string format mode: specifies the mode in which the file is opened Returns: File """ with open(file_name, mode) as f: return cls(f)
Instance variables
var base64 : bytes
-
Expand source code
@property def base64(self) -> bytes: return b64encode(self.content)
var size : int
-
Get file size
Returns
file size
Expand source code
@property def size(self) -> int: """Get file size Returns: file size """ return len(self.content)
Methods
def save(self, path: str) ‑> None
-
Save content in file
Args
path
- path to the file
Returns:
Expand source code
def save(self, path: str) -> None: """Save content in file Args: path: path to the file Returns: """ _path = path if os.path.isdir(path): _path = os.path.join(path, self.name) with open(_path, 'wb') as f: f.write(self.content)
class Links (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Links(BaseModel): self: HttpUrl first: Optional[HttpUrl] = None next: Optional[HttpUrl] = None prev: Optional[HttpUrl] = None @validator('*', pre=True) def escape_spaces(cls, v: Optional[str]) -> Optional[str]: """Replace all spaces Args: v: value Returns: value with replaced spaces """ if v is not None: return v.replace(' ', '%20') return v
Ancestors
- pydantic.main.BaseModel
- pydantic.utils.Representation
Class variables
var first : Optional[pydantic.networks.HttpUrl]
var next : Optional[pydantic.networks.HttpUrl]
var prev : Optional[pydantic.networks.HttpUrl]
var self : pydantic.networks.HttpUrl
Static methods
def escape_spaces(v: Optional[str]) ‑> Optional[str]
-
Replace all spaces
Args
v
- value
Returns
value with replaced spaces
Expand source code
@validator('*', pre=True) def escape_spaces(cls, v: Optional[str]) -> Optional[str]: """Replace all spaces Args: v: value Returns: value with replaced spaces """ if v is not None: return v.replace(' ', '%20') return v
class MID (content: Any, validate: bool = True)
-
Material ID
Expand source code
class MID(str): """Material ID""" _id_pattern = re.compile('[0-9a-f]+', flags=re.IGNORECASE) def __new__(cls, content: Any, validate: bool = True): if validate: cls.validate(content) return str.__new__(cls, content) @classmethod def __get_validators__(cls): yield cls.validate @classmethod def validate(cls, v: Any): """Validate Material ID Args: v: Material ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id = v.split(':') MaterialType(_type) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) if not cls._id_pattern.fullmatch(_id): log.error('ID: %s is not the same with %s pattern', _id, cls._id_pattern) raise EIDError(value=v) return cls(v, validate=False) @property def type(self) -> MaterialType: """Get one of the material types Returns: MaterialType """ _type, _ = self.split(':') return MaterialType(_type) @property def id(self) -> str: """Get id of material type Returns: str id """ _, _id = self.split(':') return _id
Ancestors
- builtins.str
Static methods
def validate(v: Any)
-
Validate Material ID
Args
v
- Material ID
Returns:
Expand source code
@classmethod def validate(cls, v: Any): """Validate Material ID Args: v: Material ID Returns: """ if not isinstance(v, str): log.error('%s is not instance of str', v) raise EIDError(value=v) try: _type, _id = v.split(':') MaterialType(_type) except ValueError: log.exception('Cannot get id and type from value') raise EIDError(value=v) if not cls._id_pattern.fullmatch(_id): log.error('ID: %s is not the same with %s pattern', _id, cls._id_pattern) raise EIDError(value=v) return cls(v, validate=False)
Instance variables
var id : str
-
Get id of material type
Returns
str id
Expand source code
@property def id(self) -> str: """Get id of material type Returns: str id """ _, _id = self.split(':') return _id
var type : MaterialType
-
Get one of the material types
Returns
MaterialType
Expand source code
@property def type(self) -> MaterialType: """Get one of the material types Returns: MaterialType """ _type, _ = self.split(':') return MaterialType(_type)
class MaterialType (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class MaterialType(str, Enum): LIBRARY = 'assetType' ASSET = 'asset' BATCH = 'batch'
Ancestors
- builtins.str
- enum.Enum
Class variables
var ASSET
var BATCH
var LIBRARY
class ObjectType (value, names=None, *, module=None, qualname=None, type=None, start=1)
-
An enumeration.
Expand source code
class ObjectType(str, Enum): ENTITY = 'entity' ADT_ROW = 'adtRow' COLUMN_DEFINITIONS = 'columnDefinitions' MATERIAL = 'material' ASSET_TYPE = 'assetType' ATTRIBUTE = 'attribute' STOICHIOMETRY = 'stoichiometry' PROPERTY = 'property' USER = 'user' PROFILE = 'profile' GROUP = 'group' ROLE = 'role' PLATE_ROW = 'plateRow' ATTRIBUTE_OPTION = 'option' CHOICE = 'choice' SUB_EXPERIMENT = 'subexpSummaryRow' CONTAINER = 'container' REACTION_PRODUCT = 'reactionProduct' REACTION_REACTANT = 'reactionReactant' REACTION_REAGENT = 'reactionReagent'
Ancestors
- builtins.str
- enum.Enum
Class variables
var ADT_ROW
var ASSET_TYPE
var ATTRIBUTE
var ATTRIBUTE_OPTION
var CHOICE
var COLUMN_DEFINITIONS
var CONTAINER
var ENTITY
var GROUP
var MATERIAL
var PLATE_ROW
var PROFILE
var PROPERTY
var REACTION_PRODUCT
var REACTION_REACTANT
var REACTION_REAGENT
var ROLE
var STOICHIOMETRY
var SUB_EXPERIMENT
var USER
class Response (**kwargs)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Response(GenericModel, Generic[EntityClass]): links: Optional[Links] = None data: Union[ResponseData[EntityClass], List[ResponseData[EntityClass]]] def __init__(self, _context: dict[str, Any] = None, **kwargs): data = kwargs.get('data', {}) if _context: if isinstance(data, list): data = [{'_context': _context, **item} for item in data] else: data = {'_context': _context, **data} super().__init__(**{**kwargs, 'data': data})
Ancestors
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
- Response[Attribute]
- Response[_AttributeOption]
- Response[Structure]
- Response[Property]
- Response[Row]
- Response[PlateRow]
- Response[SampleCell]
- Response[Sample]
- Response[ColumnDefinitions]
- Response[DataGrids]
- Response[ColumnDefinitions]
- Response[Row]
- Response[Table]
- Response[TaskCell]
- Response[Batch]
- Response[Asset]
- Response[_LibraryListData]
- Response[Union[Library, Asset, Batch]]
- Response[Group]
- Response[Role]
- Response[Profile]
- Response[User]
Class variables
var data : Union[ResponseData, List[ResponseData]]
var links : Optional[Links]
class ResponseData (**kwargs)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class ResponseData(GenericModel, Generic[EntityClass]): type: ObjectType eid: Union[EID, MID, AttrID, UUID, str] = Field(alias='id') links: Optional[Links] = None body: EntityClass = Field(alias='attributes') relationships: Optional[dict[str, Any]] = Field(default=None) meta: Optional[dict[str, Any]] = Field(default=None) def __init__(self, _context: dict[str, Any] = None, **kwargs): attributes = kwargs.get('attributes', {}) if _context: attributes = {**attributes, **_context} super().__init__(**{**kwargs, 'attributes': attributes})
Ancestors
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
- pydantic.generics.ResponseData[Asset]
- pydantic.generics.ResponseData[Attribute]
- pydantic.generics.ResponseData[Batch]
- pydantic.generics.ResponseData[ColumnDefinitions]
- pydantic.generics.ResponseData[ColumnDefinitions]
- pydantic.generics.ResponseData[DataGrids]
- pydantic.generics.ResponseData[Group]
- pydantic.generics.ResponseData[PlateRow]
- pydantic.generics.ResponseData[Profile]
- pydantic.generics.ResponseData[Property]
- pydantic.generics.ResponseData[Role]
- pydantic.generics.ResponseData[Row]
- pydantic.generics.ResponseData[Row]
- pydantic.generics.ResponseData[SampleCell]
- pydantic.generics.ResponseData[Sample]
- pydantic.generics.ResponseData[Structure]
- pydantic.generics.ResponseData[Table]
- pydantic.generics.ResponseData[TaskCell]
- pydantic.generics.ResponseData[Union[Library, Asset, Batch]]
- pydantic.generics.ResponseData[User]
- pydantic.generics.ResponseData[_AttributeOption]
- pydantic.generics.ResponseData[_LibraryListData]
Class variables
var body : ~EntityClass
var eid : Union[EID, MID, AttrID, uuid.UUID, str]
var links : Optional[Links]
var meta : Optional[dict]
var relationships : Optional[dict]
var type : ObjectType
class Template (**data: Any)
-
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
Expand source code
class Template(DataObject[EntityShortDescription]): pass
Ancestors
- DataObject[EntityShortDescription]
- DataObject
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Class variables
var data : EntityShortDescription