lomas_server.routes package
Submodules
lomas_server.routes.routes_admin module
- lomas_server.routes.routes_admin.get_dataset_metadata(request: Request, query_json: LomasRequestModel = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) Metadata [source]
Retrieves metadata for a given dataset.
- Parameters:
request (Request) – Raw request object
query_json (LomasRequestModel, 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 object for the specified
dataset_name.
- Return type:
- 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)) DummyDsResponse [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: LomasRequestModel = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) InitialBudgetResponse [source]
Returns the initial budget for a user and dataset.
- Parameters:
request (Request) – Raw request object
query_json (LomasRequestModel, 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: LomasRequestModel = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) RemainingBudgetResponse [source]
Returns the remaining budget for a user and dataset.
- Parameters:
request (Request) – Raw request object
query_json (LomasRequestModel, 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: LomasRequestModel = Body({'dataset_name': 'PENGUIN'}), user_name: str = Header(None)) SpentBudgetResponse [source]
Returns the spent budget for a user and dataset.
- Parameters:
request (Request) – Raw request object
query_json (LomasRequestModel, 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: LomasRequestModel = 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 (LomasRequestModel, 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
lomas_server.routes.routes_dp module
- lomas_server.routes.routes_dp.diffprivlib_query_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, diffprivlib_query: DiffPrivLibQueryModel)[source]
Handles queries for the DiffPrivLib Library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
diffprivlib_query (DiffPrivLibQueryModel) – The diffprivlib query body.
- 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 query response containing a DiffPrivLibQueryResult.
- Return type:
- lomas_server.routes.routes_dp.dummy_diffprivlib_query_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, query_json: DiffPrivLibDummyQueryModel) QueryResponse [source]
Handles queries on dummy datasets for the DiffPrivLib library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
diffprivlib_query (DiffPrivLibDummyQueryModel) – The diffprivlib query body.
- 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 query response containing a DiffPrivLibQueryResult.
- Return type:
- lomas_server.routes.routes_dp.dummy_opendp_query_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, opendp_query: OpenDPDummyQueryModel) QueryResponse [source]
Handles queries on dummy datasets for the OpenDP library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object.
opendp_query (OpenDPQueryModel) – The opendp query object.
- 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 query response containing an OpenDPQueryResult.
- Return type:
- lomas_server.routes.routes_dp.dummy_smartnoise_sql_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_sql_query: SmartnoiseSQLDummyQueryModel) QueryResponse [source]
Handles queries on dummy datasets for the SmartNoiseSQL library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_sql_query (SmartnoiseSQLDummyQueryModel) – The smartnoise_sql query body.
- 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 query response containing a SmartnoiseSQLQueryResult.
- Return type:
- lomas_server.routes.routes_dp.dummy_smartnoise_synth_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_synth_query: SmartnoiseSynthDummyQueryModel) QueryResponse [source]
Handles queries on dummy datasets for the SmartNoiseSynth library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_synth_query (SmartnoiseSynthDummyQueryModel) – The smartnoise_synth query body.
- 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 query response containing a SmartnoiseSynthModel or SmartnoiseSynthSamples.
- Return type:
- lomas_server.routes.routes_dp.estimate_diffprivlib_cost(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, diffprivlib_query: DiffPrivLibRequestModel) CostResponse [source]
Estimates the privacy loss budget cost of an DiffPrivLib query.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
diffprivlib_query (DiffPrivLibRequestModel) – The diffprivlib query body.
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 – 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:
The privacy loss cost of the input query.
- Return type:
- lomas_server.routes.routes_dp.estimate_opendp_cost(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, opendp_query: OpenDPRequestModel) CostResponse [source]
Estimates the privacy loss budget cost of an OpenDP query.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object.
opendp_query (OpenDPRequestModel) – The opendp query object.
- 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:
The privacy loss cost of the input query.
- Return type:
- lomas_server.routes.routes_dp.estimate_smartnoise_sql_cost(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_sql_query: SmartnoiseSQLRequestModel) CostResponse [source]
Estimates the privacy loss budget cost of a SmartNoiseSQL query.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_sql_query (SmartnoiseSQLRequestModel) – The smartnoise_sql request body.
- Raises:
ExternalLibraryException – For exceptions from libraries external to this package.
InternalServerException – For any other unforseen exceptions.
InvalidQueryException – 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:
The privacy loss cost of the input query.
- Return type:
- lomas_server.routes.routes_dp.estimate_smartnoise_synth_cost(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_synth_query: SmartnoiseSynthRequestModel) CostResponse [source]
Computes the privacy loss budget cost of a SmartNoiseSynth query.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_synth_query (SmartnoiseSynthRequestModel) – The smartnoise_synth query body.
- 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:
The privacy loss cost of the input query.
- Return type:
- lomas_server.routes.routes_dp.opendp_query_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, opendp_query: OpenDPQueryModel) QueryResponse [source]
Handles queries for the OpenDP Library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object.
opendp_query (OpenDPQueryModel) – The opendp query object.
- 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 query response containing an OpenDPQueryResult.
- Return type:
- lomas_server.routes.routes_dp.smartnoise_sql_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_sql_query: SmartnoiseSQLQueryModel) QueryResponse [source]
Handles queries for the SmartNoiseSQL library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_sql_query (SmartnoiseSQLQueryModel) – The smartnoise_sql query body.
- 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 query response containing a SmartnoiseSQLQueryResult.
- Return type:
- lomas_server.routes.routes_dp.smartnoise_synth_handler(user_name: Annotated[str, Header(PydanticUndefined)], request: Request, smartnoise_synth_query: SmartnoiseSynthQueryModel) QueryResponse [source]
Handles queries for the SmartNoiseSynth library.
- Parameters:
user_name (str) – The user name.
request (Request) – Raw request object
smartnoise_synth_query (SmartnoiseSynthQueryModel) – The smartnoise_synth query body.
- 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 query response containing a SmartnoiseSynthModel or SmartnoiseSynthSamples.
- Return type:
lomas_server.routes.utils module
- lomas_server.routes.utils.handle_cost_query(request: Request, request_model: LomasRequestModel, user_name: str, dp_library: DPLibraries) CostResponse [source]
Handles cost queries for DP libraries.
- Parameters:
request (Request) – Raw request object
request_model (LomasRequestModel) – An instance of LomasRequestModel, specific to the library.
user_name (str) – The user name
dp_library (DPLibraries) – Name of the DP library to use for the request
- 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 cost response containing the epsilon and delta
privacy-loss budget cost for the request.
- Return type:
- lomas_server.routes.utils.handle_query_on_dummy_dataset(request: Request, query_model: DummyQueryModel, user_name: str, dp_library: DPLibraries) QueryResponse [source]
Handles queries on dummy datasets for all supported libraries.
- Parameters:
request (Request) – Raw request object
query_model (DummyQueryModel) – An instance of DummyQueryModel, specific to the library.
user_name (str) – The user name
dp_library (DPLibraries) – Name of the DP library to use for the request
- 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 QueryResponse model containing the result of the query
(specific to the library) as well as the cost of such a query if it was executed on a private dataset.
- Return type:
- lomas_server.routes.utils.handle_query_on_private_dataset(request: Request, query_json: QueryModel, user_name: str, dp_library: DPLibraries) QueryResponse [source]
Handles queries on private datasets for all supported libraries.
- Parameters:
request (Request) – Raw request object
query_model (DummyQueryModel) – An instance of DummyQueryModel, specific to the library.
user_name (str) – The user name
dp_library (DPLibraries) – Name of the DP library to use for the request
- 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 QueryResponse model containing the result of the query
(specific to the library) as well as the cost of the query.
- Return type:
- 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