Skip to content

Datasource API

Source code in upriver/sdk/datasource/datasource_api.py
22
23
def __init__(self, session: Session):
    self._session = session

create_datasource

create_datasource(
    name,
    owners,
    data_connection_configuration,
    *,
    id=None,
    contract_generation_configuration=None,
    incident_configuration=None,
    pivot_fields=(),
    tags=None,
    pause_on_creation=False,
    is_key_asset=False
)

Creates a new datasource with the given parameters. See the NewDatasource class for more detailed information on the parameters.

PARAMETER DESCRIPTION
name

The name of the datasource.

TYPE: str

owners

The list of the names of the owners of the datasource.

TYPE: List[str]

data_connection_configuration

The configuration connecting to pull data for this datasource. These configurations cannot be changed once the datasource is created.

TYPE: DatasourceConnectionConfiguration

id

(optional) The id of the datasource. This id will not be used by upriver internally, and is meant to be used by the client to identify the datasource.

TYPE: Optional[str] DEFAULT: None

contract_generation_configuration

(optional) Configurations that alter the behaviour of Upriver when generating the contract for this datasource.

TYPE: Optional[DatasourceContractGenerationConfiguration] DEFAULT: None

incident_configuration

(optional) Configurations that alter the behaviour of Upriver when raising incidents for the datasource.

TYPE: Optional[DatasourceIncidentConfiguration] DEFAULT: None

pivot_fields

(optional) The fields that will be used to pivot the datasource and generate derived datasources. The order of the fields matter - the datasources will be nested by the order of the fields here. This pivot fields cannot be changed once the datasource is created.

TYPE: Sequence[str] DEFAULT: ()

tags

(optional) A list of tags to associate with the datasource.

TYPE: Optional[List[str]] DEFAULT: None

pause_on_creation

If true, the datasource will be paused after creation.

TYPE: (optional) DEFAULT: False

is_key_asset

If true, the datasource will be considered a key asset.

TYPE: (optional) DEFAULT: False

RETURNS DESCRIPTION
NewDatasourceResponse

The id of the created datasource.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def create_datasource(
    self,
    name: str,
    owners: List[str],
    data_connection_configuration: DatasourceConnectionConfiguration,
    *,
    id: Optional[str] = None,
    contract_generation_configuration: Optional[DatasourceContractGenerationConfiguration] = None,
    incident_configuration: Optional[DatasourceIncidentConfiguration] = None,
    pivot_fields: Sequence[str] = (),
    tags: Optional[List[str]] = None,
    pause_on_creation: bool = False,
    is_key_asset: bool = False,
) -> NewDatasourceResponse:
    """
    Creates a new datasource with the given parameters.
    See the NewDatasource class for more detailed information on the parameters.
    :param name: The name of the datasource.
    :param owners: The list of the names of the owners of the datasource.
    :param data_connection_configuration: The configuration connecting to pull data for this datasource.
    These configurations cannot be changed once the datasource is created.
    :param id: (optional) The id of the datasource. This id will not be used by upriver internally,
    and is meant to be used by the client to identify the datasource.
    :param contract_generation_configuration: (optional) Configurations that alter the behaviour of Upriver
    when generating the contract for this datasource.
    :param incident_configuration: (optional) Configurations that alter the behaviour of Upriver when
    raising incidents for the datasource.
    :param pivot_fields: (optional) The fields that will be used to pivot the datasource and generate
    derived datasources.
    The order of the fields matter - the datasources will be nested by the order of the fields here.
    This pivot fields cannot be changed once the datasource is created.
    :param tags: (optional) A list of tags to associate with the datasource.
    :param (optional) pause_on_creation: If true, the datasource will be paused after creation.
    :param (optional) is_key_asset: If true, the datasource will be considered a key asset.
    :return: The id of the created datasource.
    :raises requests.HTTPError: If the request fails.
    """
    datasource = NewDatasource(
        id=id,
        owners=owners,
        name=name,
        data_connection_configuration=data_connection_configuration,
        contract_generation_configuration=(
            contract_generation_configuration
            if contract_generation_configuration
            else DatasourceContractGenerationConfiguration()
        ),
        incident_configuration=(
            incident_configuration if incident_configuration else DatasourceIncidentConfiguration()
        ),
        pivot_fields=tuple(pivot_fields),
        tags=tags or [],
        pause_on_creation=pause_on_creation,
        is_key_asset=is_key_asset,
    )
    response = self._session.post("datasource/new", "v1", datasource)
    return NewDatasourceResponse.model_validate(response.json())

get_root_datasources

get_root_datasources()

Gets all root datasources.

RETURNS DESCRIPTION
List[Datasource]

A list of all root datasources.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
83
84
85
86
87
88
89
90
def get_root_datasources(self) -> List[Datasource]:
    """
    Gets all root datasources.
    :return: A list of all root datasources.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get("datasource/roots", "v1")
    return [Datasource.model_validate(datasource) for datasource in response.json()]

get_datasource

get_datasource(upriver_id)

Gets the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to get.

TYPE: str

RETURNS DESCRIPTION
Datasource

The datasource with the given id.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
 92
 93
 94
 95
 96
 97
 98
 99
100
def get_datasource(self, upriver_id: str) -> Datasource:
    """
    Gets the datasource with the given id.
    :param upriver_id: The id of the datasource to get.
    :return: The datasource with the given id.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get(f"datasource/{upriver_id}", "v1")
    return Datasource.model_validate(response.json())

get_datasource_schema

get_datasource_schema(upriver_id)

Gets the schema of the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to get the schema of.

TYPE: str

RETURNS DESCRIPTION
SchemaResponse

The schema of the datasource with the given id.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
102
103
104
105
106
107
108
109
110
def get_datasource_schema(self, upriver_id: str) -> SchemaResponse:
    """
    Gets the schema of the datasource with the given id.
    :param upriver_id: The id of the datasource to get the schema of.
    :return: The schema of the datasource with the given id.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get(f"datasource/{upriver_id}/schema", "v1")
    return SchemaResponse.model_validate(response.json())

get_all_datasources

get_all_datasources()

Gets all datasources.

RETURNS DESCRIPTION
List[Datasource]

A list of all datasources.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
112
113
114
115
116
117
118
119
def get_all_datasources(self) -> List[Datasource]:
    """
    Gets all datasources.
    :return: A list of all datasources.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get("datasource/all", "v1")
    return [Datasource.model_validate(datasource) for datasource in response.json()]

get_datasource_settings

get_datasource_settings(upriver_id)

Gets the settings of the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to get.

TYPE: str

RETURNS DESCRIPTION
DatasourceSettings

The settings of the datasource with the given id.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
121
122
123
124
125
126
127
128
129
def get_datasource_settings(self, upriver_id: str) -> DatasourceSettings:
    """
    Gets the settings of the datasource with the given id.
    :param upriver_id: The id of the datasource to get.
    :return: The settings of the datasource with the given id.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get(f"datasource/{upriver_id}/settings/get", "v1")
    return DatasourceSettings.model_validate(response.json())

update_datasource_settings

update_datasource_settings(
    upriver_id, datasource_settings, sync_children=False
)

Updates the settings of the datasource with the given id. None values in the settings will be updated to None in the datasource if allowed.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to update.

TYPE: str

datasource_settings

The new settings of the datasource.

TYPE: DatasourceSettings

RETURNS DESCRIPTION
Response

The updated settings of the datasource.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
def update_datasource_settings(
    self, upriver_id: str, datasource_settings: DatasourceSettings, sync_children: bool = False
) -> Response:
    """
    Updates the settings of the datasource with the given id.
    None values in the settings will be updated to None in the datasource if allowed.
    :param upriver_id: The id of the datasource to update.
    :param datasource_settings: The new settings of the datasource.
    :return: The updated settings of the datasource.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.post(
        f"datasource/{upriver_id}/settings/update/{sync_children}", "v1", datasource_settings
    )
    return response

patch_datasource_settings

patch_datasource_settings(
    upriver_id, datasource_settings, sync_children=False
)

Patches the settings of the datasource with the given id. Ignores None values in the settings.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to patch.

TYPE: str

datasource_settings

The settings to patch the datasource with.

TYPE: DatasourceSettings

RETURNS DESCRIPTION
Response

The updated settings of the datasource.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
def patch_datasource_settings(
    self, upriver_id: str, datasource_settings: DatasourceSettings, sync_children: bool = False
) -> Response:
    """
    Patches the settings of the datasource with the given id.
    Ignores None values in the settings.
    :param upriver_id: The id of the datasource to patch.
    :param datasource_settings: The settings to patch the datasource with.
    :return: The updated settings of the datasource.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.post(
        f"datasource/{upriver_id}/settings/patch/{sync_children}", "v1", datasource_settings
    )
    return response

run_datasource

run_datasource(upriver_id)

Runs the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to run.

TYPE: str

RETURNS DESCRIPTION
RunResponse

The id of the run.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
163
164
165
166
167
168
169
170
171
def run_datasource(self, upriver_id: str) -> RunResponse:
    """
    Runs the datasource with the given id.
    :param upriver_id: The id of the datasource to run.
    :return: The id of the run.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.post(f"datasource/{upriver_id}/run", "v1", None)
    return RunResponse.model_validate(response.json())

get_datasource_status

get_datasource_status(upriver_id)

Gets a detailed status of the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource.

TYPE: str

RETURNS DESCRIPTION
DatasourceStatus

The status of the run.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
173
174
175
176
177
178
179
180
181
def get_datasource_status(self, upriver_id: str) -> DatasourceStatus:
    """
    Gets a detailed status of the datasource with the given id.
    :param upriver_id: The id of the datasource.
    :return: The status of the run.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get(f"datasource/{upriver_id}/status", "v1")
    return DatasourceStatus.model_validate(response.json())

get_datasource_run_status

get_datasource_run_status(upriver_id, run_id)

Gets the status of the run of the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource.

TYPE: str

run_id

The id of the run.

TYPE: str

RETURNS DESCRIPTION
RunStatusResponse

The status of the run.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
183
184
185
186
187
188
189
190
191
192
def get_datasource_run_status(self, upriver_id: str, run_id: str) -> RunStatusResponse:
    """
    Gets the status of the run of the datasource with the given id.
    :param upriver_id: The id of the datasource.
    :param run_id: The id of the run.
    :return: The status of the run.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.get(f"datasource/{upriver_id}/run/{run_id}/status", "v1")
    return RunStatusResponse.model_validate(response.json())

set_user_defined_schema

set_user_defined_schema(
    upriver_id, user_defined_schema_file_path, sync
)

Sets a user defined schema for the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource.

TYPE: str

user_defined_schema_file_path

Path to a user defined schema file if exists.

TYPE: str

sync

If true, the schema will also be applied to descendants datasources.

TYPE: bool

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
def set_user_defined_schema(self, upriver_id: str, user_defined_schema_file_path: str, sync: bool) -> Response:
    """
    Sets a user defined schema for the datasource with the given id.
    :param upriver_id: The id of the datasource.
    :param user_defined_schema_file_path: Path to a user defined schema file if exists.
    :param sync: If true, the schema will also be applied to descendants datasources.
    :raises requests.HTTPError: If the request fails.
    """
    with open(user_defined_schema_file_path, "rb") as f:
        files = {
            "user_defined_schema": (
                user_defined_schema_file_path,
                f,
                "text/csv" if user_defined_schema_file_path.endswith(".csv") else "application/json",
            )
        }
        return self._session.post(f"datasource/{upriver_id}/add_schema/{sync}", "v1", json=None, files=files)

delete_user_defined_schema

delete_user_defined_schema(upriver_id)

Delete the user defined schema for the datasource with the given id. Will also delete all user expectations.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource.

TYPE: str

sync

If true, the schema will also be applied to descendants datasources.

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
212
213
214
215
216
217
218
219
def delete_user_defined_schema(self, upriver_id: str) -> Response:
    """
    Delete the user defined schema for the datasource with the given id. Will also delete all user expectations.
    :param upriver_id: The id of the datasource.
    :param sync: If true, the schema will also be applied to descendants datasources.
    :raises requests.HTTPError: If the request fails.
    """
    return self._session.delete(f"datasource/{upriver_id}/delete_schema", "v1")

set_datasource_metadata_expectations

set_datasource_metadata_expectations(
    upriver_id, metadata_expectations, sync_children=False
)

Sets the metadata expectations for the datasource with the given id.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to update.

TYPE: str

metadata_expectations

The metadata expectations to set over the datasource.

TYPE: DatasourceMetadataExpectations

sync_children

If true, the metadata expectations will also be applied to descendants datasources.

TYPE: bool DEFAULT: False

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
221
222
223
224
225
226
227
228
229
230
231
232
233
234
def set_datasource_metadata_expectations(
    self, upriver_id: str, metadata_expectations: DatasourceMetadataExpectations, sync_children: bool = False
) -> Response:
    """
    Sets the metadata expectations for the datasource with the given id.
    :param upriver_id: The id of the datasource to update.
    :param metadata_expectations: The metadata expectations to set over the datasource.
    :param sync_children: If true, the metadata expectations will also be applied to descendants datasources.
    :raises requests.HTTPError: If the request fails.
    """
    response = self._session.post(
        f"datasource/{upriver_id}/set_metadata_expectations/{sync_children}", "v1", metadata_expectations
    )
    return response

force_running_state_datasource

force_running_state_datasource(upriver_id)

Fast forward provided datasource to running state. This action is only available for datasources that are in the learning state. Note: This action will shorten the baseline learning time and may affect the accuracy of the monitoring.

PARAMETER DESCRIPTION
upriver_id

The id of the datasource to force running state.

TYPE: str

RAISES DESCRIPTION
requests.HTTPError

If the request fails.

Source code in upriver/sdk/datasource/datasource_api.py
236
237
238
239
240
241
242
243
244
245
def force_running_state_datasource(self, upriver_id: str) -> Response:
    """
    Fast forward provided datasource to running state. This action is only available
    for datasources that are in the learning state.
    Note: This action will shorten the baseline learning time and may affect the accuracy
    of the monitoring.
    :param upriver_id: The id of the datasource to force running state.
    :raises requests.HTTPError: If the request fails.
    """
    return self._session.post(f"datasource/{upriver_id}/force_running_state", "v1", None)