Skip to content

Material

Access material information from FIO.

Material

Bases: AbstractMaterial, AbstractEndpoint

get

get(material_ticker, timeout=None)

Gets a single material from FIO

Parameters:

Name Type Description Default
material_ticker str

Material Ticker (e.g., "DW")

required
timeout float

Request timeout in seconds. Defaults to None.

None

Raises:

Type Description
MaterialTickerNotFound

Material Ticker was not found

Returns:

Name Type Description
MaterialModel MaterialTicker

Material

Source code in fio_wrapper/endpoints/endpoints_v1/material.py
def get(
    self, material_ticker: str, timeout: Optional[float] = None
) -> MaterialTicker:
    """Gets a single material from FIO

    Args:
        material_ticker (str): Material Ticker (e.g., "DW")
        timeout (float, optional): Request timeout in seconds. Defaults to None.

    Raises:
        MaterialTickerNotFound: Material Ticker was not found

    Returns:
        MaterialModel: Material
    """

    self._validate_ticker(material_ticker=material_ticker)

    (status, data) = self.adapter.get(
        endpoint=self.urls.material_get_url(material_ticker=material_ticker),
        err_codes=[204],
        timeout=timeout,
    )

    if status == 200:
        return MaterialTicker.model_validate(data)
    elif status == 204:
        raise MaterialTickerNotFound("Materialticker not found")

all

all(timeout=None)

Gets all materials from FIO

Parameters:

Name Type Description Default
timeout float

Request timeout in seconds. Defaults to None.

None

Returns:

Name Type Description
MaterialModelList MaterialTickerList

List of Materials as List[MaterialModel]

Source code in fio_wrapper/endpoints/endpoints_v1/material.py
def all(self, timeout: Optional[float] = None) -> MaterialTickerList:
    """Gets all materials from FIO

    Args:
        timeout (float, optional): Request timeout in seconds. Defaults to None.

    Returns:
        MaterialModelList: List of Materials as List[MaterialModel]
    """
    (_, data) = self.adapter.get(
        endpoint=self.urls.material_allmaterials_url(), timeout=timeout
    )
    return MaterialTickerList.model_validate(data)

category

category(category_name, timeout=None)

Gets all materials of specified category

Parameters:

Name Type Description Default
category_name str

Category name (e.g., "agricultural products")

required
timeout float

Request timeout in seconds. Defaults to None.

None

Raises:

Type Description
MaterialCategoryNotFound

Category was not found

Returns:

Name Type Description
MaterialModelList MaterialTickerList

List of Materials as List[MaterialModel]

Source code in fio_wrapper/endpoints/endpoints_v1/material.py
def category(
    self, category_name: str, timeout: Optional[float] = None
) -> MaterialTickerList:
    """Gets all materials of specified category

    Args:
        category_name (str): Category name (e.g., "agricultural products")
        timeout (float, optional): Request timeout in seconds. Defaults to None.

    Raises:
        MaterialCategoryNotFound: Category was not found

    Returns:
        MaterialModelList: List of Materials as List[MaterialModel]
    """
    (status, data) = self.adapter.get(
        endpoint=self.urls.material_get_category(category_name=category_name),
        err_codes=[204],
        timeout=timeout,
    )

    if status == 200 and len(data) > 0:
        return MaterialTickerList.model_validate(data)
    elif status == 204 or len(data) == 0:
        raise MaterialCategoryNotFound("Material category not found")