Skip to content

Capacities

get_capacity_id(capacity_name)

Retrieves the ID of a capacity by its name.

Parameters:

Name Type Description Default
capacity_name str

The name of the capacity.

required

Returns:

Type Description
str | None

str | None: The ID of the capacity if found, otherwise None.

Source code in src/pyfabricops/core/capacities.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def get_capacity_id(capacity_name: str) -> str | None:
    """
    Retrieves the ID of a capacity by its name.

    Args:
        capacity_name (str): The name of the capacity.

    Returns:
        str | None: The ID of the capacity if found, otherwise None.
    """
    capacities = list_capacities(df=False)

    for _capacity in capacities:
        if _capacity['displayName'] == capacity_name:
            return _capacity['id']

    logger.warning(f"Capacity '{capacity_name}' not found.")
    return None

list_capacities(df=True)

Returns a list of capacities.

Parameters:

Name Type Description Default
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, List[Dict[str, Any]], None]

A DataFrame with the list of capacities.

Union[DataFrame, List[Dict[str, Any]], None]

If df=False, returns a list of dictionaries. If no capacities are found, returns None.

Source code in src/pyfabricops/core/capacities.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
@df
def list_capacities(
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Returns a list of capacities.

    Args:
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, List[Dict[str, Any]], None]): A DataFrame with the list of capacities.
        If `df=False`, returns a list of dictionaries. If no capacities are found, returns None.
    """
    return api_request('/capacities', support_pagination=True)

resolve_capacity(capacity)

Resolves a capacity name to its ID.

Parameters:

Name Type Description Default
capacity str

The name of the capacity.

required

Returns:

Type Description
str | None

str | None: The ID of the capacity if found, otherwise None.

Source code in src/pyfabricops/core/capacities.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def resolve_capacity(capacity: str) -> str | None:
    """
    Resolves a capacity name to its ID.

    Args:
        capacity (str): The name of the capacity.

    Returns:
        str | None: The ID of the capacity if found, otherwise None.
    """
    if is_valid_uuid(capacity):
        return capacity
    else:
        return get_capacity_id(capacity)