lomas_server.dp_queries package

Subpackages

Submodules

lomas_server.dp_queries.dp_querier module

class lomas_server.dp_queries.dp_querier.DPQuerier(data_connector: DataConnector, admin_database: AdminDatabase)[source]

Bases: ABC, Generic[RequestModelGeneric, QueryModelGeneric]

Abstract Base Class for Queriers to external DP library.

A querier type is specific to a DP library and a querier instance is specific to a DataConnector instance.

abstract cost(query_json: RequestModelGeneric) tuple[float, float][source]

Estimate cost of query.

Parameters:

query_json (RequestModelGeneric) – The input object of the request. Must be a subclass of RequestModel.

Returns:

The tuple of costs, the first value is

the epsilon cost, the second value is the delta value.

Return type:

tuple[float, float]

handle_query(query_json: QueryModel, user_name: str) dict[source]

Handle DP query.

Parameters:
  • query_json (RequestModel) – The input object of the query. Must be a subclass of QueryModel.

  • user_name (str, optional) – User name.

Raises:
  • UnauthorizedAccessException – A query is already ongoing for this user,

  • the user does not exist or does not have access to the dataset.

  • InvalidQueryException – If the query is not valid.

  • InternalServerException – For any other unforseen exceptions.

Returns:

A dictionary containing:
  • requested_by (str): The user name.

  • query_response (pd.DataFrame): A DataFrame containing the query response.

  • spent_epsilon (float): The amount of epsilon budget spent

for the query. - spent_delta (float): The amount of delta budget spent

for the query.

Return type:

dict

abstract query(query_json: QueryModelGeneric) dict | int | float | List[Any] | Any | str[source]

Perform the query and return the response.

Parameters:

query_json (QueryModelGeneric) – The input object of the query. Must be a subclass of QueryModel.

Returns:

The query result, to be added to the response dict.

Return type:

dict | int | float | List[Any] | Any | str

lomas_server.dp_queries.dummy_dataset module

lomas_server.dp_queries.dummy_dataset.get_dummy_dataset_for_query(admin_database: AdminDatabase, query_json: RequestModel) InMemoryConnector[source]

Get a dummy dataset for a given query.

Parameters:
  • admin_database (AdminDatabase) – An initialized instance of AdminDatabase.

  • query_json (RequestModel) – The request object for the query.

Returns:

An in memory dummy dataset instance.

Return type:

InMemoryConnector

lomas_server.dp_queries.dummy_dataset.make_dummy_dataset(metadata: Metadata, nb_rows: int = 100, seed: int = 42) DataFrame[source]

Create a dummy dataset based on a metadata dictionnary

Parameters:
  • metadata (Metadata) – The metadata model for the real dataset.

  • nb_rows (int, optional) – _description_. Defaults to DUMMY_NB_ROWS.

  • seed (int, optional) – _description_. Defaults to DUMMY_SEED.

Raises:

InternalServerException – If any unknown column type occurs.

Returns:

dummy dataframe based on metadata

Return type:

pd.DataFrame

Module contents