Skip to content

Gateways

get_gateway(gateway, *, df=True)

Retrieves the details of a gateway by its ID.

Parameters:

Name Type Description Default
gateway str

The name or ID of the gateway to retrieve.

required
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, Dict[str, Any], None]

The gateway details if found, otherwise None.

Examples:

get_gateway('123e4567-e89b-12d3-a456-426614174000')
get_gateway('my-gateway')
Source code in src/pyfabricops/core/gateways.py
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@df
def get_gateway(
    gateway: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Retrieves the details of a gateway by its ID.

    Args:
        gateway (str): The name or ID of the gateway to retrieve.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The gateway details if found, otherwise None.

    Examples:
        ```python
        get_gateway('123e4567-e89b-12d3-a456-426614174000')
        get_gateway('my-gateway')
        ```
    """
    gateway_id = resolve_gateway(gateway)
    if not gateway_id:
        return None
    return api_request(
        '/gateways/' + gateway_id,
    )

get_gateway_id(gateway_name)

Retrieves the ID of a gateway by its name.

Parameters:

Name Type Description Default
gateway_name str

The name of the gateway.

required

Returns:

Type Description
Union[str, None]

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

Source code in src/pyfabricops/core/gateways.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
def get_gateway_id(gateway_name: str) -> Union[str, None]:
    """
    Retrieves the ID of a gateway by its name.

    Args:
        gateway_name (str): The name of the gateway.

    Returns:
        str | None: The ID of the gateway if found, otherwise None.
    """
    gateways = list_gateways(df=False)
    for _gateway in gateways:
        if _gateway['displayName'] == gateway_name:
            return _gateway['id']
    logger.warning(f"Gateway '{gateway_name}' not found.")
    return None

get_gateway_public_key(gateway)

Extracts the public key of a gateway by its ID.

Parameters:

Name Type Description Default
gateway str

The ID of the gateway to retrieve the public key from.

required

Returns:

Name Type Description
dict dict | None

The public key details if found, otherwise None.

Examples:

get_gateway_public_key('123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/core/gateways.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def get_gateway_public_key(gateway: str) -> dict | None:
    """
    Extracts the public key of a gateway by its ID.

    Args:
        gateway (str): The ID of the gateway to retrieve the public key from.

    Returns:
        dict: The public key details if found, otherwise None.

    Examples:
        ```python
        get_gateway_public_key('123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    response = get_gateway(gateway, df=False)
    if not response:
        return None

    return response.get('publicKey')

list_gateways(df=True)

Lists all available gateways.

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]

The list of gateways.

Examples:

list_gateways()
Source code in src/pyfabricops/core/gateways.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@df
def list_gateways(
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Lists all available gateways.

    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]): The list of gateways.

    Examples:
        ```python
        list_gateways()
        ```
    """
    return api_request('/gateways', support_pagination=True)

resolve_gateway(gateway)

Resolves a gateway name to its ID.

Parameters:

Name Type Description Default
gateway str

The name of the gateway.

required

Returns:

Type Description
Union[str, None]

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

Source code in src/pyfabricops/core/gateways.py
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def resolve_gateway(gateway: str) -> Union[str, None]:
    """
    Resolves a gateway name to its ID.

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

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