lomas_server.routes package

Submodules

lomas_server.routes.routes_admin module

lomas_server.routes.routes_admin.get_dataset_metadata(request: Request, query_json: GetDbData = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) JSONResponse[source]

Retrieves metadata for a given dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDbData, optional) – A JSON object containing the dataset_name key for indicating the dataset. Defaults to Body(example_get_admin_db_data).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

Returns:

The metadata dictionary for the specified

dataset_name.

Return type:

JSONResponse

lomas_server.routes.routes_admin.get_dummy_dataset(request: Request, query_json: GetDummyDataset = Body({'dataset_name': 'PENGUIN', 'dummy_nb_rows': 100, 'dummy_seed': 42}), user_name: str = Header(None)) JSONResponse[source]

Generates and returns a dummy dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDummyDataset, optional) –

    A JSON object containing the following:
    • nb_rows (int, optional): The number of rows in the dummy dataset (default: 100).

    • seed (int, optional): The random seed for generating the dummy dataset (default: 42).

    Defaults to Body(example_get_dummy_dataset).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

Returns:

a dict with the dataframe as a dict, the column types

and the list of datetime columns.

Return type:

JSONResponse

lomas_server.routes.routes_admin.get_initial_budget(request: Request, query_json: GetDbData = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) JSONResponse[source]

Returns the initial budget for a user and dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDbData, optional) –

    A JSON object containing: - dataset_name (str): The name of the dataset.

    Defaults to Body(example_get_admin_db_data).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

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

Returns:

a JSON object with:
  • initial_epsilon (float): initial epsilon budget.

  • initial_delta (float): initial delta budget.

Return type:

JSONResponse

lomas_server.routes.routes_admin.get_remaining_budget(request: Request, query_json: GetDbData = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) JSONResponse[source]

Returns the remaining budget for a user and dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDbData, optional) –

    A JSON object containing: - dataset_name (str): The name of the dataset.

    Defaults to Body(example_get_admin_db_data).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

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

Returns:

a JSON object with:
  • remaining_epsilon (float): remaining epsilon budget.

  • remaining_delta (float): remaining delta budget.

Return type:

JSONResponse

async lomas_server.routes.routes_admin.get_state(request: Request, user_name: str = Header(None)) JSONResponse[source]

Returns the current state dict of this server instance.

Parameters:
  • request (Request) – Raw request object

  • user_name (str, optional) – The user name. Defaults to Header(None).

Returns:

The state of the server instance.

Return type:

JSONResponse

lomas_server.routes.routes_admin.get_total_spent_budget(request: Request, query_json: GetDbData = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) JSONResponse[source]

Returns the spent budget for a user and dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDbData, optional) –

    A JSON object containing: - dataset_name (str): The name of the dataset.

    Defaults to Body(example_get_admin_db_data).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

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

Returns:

a JSON object with:
  • total_spent_epsilon (float): total spent epsilon budget.

  • total_spent_delta (float): total spent delta budget.

Return type:

JSONResponse

lomas_server.routes.routes_admin.get_user_previous_queries(request: Request, query_json: GetDbData = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) JSONResponse[source]

Returns the query history of a user on a specific dataset.

Parameters:
  • request (Request) – Raw request object

  • query_json (GetDbData, optional) –

    A JSON object containing: - dataset_name (str): The name of the dataset.

    Defaults to Body(example_get_admin_db_data).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

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

Returns:

A JSON object containing:
  • previous_queries (list[dict]): a list of dictionaries containing the previous queries.

Return type:

JSONResponse

async lomas_server.routes.routes_admin.root()[source]

Redirect root endpoint to the state endpoint :returns: The state of the server instance. :rtype: JSONResponse

lomas_server.routes.routes_dp module

lomas_server.routes.routes_dp.diffprivlib_query_handler(request: Request, query_json: DiffPrivLibQueryModel = Body({'dataset_name': 'PENGUIN', 'diffprivlib_json': '{"module": "diffprivlib", "version": "0.6.4", "pipeline": [{"type": "_dpl_type:StandardScaler", "name": "scaler", "params": {"with_mean": true, "with_std": true, "copy": true, "epsilon": 0.5, "bounds": {"_tuple": true, "_items": [[30.0, 13.0, 150.0, 2000.0], [65.0, 23.0, 250.0, 7000.0]]}, "random_state": null, "accountant": "_dpl_instance:BudgetAccountant"}}, {"type": "_dpl_type:LogisticRegression", "name": "classifier", "params": {"tol": 0.0001, "C": 1.0, "fit_intercept": true, "random_state": null, "max_iter": 100, "verbose": 0, "warm_start": false, "n_jobs": null, "epsilon": 1.0, "data_norm": 83.69469642643347, "accountant": "_dpl_instance:BudgetAccountant"}}]}', 'feature_columns': ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'target_columns': ['species'], 'test_size': 0.2, 'test_train_split_seed': 4, 'imputer_strategy': 'drop'}), user_name: str = Header(None))[source]

Handles queries for the DiffPrivLib Library.

Parameters:
  • request (Request) – Raw request object.

  • query_json (DiffPrivLibQueryModel, optional) –

    A JSON object containing the following:
    • pipeline: The DiffPrivLib pipeline for the query.

    • feature_columns: the list of feature column to train

    • target_columns: the list of target column to predict

    • test_size: proportion of the test set

    • test_train_split_seed: seed for the random train test split,

    • imputer_strategy: imputation strategy

    Defaults to Body(example_diffprivlib).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The pipeline does not contain a “measurement”, there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

lomas_server.routes.routes_dp.dummy_diffprivlib_query_handler(request: Request, query_json: DiffPrivLibDummyQueryModel = Body({'dataset_name': 'PENGUIN', 'diffprivlib_json': '{"module": "diffprivlib", "version": "0.6.4", "pipeline": [{"type": "_dpl_type:StandardScaler", "name": "scaler", "params": {"with_mean": true, "with_std": true, "copy": true, "epsilon": 0.5, "bounds": {"_tuple": true, "_items": [[30.0, 13.0, 150.0, 2000.0], [65.0, 23.0, 250.0, 7000.0]]}, "random_state": null, "accountant": "_dpl_instance:BudgetAccountant"}}, {"type": "_dpl_type:LogisticRegression", "name": "classifier", "params": {"tol": 0.0001, "C": 1.0, "fit_intercept": true, "random_state": null, "max_iter": 100, "verbose": 0, "warm_start": false, "n_jobs": null, "epsilon": 1.0, "data_norm": 83.69469642643347, "accountant": "_dpl_instance:BudgetAccountant"}}]}', 'feature_columns': ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'target_columns': ['species'], 'test_size': 0.2, 'test_train_split_seed': 4, 'imputer_strategy': 'drop', 'dummy_nb_rows': 100, 'dummy_seed': 42}), user_name: str = Header(None))[source]

Handles queries on dummy datasets for the DiffPrivLib library.

Parameters:
  • request (Request) – Raw request object.

  • query_json (DiffPrivLibDummyQueryModel, optional) –

    A JSON object containing the following:
    • pipeline: The DiffPrivLib pipeline for the query.

    • feature_columns: the list of feature column to train

    • target_columns: the list of target column to predict

    • test_size: proportion of the test set

    • test_train_split_seed: seed for the random train test split,

    • imputer_strategy: imputation strategy

    • nb_rows (int, optional): The number of rows in the dummy dataset (default: 100).

    • seed (int, optional): The random seed for generating

    the dummy dataset (default: 42).

    Defaults to Body(example_dummy_diffprivlib)

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

Returns:

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

Return type:

JSONResponse

lomas_server.routes.routes_dp.dummy_opendp_query_handler(request: Request, query_json: OpenDPDummyQueryModel = Body({'dataset_name': 'PENGUIN', 'opendp_json': '{"version": "0.10.0", "ast": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "constructor", "func": "make_chain_tt", "module": "combinators", "args": [{"_type": "constructor", "func": "make_select_column", "module": "transformations", "kwargs": {"key": "bill_length_mm", "TOA": "String"}}, {"_type": "constructor", "func": "make_split_dataframe", "module": "transformations", "kwargs": {"separator": ",", "col_names": {"_type": "list", "_items": ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "sex"]}}}]}, "rhs": {"_type": "constructor", "func": "then_cast_default", "module": "transformations", "kwargs": {"TOA": "f64"}}}, "rhs": {"_type": "constructor", "func": "then_clamp", "module": "transformations", "kwargs": {"bounds": [30.0, 65.0]}}}, "rhs": {"_type": "constructor", "func": "then_resize", "module": "transformations", "kwargs": {"size": 346, "constant": 43.61}}}, "rhs": {"_type": "constructor", "func": "then_variance", "module": "transformations"}}, "rhs": {"_type": "constructor", "func": "then_laplace", "module": "measurements", "kwargs": {"scale": 5.0}}}}', 'fixed_delta': 1e-05, 'dummy_nb_rows': 100, 'dummy_seed': 42}), user_name: str = Header(None)) JSONResponse[source]

Handles queries on dummy datasets for the OpenDP library.

Parameters:
  • request (Request) – Raw request object.

  • query_json (OpenDPDummyQueryModel, optional) –

    A JSON object containing the following: - opendp_pipeline: The OpenDP pipeline for the query. - fixed_delta: If the pipeline measurement is of type “ZeroConcentratedDivergence” (e.g. with “make_gaussian”) then

    it is converted to “SmoothedMaxDivergence” with “make_zCDP_to_approxDP” (see opendp measurements documentation at https://docs.opendp.org/en/stable/api/python/opendp.combinators.html#opendp.combinators.make_zCDP_to_approxDP). # noqa # pylint: disable=C0301 In that case a “fixed_delta” must be provided by the user.

    • nb_rows (int, optional): The number of rows in the dummy dataset (default: 100).

    • seed (int, optional): The random seed for generating the dummy dataset (default: 42).

    Defaults to Body(example_dummy_opendp).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

Returns:

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

Return type:

JSONResponse

lomas_server.routes.routes_dp.dummy_smartnoise_sql_handler(request: Request, query_json: SmartnoiseSQLDummyQueryModel = Body({'query_str': 'SELECT COUNT(*) AS NB_ROW FROM df', 'dataset_name': 'PENGUIN', 'epsilon': 0.1, 'delta': 1e-05, 'mechanisms': {'count': 'gaussian'}, 'postprocess': True, 'dummy_nb_rows': 100, 'dummy_seed': 42}), user_name: str = Header(None)) JSONResponse[source]

Handles queries on dummy datasets for the SmartNoiseSQL library.

Parameters:
  • request (Request) – Raw request object

  • query_json (DummySmartnoiseSQLModel, optional) –

    A JSON object containing: - query: The SQL query to execute. NOTE: the table name is “df”,

    the query must end with “FROM df”.

    • epsilon (float): Privacy parameter (e.g., 0.1).

    • delta (float): Privacy parameter (e.g., 1e-5).

    • mechanisms (dict, optional): Dictionary of mechanisms for the query (default: {}). See Smartnoise-SQL mechanisms documentation https://docs.smartnoise.org/sql/advanced.html#overriding-mechanisms.

    • postprocess (bool, optional): Whether to postprocess the query results (default: True). See Smartnoise-SQL postprocessing documentation https://docs.smartnoise.org/sql/advanced.html#postprocess.

    • nb_rows (int, optional): The number of rows in the dummy dataset (default: 100).

    • seed (int, optional): The random seed for generating the dummy dataset (default: 42).

    Defaults to Body(example_dummy_smartnoise_sql).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

Returns:

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

Return type:

JSONResponse

lomas_server.routes.routes_dp.dummy_smartnoise_synth_handler(request: ~starlette.requests.Request, query_json: ~lomas_server.utils.query_models.SmartnoiseSynthDummyQueryModel = Body({'dataset_name': 'PENGUIN', 'synth_name': <SSynthGanSynthesizer.DP_CTGAN: 'dpctgan'>, 'epsilon': 0.1, 'delta': 1e-05, 'select_cols': [], 'synth_params': {'embedding_dim': 128, 'batch_size': 50, 'epochs': 5}, 'nullable': True, 'constraints': '', 'return_model': True, 'condition': '', 'nb_samples': 200, 'dummy_nb_rows': 100, 'dummy_seed': 42}), user_name: str = Header(None)) JSONResponse[source]

Handles queries for the SmartNoise Synth library. :param request: Raw request object :type request: Request :param query_json: A JSON object containing:

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

  • epsilon (float): Privacy parameter (e.g., 0.1).

  • delta (float): Privacy parameter (e.g., 1e-5).

    mechanisms (dict[str, str], optional): Dictionary of mechanisms for the query See Smartnoise-SQL postprocessing documentation.

  • select_cols (List[str]): List of columns to select.

  • synth_params (dict): Keyword arguments to pass to the synthesizer

    constructor. See https://docs.smartnoise.org/synth/synthesizers/index.html#, provide all parameters of the model except epsilon and delta.

  • nullable (bool): True if some data cells may be null

  • constraints (dict): Dictionnary for custom table transformer constraints.

    Column that are not specified will be inferred based on metadata.

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

  • condition (Optional[str]): sampling condition in model.sample

    (only relevant if return_model is False)

  • nb_samples (Optional[int]): number of samples to generate.

    (only relevant if return_model is False)

  • nb_rows (int, optional): The number of rows in the dummy dataset (default: 100).

  • seed (int, optional): The random seed for generating the dummy dataset (default: 42).

Defaults to Body(example_smartnoise_synth).

Parameters:

user_name (str) – The user name.

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

lomas_server.routes.routes_dp.estimate_diffprivlib_cost(request: Request, query_json: DiffPrivLibRequestModel = Body({'dataset_name': 'PENGUIN', 'diffprivlib_json': '{"module": "diffprivlib", "version": "0.6.4", "pipeline": [{"type": "_dpl_type:StandardScaler", "name": "scaler", "params": {"with_mean": true, "with_std": true, "copy": true, "epsilon": 0.5, "bounds": {"_tuple": true, "_items": [[30.0, 13.0, 150.0, 2000.0], [65.0, 23.0, 250.0, 7000.0]]}, "random_state": null, "accountant": "_dpl_instance:BudgetAccountant"}}, {"type": "_dpl_type:LogisticRegression", "name": "classifier", "params": {"tol": 0.0001, "C": 1.0, "fit_intercept": true, "random_state": null, "max_iter": 100, "verbose": 0, "warm_start": false, "n_jobs": null, "epsilon": 1.0, "data_norm": 83.69469642643347, "accountant": "_dpl_instance:BudgetAccountant"}}]}', 'feature_columns': ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g'], 'target_columns': ['species'], 'test_size': 0.2, 'test_train_split_seed': 4, 'imputer_strategy': 'drop'}), user_name: str = Header(None))[source]

Estimates the privacy loss budget cost of an DiffPrivLib query.

Parameters:
  • request (Request) – Raw request object

  • query_json (DiffPrivLibRequestModel, optional)

  • following (A JSON object containing the) –

    • pipeline: The DiffPrivLib pipeline for the query.

    • feature_columns: the list of feature column to train

    • target_columns: the list of target column to predict

    • test_size: proportion of the test set

    • test_train_split_seed: seed for the random train test split,

    • imputer_strategy: imputation strategy

    Defaults to Body(example_dummy_diffprivlib).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist or the pipeline does not contain a measurement.

Returns:

A JSON object containing:
  • epsilon_cost (float): The estimated epsilon cost.

  • delta_cost (float): The estimated delta cost.

Return type:

JSONResponse

lomas_server.routes.routes_dp.estimate_opendp_cost(request: Request, query_json: OpenDPRequestModel = Body({'dataset_name': 'PENGUIN', 'opendp_json': '{"version": "0.10.0", "ast": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "constructor", "func": "make_chain_tt", "module": "combinators", "args": [{"_type": "constructor", "func": "make_select_column", "module": "transformations", "kwargs": {"key": "bill_length_mm", "TOA": "String"}}, {"_type": "constructor", "func": "make_split_dataframe", "module": "transformations", "kwargs": {"separator": ",", "col_names": {"_type": "list", "_items": ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "sex"]}}}]}, "rhs": {"_type": "constructor", "func": "then_cast_default", "module": "transformations", "kwargs": {"TOA": "f64"}}}, "rhs": {"_type": "constructor", "func": "then_clamp", "module": "transformations", "kwargs": {"bounds": [30.0, 65.0]}}}, "rhs": {"_type": "constructor", "func": "then_resize", "module": "transformations", "kwargs": {"size": 346, "constant": 43.61}}}, "rhs": {"_type": "constructor", "func": "then_variance", "module": "transformations"}}, "rhs": {"_type": "constructor", "func": "then_laplace", "module": "measurements", "kwargs": {"scale": 5.0}}}}', 'fixed_delta': 1e-05}), user_name: str = Header(None)) JSONResponse[source]

Estimates the privacy loss budget cost of an OpenDP query.

Parameters:
  • request (Request) – Raw request object

  • query_json (OpenDPRequestModel, optional) –

    A JSON object containing the following: - “opendp_pipeline”: The OpenDP pipeline for the query.

    Defaults to Body(example_opendp).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist or the pipeline does not contain a measurement.

Returns:

A JSON object containing:
  • epsilon_cost (float): The estimated epsilon cost.

  • delta_cost (float): The estimated delta cost.

Return type:

JSONResponse

lomas_server.routes.routes_dp.estimate_smartnoise_sql_cost(request: Request, query_json: SmartnoiseSQLRequestModel = Body({'query_str': 'SELECT COUNT(*) AS NB_ROW FROM df', 'dataset_name': 'PENGUIN', 'epsilon': 0.1, 'delta': 1e-05, 'mechanisms': {'count': 'gaussian'}}), user_name: str = Header(None)) JSONResponse[source]

Estimates the privacy loss budget cost of a SmartNoiseSQL query.

Parameters:
  • request (Request) – Raw request object

  • query_json (SmartnoiseSQLRequestModel, optional) –

    A JSON object containing the following: - query: The SQL query to estimate the cost for.

    NOTE: the table name is “df”, the query must end with “FROM df”.

    Defaults to Body(example_smartnoise_sql_cost).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

Returns:

A JSON object containing:
  • epsilon_cost (float): The estimated epsilon cost.

  • delta_cost (float): The estimated delta cost.

Return type:

JSONResponse

lomas_server.routes.routes_dp.estimate_smartnoise_synth_cost(request: ~starlette.requests.Request, query_json: ~lomas_server.utils.query_models.SmartnoiseSynthRequestModel = Body({'dataset_name': 'PENGUIN', 'synth_name': <SSynthGanSynthesizer.DP_CTGAN: 'dpctgan'>, 'epsilon': 0.1, 'delta': 1e-05, 'select_cols': [], 'synth_params': {'embedding_dim': 128, 'batch_size': 50, 'epochs': 5}, 'nullable': True, 'constraints': ''}), user_name: str = Header(None)) JSONResponse[source]

Handles queries for the SmartNoise Synth library. :param request: Raw request object :type request: Request :param query_json: A JSON object containing:

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

  • epsilon (float): Privacy parameter (e.g., 0.1).

  • delta (float): Privacy parameter (e.g., 1e-5).

    mechanisms (dict[str, str], optional): Dictionary of mechanisms for the query See Smartnoise-SQL postprocessing documentation.

  • select_cols (List[str]): List of columns to select.

  • synth_params (dict): Keyword arguments to pass to the synthesizer

    constructor. See https://docs.smartnoise.org/synth/synthesizers/index.html#, provide all parameters of the model except epsilon and delta.

  • nullable (bool): True if some data cells may be null

  • constraints

  • nb_rows (int, optional): The number of rows in the dummy dataset

  • seed (int, optional): The random seed for generating

    the dummy dataset (default: 42).

Defaults to Body(example_smartnoise_synth).

Parameters:

user_name (str) – The user name.

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing:
  • epsilon_cost (float): The estimated epsilon cost.

  • delta_cost (float): The estimated delta cost.

Return type:

JSONResponse

lomas_server.routes.routes_dp.opendp_query_handler(request: Request, query_json: OpenDPQueryModel = Body({'dataset_name': 'PENGUIN', 'opendp_json': '{"version": "0.10.0", "ast": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "partial_chain", "lhs": {"_type": "constructor", "func": "make_chain_tt", "module": "combinators", "args": [{"_type": "constructor", "func": "make_select_column", "module": "transformations", "kwargs": {"key": "bill_length_mm", "TOA": "String"}}, {"_type": "constructor", "func": "make_split_dataframe", "module": "transformations", "kwargs": {"separator": ",", "col_names": {"_type": "list", "_items": ["species", "island", "bill_length_mm", "bill_depth_mm", "flipper_length_mm", "body_mass_g", "sex"]}}}]}, "rhs": {"_type": "constructor", "func": "then_cast_default", "module": "transformations", "kwargs": {"TOA": "f64"}}}, "rhs": {"_type": "constructor", "func": "then_clamp", "module": "transformations", "kwargs": {"bounds": [30.0, 65.0]}}}, "rhs": {"_type": "constructor", "func": "then_resize", "module": "transformations", "kwargs": {"size": 346, "constant": 43.61}}}, "rhs": {"_type": "constructor", "func": "then_variance", "module": "transformations"}}, "rhs": {"_type": "constructor", "func": "then_laplace", "module": "measurements", "kwargs": {"scale": 5.0}}}}', 'fixed_delta': 1e-05}), user_name: str = Header(None)) JSONResponse[source]

Handles queries for the OpenDP Library.

Parameters:
  • request (Request) – Raw request object.

  • query_json (OpenDPQueryModel, optional) –

    A JSON object containing the following: - opendp_pipeline: The OpenDP pipeline for the query. - fixed_delta: If the pipeline measurement is of type

    ”ZeroConcentratedDivergence” (e.g. with “make_gaussian”) then it is converted to “SmoothedMaxDivergence” with “make_zCDP_to_approxDP” (see “opendp measurements documentation at https://docs.opendp.org/en/stable/api/python/opendp.combinators.html#opendp.combinators.make_zCDP_to_approxDP). # noqa # pylint: disable=C0301 In that case a “fixed_delta” must be provided by the user.

    Defaults to Body(example_opendp).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The pipeline does not contain a “measurement”, there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

lomas_server.routes.routes_dp.smartnoise_sql_handler(request: Request, query_json: SmartnoiseSQLQueryModel = Body({'query_str': 'SELECT COUNT(*) AS NB_ROW FROM df', 'dataset_name': 'PENGUIN', 'epsilon': 0.1, 'delta': 1e-05, 'mechanisms': {'count': 'gaussian'}, 'postprocess': True}), user_name: str = Header(None)) JSONResponse[source]

Handles queries for the SmartNoiseSQL library.

Parameters:
  • request (Request) – Raw request object

  • query_json (SmartnoiseSQLModel) –

    A JSON object containing: - query: The SQL query to execute. NOTE: the table name is “df”,

    the query must end with “FROM df”.

    Defaults to Body(example_smartnoise_sql).

  • user_name (str, optional) – The user name. Defaults to Header(None).

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

lomas_server.routes.routes_dp.smartnoise_synth_handler(request: ~starlette.requests.Request, query_json: ~lomas_server.utils.query_models.SmartnoiseSynthQueryModel = Body({'dataset_name': 'PENGUIN', 'synth_name': <SSynthGanSynthesizer.DP_CTGAN: 'dpctgan'>, 'epsilon': 0.1, 'delta': 1e-05, 'select_cols': [], 'synth_params': {'embedding_dim': 128, 'batch_size': 50, 'epochs': 5}, 'nullable': True, 'constraints': '', 'return_model': True, 'condition': '', 'nb_samples': 200}), user_name: str = Header(None)) JSONResponse[source]

Handles queries for the SmartNoise Synth library. :param request: Raw request object :type request: Request :param query_json: A JSON object containing:

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

  • epsilon (float): Privacy parameter (e.g., 0.1).

  • delta (float): Privacy parameter (e.g., 1e-5).

    mechanisms (dict[str, str], optional): Dictionary of mechanisms for the query See Smartnoise-SQL postprocessing documentation.

  • select_cols (List[str]): List of columns to select.

  • synth_params (dict): Keyword arguments to pass to the synthesizer

    constructor. See https://docs.smartnoise.org/synth/synthesizers/index.html#, provide all parameters of the model except epsilon and delta.

  • nullable (bool): True if some data cells may be null

  • constraints (dict): Dictionnary for custom table transformer constraints.

    Column that are not specified will be inferred based on metadata.

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

  • condition (Optional[str]): sampling condition in model.sample

    (only relevant if return_model is False)

  • nb_samples (Optional[int]): number of samples to generate.

    (only relevant if return_model is False)

  • Defaults to Body(example_smartnoise_synth).

Parameters:

user_name (str) – The user name.

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

lomas_server.routes.utils module

lomas_server.routes.utils.handle_cost_query(request: Request, query_json: RequestModel, user_name: str, dp_library: DPLibraries)[source]

Handles cost queries for DP libraries.

Parameters:
  • request (Request) – Raw request object

  • query_json (BaseModel) – A JSON object containing the user request

  • user_name (str) – The user name

  • dp_library – Name of the DP library to use for the query

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – The dataset does not exist.

Returns:

A JSON object containing:
  • epsilon_cost (float): The estimated epsilon cost.

  • delta_cost (float): The estimated delta cost.

Return type:

JSONResponse

lomas_server.routes.utils.handle_query_on_dummy_dataset(request: Request, query_json: DummyQueryModel, user_name: str, dp_library: DPLibraries)[source]

Handles queries for the SmartNoiseSQL library.

Parameters:
  • request (Request) – Raw request object

  • query_json (BaseModel) – A JSON object containing the user request

  • user_name (str) – The user name

  • dp_library – Name of the DP library to use for the query

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

Returns:

A JSON object containing the query response.

Return type:

JSONResponse

lomas_server.routes.utils.handle_query_on_private_dataset(request: Request, query_json: QueryModel, user_name: str, dp_library: DPLibraries)[source]

Handles queries for the SmartNoiseSQL library.

Parameters:
  • request (Request) – Raw request object

  • query_json (BaseModel) – A JSON object containing the user request

  • user_name (str) – The user name

  • dp_library – Name of the DP library to use for the query

Raises:
  • ExternalLibraryException – For exceptions from libraries external to this package.

  • InternalServerException – For any other unforseen exceptions.

  • InvalidQueryException – If there is not enough budget or the dataset does not exist.

  • UnauthorizedAccessException – A query is already ongoing for this user, the user does not exist or does not have access to the dataset.

Returns:

A JSON object containing the following:
  • 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:

JSONResponse

async lomas_server.routes.utils.server_live(request: Request) AsyncGenerator[source]

Checks the server is live and throws an exception otherwise.

Parameters:

request (Request) – Raw request

Raises:

InternalServerException – If the server is not live.

Returns:

AsyncGenerator

Module contents