lomas_client package

Subpackages

Submodules

lomas_client.client module

class lomas_client.client.Client(**kwargs: {'extra': 'ignore', 'arbitrary_types_allowed': True, 'validate_default': True, 'case_sensitive': False, 'env_prefix': 'lomas_client_', 'nested_model_default_partial_update': False, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': False, 'env_nested_delimiter': '__', 'env_nested_max_split': None, 'env_parse_none_str': None, 'env_parse_enums': None, 'cli_prog_name': None, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_hide_none_type': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_use_class_docs_for_groups': False, 'cli_exit_on_error': True, 'cli_prefix': '', 'cli_flag_prefix_char': '-', 'cli_implicit_flags': False, 'cli_ignore_unknown_args': False, 'cli_kebab_case': False, 'json_file': None, 'json_file_encoding': None, 'yaml_file': None, 'yaml_file_encoding': None, 'toml_file': None, 'secrets_dir': None, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'enable_decoding': True})[source]

Bases: object

Client class to send requests to the server.

Handle all serialisation and deserialisation steps

get_dataset_metadata() LomasRequestModel[source]

This function retrieves metadata for the dataset.

Returns:

A dictionary containing dataset metadata.

Return type:

LomasRequestModel

get_dummy_dataset(nb_rows: int = 100, seed: int = 42, lazy: bool = False) DataFrame | LazyFrame[source]

This function retrieves a dummy dataset with optional parameters.

Parameters:
  • nb_rows (int, optional) – The number of rows in the dummy dataset. Defaults to DUMMY_NB_ROWS.

  • seed (int, optional) – The random seed for generating the dummy dataset. Defaults to DUMMY_SEED.

  • lazy (bool, optional) – If True, return a polars LazyFrame. Defaults to False (pandas DataFrame)

Returns:

A Pandas DataFrame representing the dummy dataset (optionally in LazyFrame format).

Return type:

pd.DataFrame | pl.LazyFrame

get_dummy_lf(nb_rows: int = 100, seed: int = 42) LazyFrame[source]

Returns the polars LazyFrame for the dummy dataset with optional parameters.

Parameters:
  • nb_rows (int, optional) – The number of rows in the dummy dataset. Defaults to DUMMY_NB_ROWS.

  • seed (int, optional) – The random seed for generating the dummy dataset. Defaults to DUMMY_SEED.

Returns:

The LazyFrame for the dummy dataset

Return type:

Optional[pl.LazyFrame]

get_initial_budget() InitialBudgetResponse[source]

This function retrieves the initial budget.

Returns:

A dictionary

containing the initial budget.

Return type:

InitialBudgetResponse

get_previous_queries() list[dict][source]

This function retrieves the previous queries of the user.

Raises:

ValueError – If an unknown query type is encountered during deserialization.

Returns:

A list of dictionary containing the different queries on the private dataset.

Return type:

List[dict]

get_remaining_budget() RemainingBudgetResponse[source]

This function retrieves the remaining budget.

Returns:

A dictionary

containing the remaining budget.

Return type:

RemainingBudgetResponse

get_total_spent_budget() SpentBudgetResponse[source]

This function retrieves the total spent budget.

Returns:

A dictionary containing

the total spent budget.

Return type:

SpentBudgetResponse

lomas_client.constants module

lomas_client.http_client module

class lomas_client.http_client.LomasHttpClient(config: ClientConfig)[source]

Bases: object

A client for interacting with the Lomas API.

post(endpoint: str, body: LomasRequestModel, read_timeout: int = 300) Response[source]

Executes a POST request to endpoint with the provided JSON body.

Handles authorization to the api by automatically fetching a token if required.

Parameters:
  • endpoint (str) – The API endpoint to which the request will be sent.

  • body_json (dict, optional) – The JSON body to include in the POST request. Defaults to {}.

  • request_model – (BaseModel, optional): The pydantic model to validate the body_json against. Must be non-null if body_json contains data.

  • read_timeout (int) – number of seconds that client wait for the server to send a response. Defaults to DEFAULT_READ_TIMEOUT.

Returns:

The response object resulting from the POST request.

Return type:

requests.Response

wait_for_job(job_uid: str, n_retry: int = 1800, sleep_sec: float = 1) Job[source]

Periodically query the job endpoint sleeping in between until it completes / times-out.

lomas_client.utils module

lomas_client.utils.raise_error(response: Response) Never[source]

Raise error message based on the HTTP response.

Parameters:

res (requests.Response) – The response object from an HTTP request.

Raises:

Server Error

lomas_client.utils.validate_model_response(client: LomasHttpClient, response: Response, response_model: type[ResponseT]) ResponseT[source]

Validate and process a HTTP response.

Parameters:

response (requests.Response) – The response object from an HTTP request.

Returns:

Model for responses requests.

Return type:

response_model

lomas_client.utils.validate_model_response_direct(response: Response, response_model: Any) Any[source]

Validate and process a HTTP response.

Parameters:

response (requests.Response) – The response object from an HTTP request.

Returns:

Model for responses requests.

Return type:

response_model

lomas_client.utils.validate_synthesizer(synth_name: str, return_model: bool = False) None[source]

Validate smartnoise synthesizer (some model are not accepted).

Parameters:
  • synth_name (str) – name of the Synthesizer model to use.

  • return_model (bool) – True to get Synthesizer model, False to get samples

Raises:

ValueError – if a synthesizer or its parameters are not valid

Module contents

class lomas_client.Client(**kwargs: {'extra': 'ignore', 'arbitrary_types_allowed': True, 'validate_default': True, 'case_sensitive': False, 'env_prefix': 'lomas_client_', 'nested_model_default_partial_update': False, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': False, 'env_nested_delimiter': '__', 'env_nested_max_split': None, 'env_parse_none_str': None, 'env_parse_enums': None, 'cli_prog_name': None, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_hide_none_type': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_use_class_docs_for_groups': False, 'cli_exit_on_error': True, 'cli_prefix': '', 'cli_flag_prefix_char': '-', 'cli_implicit_flags': False, 'cli_ignore_unknown_args': False, 'cli_kebab_case': False, 'json_file': None, 'json_file_encoding': None, 'yaml_file': None, 'yaml_file_encoding': None, 'toml_file': None, 'secrets_dir': None, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'enable_decoding': True})[source]

Bases: object

Client class to send requests to the server.

Handle all serialisation and deserialisation steps

get_dataset_metadata() LomasRequestModel[source]

This function retrieves metadata for the dataset.

Returns:

A dictionary containing dataset metadata.

Return type:

LomasRequestModel

get_dummy_dataset(nb_rows: int = 100, seed: int = 42, lazy: bool = False) DataFrame | LazyFrame[source]

This function retrieves a dummy dataset with optional parameters.

Parameters:
  • nb_rows (int, optional) – The number of rows in the dummy dataset. Defaults to DUMMY_NB_ROWS.

  • seed (int, optional) – The random seed for generating the dummy dataset. Defaults to DUMMY_SEED.

  • lazy (bool, optional) – If True, return a polars LazyFrame. Defaults to False (pandas DataFrame)

Returns:

A Pandas DataFrame representing the dummy dataset (optionally in LazyFrame format).

Return type:

pd.DataFrame | pl.LazyFrame

get_dummy_lf(nb_rows: int = 100, seed: int = 42) LazyFrame[source]

Returns the polars LazyFrame for the dummy dataset with optional parameters.

Parameters:
  • nb_rows (int, optional) – The number of rows in the dummy dataset. Defaults to DUMMY_NB_ROWS.

  • seed (int, optional) – The random seed for generating the dummy dataset. Defaults to DUMMY_SEED.

Returns:

The LazyFrame for the dummy dataset

Return type:

Optional[pl.LazyFrame]

get_initial_budget() InitialBudgetResponse[source]

This function retrieves the initial budget.

Returns:

A dictionary

containing the initial budget.

Return type:

InitialBudgetResponse

get_previous_queries() list[dict][source]

This function retrieves the previous queries of the user.

Raises:

ValueError – If an unknown query type is encountered during deserialization.

Returns:

A list of dictionary containing the different queries on the private dataset.

Return type:

List[dict]

get_remaining_budget() RemainingBudgetResponse[source]

This function retrieves the remaining budget.

Returns:

A dictionary

containing the remaining budget.

Return type:

RemainingBudgetResponse

get_total_spent_budget() SpentBudgetResponse[source]

This function retrieves the total spent budget.

Returns:

A dictionary containing

the total spent budget.

Return type:

SpentBudgetResponse