Module signals_notebook.materials.material_store
Expand source code
import logging
from typing import cast, Union
from signals_notebook.api import SignalsNotebookApi
from signals_notebook.common_types import MID, Response, ResponseData
from signals_notebook.materials.asset import Asset
from signals_notebook.materials.batch import Batch
from signals_notebook.materials.library import Library
from signals_notebook.materials.material import Material
log = logging.getLogger(__name__)
class MaterialResponse(Response[Union[Library, Asset, Batch]]):
pass
class MaterialStore:
@classmethod
def _get_endpoint(cls) -> str:
return 'materials'
@classmethod
def get(cls, eid: MID) -> Material:
"""Fetch material by entity ID.
Args:
eid: Unique material identifier
Returns:
Material
"""
api = SignalsNotebookApi.get_default_api()
log.debug('Get Material Store for %s', eid)
response = api.call(
method='GET',
path=(cls._get_endpoint(), eid),
)
result = MaterialResponse(**response.json())
return cast(ResponseData, result.data).body
Classes
class MaterialResponse (**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 MaterialResponse(Response[Union[Library, Asset, Batch]]): pass
Ancestors
- Response[Union[Library, Asset, Batch]]
- Response
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Class variables
var data : Union[pydantic.generics.ResponseData[Union[Library, Asset, Batch]], List[pydantic.generics.ResponseData[Union[Library, Asset, Batch]]]]
var links : Optional[Links]
class MaterialStore
-
Expand source code
class MaterialStore: @classmethod def _get_endpoint(cls) -> str: return 'materials' @classmethod def get(cls, eid: MID) -> Material: """Fetch material by entity ID. Args: eid: Unique material identifier Returns: Material """ api = SignalsNotebookApi.get_default_api() log.debug('Get Material Store for %s', eid) response = api.call( method='GET', path=(cls._get_endpoint(), eid), ) result = MaterialResponse(**response.json()) return cast(ResponseData, result.data).body
Static methods
def get(eid: MID) ‑> Material
-
Fetch material by entity ID.
Args
eid
- Unique material identifier
Returns
Material
Expand source code
@classmethod def get(cls, eid: MID) -> Material: """Fetch material by entity ID. Args: eid: Unique material identifier Returns: Material """ api = SignalsNotebookApi.get_default_api() log.debug('Get Material Store for %s', eid) response = api.call( method='GET', path=(cls._get_endpoint(), eid), ) result = MaterialResponse(**response.json()) return cast(ResponseData, result.data).body
class Response[Union[Library, Asset, Batch]] (**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.
Ancestors
- Response
- pydantic.generics.GenericModel
- pydantic.main.BaseModel
- pydantic.utils.Representation
- typing.Generic
Subclasses
Class variables
var Config
var data : Union[pydantic.generics.ResponseData[Union[Library, Asset, Batch]], List[pydantic.generics.ResponseData[Union[Library, Asset, Batch]]]]
var links : Optional[Links]