Server
Classes:
-
AdminDatabase–Overall database management for server state.
Functions:
-
user_must_exist–Decorator function to verify that a user exists.
-
dataset_must_exist–Decorator function to verify that a dataset exists.
-
user_must_have_access_to_dataset–Decorator function to enforce a user has access to a dataset.
AdminDatabase
#
flowchart TD
lomas_server.admin_database.admin_database.AdminDatabase[AdminDatabase]
click lomas_server.admin_database.admin_database.AdminDatabase href "" "lomas_server.admin_database.admin_database.AdminDatabase"
Overall database management for server state.
-
API Reference
Server
authorize_user
Methods:
-
does_user_exist–Checks if user exist in the database.
-
does_dataset_exist–Checks if dataset exist in the database.
-
get_dataset_metadata–Returns the metadata dictionnary of the dataset.
-
is_user_admin–Returns true if the user is an admin.
-
set_may_user_query–Sets if a user may query the server..
-
get_and_set_may_user_query–Atomic operation to check and set if the user may query the server.
-
has_user_access_to_dataset–Checks if a user may access a particular dataset.
-
get_epsilon_or_delta–Get the total spent epsilon or delta by user on dataset.
-
get_total_spent_budget–Get the total spent epsilon and delta spent by user on dataset.
-
get_initial_budget–Get the initial epsilon and delta budget.
-
get_remaining_budget–Get the remaining epsilon and delta budget (initial - total spent).
-
update_epsilon_or_delta–Update current budget spent by user with spent budget.
-
update_epsilon–Update spent epsilon by user with total spent epsilon.
-
update_delta–Update spent delta spent by user with spent delta of the user.
-
update_budget–Update current epsilon and delta delta spent by user.
-
get_dataset–Get dataset access info based on dataset_name.
-
get_user_previous_queries–Retrieves and return the queries already done by a user.
-
prepare_save_query–Prepare the query to save in archives.
-
save_query–Save queries of user on datasets in a separate collection (table).
-
wipe–Wipe the entire Database.
does_user_exist
abstractmethod
#
Checks if user exist in the database.
Parameters:
Returns:
-
bool(bool) –True if the user exists, False otherwise.
Source code in server/lomas_server/admin_database/admin_database.py
125 126 127 128 129 130 131 132 133 134 135 | |
does_dataset_exist
abstractmethod
#
does_dataset_exist(dataset_name: str) -> bool
Checks if dataset exist in the database.
Parameters:
Returns:
-
bool(bool) –True if the dataset exists, False otherwise.
Source code in server/lomas_server/admin_database/admin_database.py
137 138 139 140 141 142 143 144 145 146 147 | |
get_dataset_metadata
abstractmethod
#
get_dataset_metadata(dataset_name: str) -> TableMetadata
Returns the metadata dictionnary of the dataset.
Wrapped by dataset_must_exist.
Parameters:
Returns:
-
TableMetadata(TableMetadata) –The metadata object.
Source code in server/lomas_server/admin_database/admin_database.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
is_user_admin
abstractmethod
#
Returns true if the user is an admin.
Parameters:
Returns:
-
bool(bool) –True if the user is a lomas admin.
Source code in server/lomas_server/admin_database/admin_database.py
164 165 166 167 168 169 170 171 172 173 174 175 | |
set_may_user_query
#
Sets if a user may query the server..
(Set False before querying and True after updating budget)
Wrapped by user_must_exist.
Parameters:
Source code in server/lomas_server/admin_database/admin_database.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_and_set_may_user_query
abstractmethod
#
Atomic operation to check and set if the user may query the server.
(Set False before querying and True after updating budget)
Wrapped by user_must_exist.
Parameters:
Returns:
-
bool(bool) –The may_query status of the user before the update.
Source code in server/lomas_server/admin_database/admin_database.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | |
has_user_access_to_dataset
abstractmethod
#
has_user_access_to_dataset(user_name: str, dataset_name: str) -> bool
Checks if a user may access a particular dataset.
Wrapped by user_must_exist.
Parameters:
Returns:
-
bool(bool) –True if the user has access, False otherwise.
Source code in server/lomas_server/admin_database/admin_database.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
get_epsilon_or_delta
abstractmethod
#
get_epsilon_or_delta(user_name: str, dataset_name: str, parameter: BudgetDBKey) -> float
Get the total spent epsilon or delta by user on dataset.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(parameter#str) –Member of BudgetDBKey.
Returns:
-
float(float) –The requested budget value.
Source code in server/lomas_server/admin_database/admin_database.py
226 227 228 229 230 231 232 233 234 235 236 237 238 | |
get_total_spent_budget
#
Get the total spent epsilon and delta spent by user on dataset.
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
get_initial_budget
#
Get the initial epsilon and delta budget.
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
get_remaining_budget
#
Get the remaining epsilon and delta budget (initial - total spent).
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
update_epsilon_or_delta
abstractmethod
#
update_epsilon_or_delta(
user_name: str, dataset_name: str, parameter: BudgetDBKey, spent_value: float
) -> None
Update current budget spent by user with spent budget.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(parameter#str) –One of BudgetDBKey
-
(spent_value#float) –spending of epsilon or delta on last query
Source code in server/lomas_server/admin_database/admin_database.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
update_epsilon
#
update_epsilon(user_name: str, dataset_name: str, spent_epsilon: float) -> None
Update spent epsilon by user with total spent epsilon.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_epsilon#float) –value of epsilon spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
317 318 319 320 321 322 323 324 325 326 | |
update_delta
#
update_delta(user_name: str, dataset_name: str, spent_delta: float) -> None
Update spent delta spent by user with spent delta of the user.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_delta#float) –value of delta spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
328 329 330 331 332 333 334 335 336 337 | |
update_budget
#
update_budget(
user_name: str, dataset_name: str, spent_epsilon: float, spent_delta: float
) -> None
Update current epsilon and delta delta spent by user.
Wrapped by user_must_have_access_to_dataset.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_epsilon#float) –value of epsilon spent on last query
-
(spent_delta#float) –value of delta spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
get_dataset
abstractmethod
#
get_dataset(dataset_name: str) -> DSInfo
Get dataset access info based on dataset_name.
Wrapped by dataset_must_exist.
Parameters:
Returns:
-
Dataset(DSInfo) –The dataset model.
Source code in server/lomas_server/admin_database/admin_database.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 | |
get_user_previous_queries
abstractmethod
#
Retrieves and return the queries already done by a user.
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
Source code in server/lomas_server/admin_database/admin_database.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
prepare_save_query
#
prepare_save_query(
user_name: str, query: LomasRequestModel, response: QueryResponse
) -> dict
Prepare the query to save in archives.
Parameters:
-
(user_name#str) –name of the user
-
(query#LomasRequestModel) –Request object received from client
-
(response#QueryResponse) –Response object sent to client
Raises:
-
InternalServerException–If the type of query is unknown.
Returns:
-
dict(dict) –The query archive dictionary.
Source code in server/lomas_server/admin_database/admin_database.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
save_query
abstractmethod
#
save_query(user_name: str, query: LomasRequestModel, response: QueryResponse) -> None
Save queries of user on datasets in a separate collection (table).
Parameters:
-
(user_name#str) –name of the user
-
(query#LomasRequestModel) –Request object received from client
-
(response#QueryResponse) –Response object sent to client
Source code in server/lomas_server/admin_database/admin_database.py
422 423 424 425 426 427 428 429 430 431 | |
wipe
abstractmethod
#
wipe() -> None
Wipe the entire Database.
Source code in server/lomas_server/admin_database/admin_database.py
433 434 435 | |
user_must_exist
#
user_must_exist(
func: Callable[Concatenate[DB, str, P], T],
) -> Callable[Concatenate[DB, str, P], T]
Decorator function to verify that a user exists.
Parameters:
-
(func#Callable) –Function to be decorated. Wrapped function arguments must include: - args[0] (str): username
Raises:
-
UnauthorizedAccessException–If the user does not exist.
Returns:
-
Callable(Callable[Concatenate[DB, str, P], T]) –Wrapper function that verifies the user exists before calling func.
Source code in server/lomas_server/admin_database/admin_database.py
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 | |
dataset_must_exist
#
dataset_must_exist(
func: Callable[Concatenate[DB, str, P], T],
) -> Callable[Concatenate[DB, str, P], T]
Decorator function to verify that a dataset exists.
Parameters:
-
(func#Callable) –Function to be decorated. Wrapped function arguments must include: - args[0] (str): dataset name
Raises:
-
InvalidQueryException–If the dataset does not exist.
Returns:
-
Callable(Callable[Concatenate[DB, str, P], T]) –Wrapper function that checks if the dataset exists before calling the wrapped function.
-
API Reference
Server
AdminDatabase
Source code in server/lomas_server/admin_database/admin_database.py
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 82 83 84 85 | |
user_must_have_access_to_dataset
#
user_must_have_access_to_dataset(
func: Callable[Concatenate[DB, str, str, P], T],
) -> Callable[Concatenate[DB, str, str, P], T]
Decorator function to enforce a user has access to a dataset.
Parameters:
-
(func#Callable) –Function to be decorated. Wrapped function arguments must include: - args[0] (str): user name - args[1] (str): dataset name
Raises:
-
UnauthorizedAccessException–If the user does not have access to the dataset.
Returns:
-
Callable(Callable[Concatenate[DB, str, str, P], T]) –Wrapper function that checks if the user has access to the dataset before calling the wrapped function.
Source code in server/lomas_server/admin_database/admin_database.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Classes:
-
TopDBKey–Key of the top level collecions.
-
BudgetDBKey–Key for selecting budget values in admin db for given.
TopDBKey
#
flowchart TD
lomas_server.admin_database.constants.TopDBKey[TopDBKey]
click lomas_server.admin_database.constants.TopDBKey href "" "lomas_server.admin_database.constants.TopDBKey"
Key of the top level collecions.
BudgetDBKey
#
flowchart TD
lomas_server.admin_database.constants.BudgetDBKey[BudgetDBKey]
click lomas_server.admin_database.constants.BudgetDBKey href "" "lomas_server.admin_database.constants.BudgetDBKey"
Key for selecting budget values in admin db for given.
dataset and user.
-
API Reference
Server
AdminDatabase
Classes:
-
LocalAdminDatabase–Local Admin database in a single file.
LocalAdminDatabase
#
flowchart TD
lomas_server.admin_database.local_database.LocalAdminDatabase[LocalAdminDatabase]
lomas_server.admin_database.admin_database.AdminDatabase[AdminDatabase]
lomas_server.admin_database.admin_database.AdminDatabase --> lomas_server.admin_database.local_database.LocalAdminDatabase
click lomas_server.admin_database.local_database.LocalAdminDatabase href "" "lomas_server.admin_database.local_database.LocalAdminDatabase"
click lomas_server.admin_database.admin_database.AdminDatabase href "" "lomas_server.admin_database.admin_database.AdminDatabase"
Local Admin database in a single file.
Methods:
-
add_datasets_via_yaml–Set all database types to datasets in dataset collection based.
-
add_dataset–Set a database type to a dataset in dataset collection.
-
add_users_via_yaml–Add all users from yaml file to the user collection.
-
add_user–Add new user in users collection with default values for all fields.
-
set_may_user_query–Sets if a user may query the server..
-
get_total_spent_budget–Get the total spent epsilon and delta spent by user on dataset.
-
get_initial_budget–Get the initial epsilon and delta budget.
-
get_remaining_budget–Get the remaining epsilon and delta budget (initial - total spent).
-
update_epsilon–Update spent epsilon by user with total spent epsilon.
-
update_delta–Update spent delta spent by user with spent delta of the user.
-
update_budget–Update current epsilon and delta delta spent by user.
-
prepare_save_query–Prepare the query to save in archives.
Attributes:
add_datasets_via_yaml
#
add_datasets_via_yaml(
yaml_file: Path | BinaryIO | SpooledTemporaryFile,
clean: bool,
path_prefix: Path = Path(),
) -> None
Set all database types to datasets in dataset collection based.
on yaml file.
Parameters:
-
(yaml_file#Path | BinaryIO | SpooledTemporaryFile) –path to the YAML file location
-
(clean#bool) –Whether to clean the collection before adding.
-
(path_prefix#Path, default:Path()) –Prefix to add to all file paths. Defaults to empty Path.
Raises:
-
ValueError–If there are errors in the YAML file format.
Returns:
-
None–None
Source code in server/lomas_server/admin_database/local_database.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
add_dataset
#
add_dataset(
dataset_name: str,
database_type: str,
metadata_database_type: str,
dataset_path: str | None = "",
metadata_path: str = "",
bucket: str | None = "",
key: str | None = "",
endpoint_url: str | None = "",
credentials_name: str | None = "",
metadata_bucket: str | None = "",
metadata_key: str | None = "",
metadata_endpoint_url: str | None = "",
metadata_access_key_id: str | None = "",
metadata_secret_access_key: str | None = "",
metadata_credentials_name: str | None = "",
) -> None
Set a database type to a dataset in dataset collection.
Parameters:
-
(dataset_name#str) –Dataset name
-
(database_type#str) –Type of the database
-
(metadata_database_type#str) –Metadata database type
-
(dataset_path#str, default:'') –Path to the dataset (for local db type)
-
(metadata_path#str, default:'') –Path to metadata (for local db type)
-
(bucket#str, default:'') –S3 bucket name
-
(key#str, default:'') –S3 key
-
(endpoint_url#str, default:'') –S3 endpoint URL
-
(credentials_name#str, default:'') –The name of the credentials in the server config to retrieve the dataset from S3 storage.
-
(metadata_bucket#str, default:'') –Metadata S3 bucket name
-
(metadata_key#str, default:'') –Metadata S3 key
-
(metadata_endpoint_url#str, default:'') –Metadata S3 endpoint URL
-
(metadata_access_key_id#str, default:'') –Metadata AWS access key ID
-
(metadata_secret_access_key#str, default:'') –Metadata AWS secret access key
-
(metadata_credentials_name#str, default:'') –The name of the credentials in the server config for retrieving the metadata.
Raises:
-
ValueError–If the dataset already exists or if the database type is unknown.
Returns:
-
None–None
Source code in server/lomas_server/admin_database/local_database.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
add_users_via_yaml
#
Add all users from yaml file to the user collection.
Parameters:
-
(yaml_file#Path) –a path to the YAML file location
-
(clean#bool) –boolean flag True if drop current user collection False if keep current user collection
Returns:
-
None–None
Source code in server/lomas_server/admin_database/local_database.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
add_user
#
add_user(
username: str,
email: str,
dataset_name: str | None = None,
epsilon: float = 0.0,
delta: float = 0.0,
) -> None
Add new user in users collection with default values for all fields.
Parameters:
Raises:
-
ValueError–If the username already exists.
-
WriteConcernError–If the result is not acknowledged.
Returns:
-
None–None
Source code in server/lomas_server/admin_database/local_database.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
set_may_user_query
#
Sets if a user may query the server..
(Set False before querying and True after updating budget)
Wrapped by user_must_exist.
Parameters:
Source code in server/lomas_server/admin_database/admin_database.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
get_total_spent_budget
#
Get the total spent epsilon and delta spent by user on dataset.
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
get_initial_budget
#
Get the initial epsilon and delta budget.
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
get_remaining_budget
#
Get the remaining epsilon and delta budget (initial - total spent).
Wrapped by user_must_have_access_to_dataset.
Parameters:
Returns:
-
list[float]–List[float]: The first value of the list is the epsilon value, the second value is the delta value.
Source code in server/lomas_server/admin_database/admin_database.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | |
update_epsilon
#
update_epsilon(user_name: str, dataset_name: str, spent_epsilon: float) -> None
Update spent epsilon by user with total spent epsilon.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_epsilon#float) –value of epsilon spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
317 318 319 320 321 322 323 324 325 326 | |
update_delta
#
update_delta(user_name: str, dataset_name: str, spent_delta: float) -> None
Update spent delta spent by user with spent delta of the user.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_delta#float) –value of delta spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
328 329 330 331 332 333 334 335 336 337 | |
update_budget
#
update_budget(
user_name: str, dataset_name: str, spent_epsilon: float, spent_delta: float
) -> None
Update current epsilon and delta delta spent by user.
Wrapped by user_must_have_access_to_dataset.
Parameters:
-
(user_name#str) –name of the user
-
(dataset_name#str) –name of the dataset
-
(spent_epsilon#float) –value of epsilon spent on last query
-
(spent_delta#float) –value of delta spent on last query
Source code in server/lomas_server/admin_database/admin_database.py
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
prepare_save_query
#
prepare_save_query(
user_name: str, query: LomasRequestModel, response: QueryResponse
) -> dict
Prepare the query to save in archives.
Parameters:
-
(user_name#str) –name of the user
-
(query#LomasRequestModel) –Request object received from client
-
(response#QueryResponse) –Response object sent to client
Raises:
-
InternalServerException–If the type of query is unknown.
Returns:
-
dict(dict) –The query archive dictionary.
Source code in server/lomas_server/admin_database/admin_database.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
Functions:
main
#
main() -> None
Main function for the streamlit lomas dashboard.
Source code in server/lomas_server/administration/dashboard/about.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | |
about
#
about() -> None
About page.
Source code in server/lomas_server/administration/dashboard/about.py
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
Functions:
-
call_if_dex–Gets the Dex config and if it exists, passes it to the provided task.
-
get_datasets–List all datasets available on the server.
-
get_users–List all users available on the server.
-
get_user_df–Get all users into a displayable pandas dataframe.
-
list_users–List all usernames.
call_if_dex
#
call_if_dex(task: Callable[[DexAdminConfig], IOResultE]) -> IOResultE[Maybe[IOResultE]]
Gets the Dex config and if it exists, passes it to the provided task.
Parameters:
-
(task#Callable[[DexAdminConfig], IOResultE]) –The task to run.
Returns:
-
IOResultE[Maybe[IOResultE]]–IOResultE[Maybe[IOResultE]]: An IOFailure if the task returns a failure or the config cannot be read.
Source code in server/lomas_server/administration/dashboard/utils.py
24 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 | |
get_datasets
#
List all datasets available on the server.
Source code in server/lomas_server/administration/dashboard/utils.py
100 101 102 | |
get_users
#
List all users available on the server.
Source code in server/lomas_server/administration/dashboard/utils.py
105 106 107 108 109 | |
get_user_df
#
get_user_df() -> IOResultE[DataFrame]
Get all users into a displayable pandas dataframe.
Source code in server/lomas_server/administration/dashboard/utils.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
Classes:
-
InvalidDexOperation–Groups all exceptions for trying to perform invalid Dex rpcs (e.g. adding a user that already exists).
-
DexRPCError–Groups all Dex rpc errors.
Functions:
-
get_grpc_channel–Returns a valid grpc channel to use as context.
-
hash_pwd–Hashes the password string.
-
to_log–Util function to sanitize user provided strings before logging.
-
add_dex_user–Adds a new user to dex.
-
del_dex_user–Removes the dex user.
-
del_all_dex_users–Removes all dex users.
-
add_dex_users–Adds new lomas users to Dex.
-
add_dex_users_via_yaml–Adds new lomas users to Dex from a YAML file.
-
set_dex_user_password–Sets the new user password to the Dex user.
InvalidDexOperation
#
InvalidDexOperation(error_message: str)
flowchart TD
lomas_server.administration.dex.dex_admin.InvalidDexOperation[InvalidDexOperation]
click lomas_server.administration.dex.dex_admin.InvalidDexOperation href "" "lomas_server.administration.dex.dex_admin.InvalidDexOperation"
Groups all exceptions for trying to perform invalid Dex rpcs (e.g. adding a user that already exists).
Args:description error_message (str): initial error message
- API Reference Server
Source code in server/lomas_server/administration/dex/dex_admin.py
28 29 30 31 32 33 34 | |
DexRPCError
#
DexRPCError(error_message: str)
flowchart TD
lomas_server.administration.dex.dex_admin.DexRPCError[DexRPCError]
click lomas_server.administration.dex.dex_admin.DexRPCError href "" "lomas_server.administration.dex.dex_admin.DexRPCError"
Groups all Dex rpc errors.
Args:description error_message (str): initial error message
Source code in server/lomas_server/administration/dex/dex_admin.py
40 41 42 43 44 45 46 | |
get_grpc_channel
#
get_grpc_channel(dex_config: DexAdminConfig) -> Channel
Returns a valid grpc channel to use as context.
Note: does not support mTLS yet.
Parameters:
-
(dex_config#DexAdminConfig) –The Dex config
Returns:
-
Channel–grpc.Channel: A valid grpc channel.
Source code in server/lomas_server/administration/dex/dex_admin.py
49 50 51 52 53 54 55 56 57 58 59 60 61 | |
hash_pwd
#
Hashes the password string.
repeated Password passwords = 1;
Returns:
-
bytes(bytes) –The password hash.
Source code in server/lomas_server/administration/dex/dex_admin.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 | |
to_log
#
to_log(user_provided_str: str) -> str
Util function to sanitize user provided strings before logging.
Parameters:
Returns:
-
str(str) –The sanitized string.
Source code in server/lomas_server/administration/dex/dex_admin.py
80 81 82 83 84 85 86 87 88 89 | |
add_dex_user
#
add_dex_user(
dex_config: DexAdminConfig, user_name: str, user_email: str, user_password: str
) -> str
Adds a new user to dex.
Parameters:
-
(dex_config#DexAdminConfig) –The DexAdminConfig
-
(user_name#str) –The user name
-
(user_email#str) –The user email
-
(user_password#str) –The user pasword
Raises:
-
InvalidDexOperation–If the user already exists.
-
e–grpc.RpcError
Source code in server/lomas_server/administration/dex/dex_admin.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | |
del_dex_user
#
del_dex_user(dex_config: DexAdminConfig, user_name: str) -> bool
Removes the dex user.
Parameters:
-
(dex_config#DexAdminConfig) –The DexAdminConfig
-
(user_name#str) –The name of the user to remove.
Raises:
-
InvalidDexOperation–If the user does not exist.
-
e–grpc.RpcError
Source code in server/lomas_server/administration/dex/dex_admin.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
del_all_dex_users
#
del_all_dex_users(dex_config: DexAdminConfig) -> None
Removes all dex users.
Parameters:
-
(dex_config#DexAdminConfig) –The DexAdminConfig
Raises:
-
RpcError–If any of the calls to dex fails
Source code in server/lomas_server/administration/dex/dex_admin.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
add_dex_users
#
add_dex_users(
dex_config: DexAdminConfig, user_list: UserCollection, clean: bool, overwrite: bool
) -> list[str]
Adds new lomas users to Dex.
Iterates over user_list and creates password entries in Dex for each user.
If clean is True all existing dex users are removed first. If overwrite
is True (and not clean) any existing dex users with the same username are
removed before creating the new entry.
Parameters:
-
(dex_config#DexAdminConfig) –A DexAdminConfig
-
(user_list#UserCollection) –Collection to load the users from
-
(clean#bool) –Whether to remove existing users and start with a clean state.
-
(overwrite#bool) –Whether to overwrite existing users.
Raises:
-
InvalidDexOperation–If a user does not have a password or the user already exists and should not be overwritten.
-
RpcError–If any of the calls to dex fails
Source code in server/lomas_server/administration/dex/dex_admin.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
add_dex_users_via_yaml
#
add_dex_users_via_yaml(
dex_config: DexAdminConfig, yaml_file: Path, clean: bool, overwrite: bool
) -> IOResultE[list[str]]
Adds new lomas users to Dex from a YAML file.
Parameters:
-
(dex_config#DexAdminConfig) –A DexAdminConfig
-
(yaml_file#Path | BytesIO) –File name to load the users from
-
(clean#bool) –Whether to remove existing users and start with a clean state.
-
(overwrite#bool) –Whether to overwrite existing users.
Source code in server/lomas_server/administration/dex/dex_admin.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
set_dex_user_password
#
set_dex_user_password(
dex_config: DexAdminConfig, user_name: str, new_password: str
) -> bool
Sets the new user password to the Dex user.
Parameters:
-
(dex_config#DexAdminConfig) –The dex admin config.
-
(user_name#str) –The user name for which to change the password.
-
(new_password#str) –The new password to set.
Raises:
-
InvalidDexOperation–If the user does not exist.
-
RpcError–If any of the calls to dex fails
Source code in server/lomas_server/administration/dex/dex_admin.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | |
Classes:
-
DemoAdminConfig–Extension of Admin config for demo setup.
Functions:
-
add_lomas_demo_data–Adds the demo data to the admindb as well as the keycloak instance if required.
-
lomas_demo_setup–Script for setting up demo users and dataset.
DemoAdminConfig
#
flowchart TD
lomas_server.administration.scripts.lomas_demo_setup.DemoAdminConfig[DemoAdminConfig]
lomas_server.models.config.AdminConfig[AdminConfig]
lomas_server.models.config.AdminConfig --> lomas_server.administration.scripts.lomas_demo_setup.DemoAdminConfig
click lomas_server.administration.scripts.lomas_demo_setup.DemoAdminConfig href "" "lomas_server.administration.scripts.lomas_demo_setup.DemoAdminConfig"
click lomas_server.models.config.AdminConfig href "" "lomas_server.models.config.AdminConfig"
Extension of Admin config for demo setup.
-
API Reference
Server
add_lomas_demo_data
add_lomas_demo_data
#
add_lomas_demo_data(config: DemoAdminConfig) -> IOResultE
Adds the demo data to the admindb as well as the keycloak instance if required.
Meant to be used in the develop mode of the service or for testing
Parameters:
-
(config#AdminConfig) –The administration config.
Source code in server/lomas_server/administration/scripts/lomas_demo_setup.py
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 82 83 84 | |
lomas_demo_setup
#
lomas_demo_setup() -> int
Script for setting up demo users and dataset.
Returns:
-
int(int) –the return code used by sys.exit (0 for success 1 or other for failure)
Source code in server/lomas_server/administration/scripts/lomas_demo_setup.py
87 88 89 90 91 92 93 94 95 96 97 98 99 | |
Functions:
-
lifespan–Lifespan function for the server.
lifespan
async
#
lifespan(lomas_app: FastAPI) -> AsyncGenerator[None]
Lifespan function for the server.
This function is executed once on server startup, yields and finishes running at server shutdown.
Server initialization is performed (config loading, etc.) and the server state is updated accordingly. This can have potential side effects on the return values of the "depends" functions, which check the server state.
Source code in server/lomas_server/app.py
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 | |
Classes:
-
FreePassAuthenticator–Authenticator that Bypass Auth.
-
OIDCAuthenticator–Authenticator that identifies users by either validating the provided JWT token querying the userinfo endpoint.
Functions:
-
get_user_id–Extracts user id from bearer token.
-
authorize_user–Raises an UnauthorizedAccessExpection if the user does not have the permission for the given scopes.
FreePassAuthenticator
#
flowchart TD
lomas_server.auth.auth.FreePassAuthenticator[FreePassAuthenticator]
click lomas_server.auth.auth.FreePassAuthenticator href "" "lomas_server.auth.auth.FreePassAuthenticator"
Authenticator that Bypass Auth.
OIDCAuthenticator
#
flowchart TD
lomas_server.auth.auth.OIDCAuthenticator[OIDCAuthenticator]
click lomas_server.auth.auth.OIDCAuthenticator href "" "lomas_server.auth.auth.OIDCAuthenticator"
Authenticator that identifies users by either validating the provided JWT token querying the userinfo endpoint.
Attributes:
-
authentication_type(Literal[OIDC]) –The OpenId connect provider's discovery url.
-
oidc_discovery_url(HttpUrl) –Whether to use the access token to query userinfo endpoint.
-
oidc_config(OIDCConfig) –Returns the oidc provider config.
-
jwk_client(PyJWKClient) –Initializes instance PyJWKClient with caching.
get_user_id
#
get_user_id(
authenticator: AuthenticatorT, security_scopes: SecurityScopes, credentials: str
) -> UserId
Extracts user id from bearer token.
Fails if user does not have scope.
Parameters:
-
(authenticator#AuthenticatorT) –A valid authenticator (FreePassAuthenticator or OIDC Authenticator)
-
(security_scopes#SecurityScopes) –The required scopes for the endpoint.
-
(credentials#str) –Authorization credentials.
Returns:
-
UserId(UserId) –The UserId object containing user infos.
Source code in server/lomas_server/auth/auth.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
authorize_user
#
authorize_user(
user: UserId, admin_database: AdminDatabase, security_scopes: SecurityScopes
) -> None
Raises an UnauthorizedAccessExpection if the user does not have the permission for the given scopes.
Also raises an exception if an unknown scope is required.
Parameters:
-
(user#UserId) –The user id object
-
(admin_database#AdminDatabase) –The admin database to get user permissions from.
-
(security_scopes#SecurityScopes) –The required scopes.
Source code in server/lomas_server/auth/auth.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
Classes:
-
OIDCClaims–OIDC claim names, also used as claim names in JWT token.
-
SSynthTableTransStyle–Transformer style for smartnoise synth.
-
SSynthColumnType–Type of columns for SmartnoiseSynth transformer pre-processing.
-
OpenDPMeasurement–Type of divergence for opendp measurement.
OIDCClaims
#
flowchart TD
lomas_server.constants.OIDCClaims[OIDCClaims]
click lomas_server.constants.OIDCClaims href "" "lomas_server.constants.OIDCClaims"
OIDC claim names, also used as claim names in JWT token.
SSynthTableTransStyle
#
flowchart TD
lomas_server.constants.SSynthTableTransStyle[SSynthTableTransStyle]
click lomas_server.constants.SSynthTableTransStyle href "" "lomas_server.constants.SSynthTableTransStyle"
Transformer style for smartnoise synth.
SSynthColumnType
#
flowchart TD
lomas_server.constants.SSynthColumnType[SSynthColumnType]
click lomas_server.constants.SSynthColumnType href "" "lomas_server.constants.SSynthColumnType"
Type of columns for SmartnoiseSynth transformer pre-processing.
OpenDPMeasurement
#
flowchart TD
lomas_server.constants.OpenDPMeasurement[OpenDPMeasurement]
click lomas_server.constants.OpenDPMeasurement href "" "lomas_server.constants.OpenDPMeasurement"
Type of divergence for opendp measurement.
see https://docs.opendp.org/en/stable/api/python/opendp.measurements.html
Classes:
-
DataConnector–Overall access to sensitive data.
DataConnector
#
flowchart TD
lomas_server.data_connector.data_connector.DataConnector[DataConnector]
click lomas_server.data_connector.data_connector.DataConnector href "" "lomas_server.data_connector.data_connector.DataConnector"
Overall access to sensitive data.
- API Reference Server
Methods:
-
get_pandas_df–Get the data in pandas dataframe format.
-
get_polars_lf–Get the data in polars lazyframe format.
get_pandas_df
abstractmethod
#
get_pandas_df() -> DataFrame
Get the data in pandas dataframe format.
Returns:
-
DataFrame–pd.DataFrame: The pandas dataframe for this dataset.
Source code in server/lomas_server/data_connector/data_connector.py
45 46 47 48 49 50 51 | |
get_polars_lf
#
get_polars_lf() -> LazyFrame
Get the data in polars lazyframe format.
Returns:
-
LazyFrame–pl.LazyFrame: The polars lazyframe for this dataset.
Source code in server/lomas_server/data_connector/data_connector.py
53 54 55 56 57 58 59 | |
Classes:
-
InMemoryConnector–DataConnector for a dataset created from an in-memory pandas DataFrame.
InMemoryConnector
#
flowchart TD
lomas_server.data_connector.in_memory_connector.InMemoryConnector[InMemoryConnector]
lomas_server.data_connector.data_connector.DataConnector[DataConnector]
lomas_server.data_connector.data_connector.DataConnector --> lomas_server.data_connector.in_memory_connector.InMemoryConnector
click lomas_server.data_connector.in_memory_connector.InMemoryConnector href "" "lomas_server.data_connector.in_memory_connector.InMemoryConnector"
click lomas_server.data_connector.data_connector.DataConnector href "" "lomas_server.data_connector.data_connector.DataConnector"
DataConnector for a dataset created from an in-memory pandas DataFrame.
-
API Reference
Server
get_dummy_dataset_for_query
Methods:
-
get_pandas_df–Get the data in pandas dataframe format.
-
get_polars_lf–Get the data in polars lazyframe format.
get_pandas_df
#
get_pandas_df() -> DataFrame
Get the data in pandas dataframe format.
Returns:
-
DataFrame–pd.DataFrame: pandas dataframe of dataset (a copy)
Source code in server/lomas_server/data_connector/in_memory_connector.py
13 14 15 16 17 18 19 20 21 | |
get_polars_lf
#
get_polars_lf() -> LazyFrame
Get the data in polars lazyframe format.
Returns:
-
LazyFrame–pl.LazyFrame: The polars lazyframe for this dataset.
Source code in server/lomas_server/data_connector/data_connector.py
53 54 55 56 57 58 59 | |
Classes:
-
PathConnector–DataConnector for dataset located at constant path.
PathConnector
#
flowchart TD
lomas_server.data_connector.path_connector.PathConnector[PathConnector]
lomas_server.data_connector.data_connector.DataConnector[DataConnector]
lomas_server.data_connector.data_connector.DataConnector --> lomas_server.data_connector.path_connector.PathConnector
click lomas_server.data_connector.path_connector.PathConnector href "" "lomas_server.data_connector.path_connector.PathConnector"
click lomas_server.data_connector.data_connector.DataConnector href "" "lomas_server.data_connector.data_connector.DataConnector"
DataConnector for dataset located at constant path.
Path can be local or remote (http).
Methods:
-
get_pandas_df–Get the data in pandas dataframe format.
-
get_polars_lf–Get the data in polars lazyframe format.
get_pandas_df
#
get_pandas_df() -> DataFrame
Get the data in pandas dataframe format.
Raises:
-
InternalServerException–If the file format is not supported.
Returns:
-
DataFrame–pd.DataFrame: pandas dataframe of dataset
Source code in server/lomas_server/data_connector/path_connector.py
22 23 24 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 | |
get_polars_lf
#
get_polars_lf() -> LazyFrame
Get the data in polars lazyframe format.
Returns:
-
LazyFrame–pl.LazyFrame: The polars lazyframe for this dataset.
Source code in server/lomas_server/data_connector/data_connector.py
53 54 55 56 57 58 59 | |
Classes:
-
S3Connector–DataConnector for dataset in S3 storage.
S3Connector
#
flowchart TD
lomas_server.data_connector.s3_connector.S3Connector[S3Connector]
lomas_server.data_connector.data_connector.DataConnector[DataConnector]
lomas_server.data_connector.data_connector.DataConnector --> lomas_server.data_connector.s3_connector.S3Connector
click lomas_server.data_connector.s3_connector.S3Connector href "" "lomas_server.data_connector.s3_connector.S3Connector"
click lomas_server.data_connector.data_connector.DataConnector href "" "lomas_server.data_connector.data_connector.DataConnector"
DataConnector for dataset in S3 storage.
Methods:
-
get_pandas_df–Get the data in pandas dataframe format.
-
get_polars_lf–Get the data in polars lazyframe format.
get_pandas_df
#
get_pandas_df() -> DataFrame
Get the data in pandas dataframe format.
Raises:
-
InternalServerException–If the dataset cannot be read.
Returns:
-
DataFrame–pd.DataFrame: pandas dataframe of dataset
Source code in server/lomas_server/data_connector/s3_connector.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
get_polars_lf
#
get_polars_lf() -> LazyFrame
Get the data in polars lazyframe format.
Returns:
-
LazyFrame–pl.LazyFrame: The polars lazyframe for this dataset.
Source code in server/lomas_server/data_connector/data_connector.py
53 54 55 56 57 58 59 | |
Classes:
-
DiffPrivLibQuerier–Concrete implementation of the DPQuerier ABC for the DiffPrivLib library.
Functions:
-
split_train_test_data–Split the data between train and test set.
-
get_dpl_bounds–Format metadata bounds of feature columns in format expected by DiffPrivLib.
DiffPrivLibQuerier
#
DiffPrivLibQuerier(data_connector: DataConnector, admin_database: Proxy)
flowchart TD
lomas_server.dp_queries.dp_libraries.diffprivlib.DiffPrivLibQuerier[DiffPrivLibQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier[DPQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier --> lomas_server.dp_queries.dp_libraries.diffprivlib.DiffPrivLibQuerier
click lomas_server.dp_queries.dp_libraries.diffprivlib.DiffPrivLibQuerier href "" "lomas_server.dp_queries.dp_libraries.diffprivlib.DiffPrivLibQuerier"
click lomas_server.dp_queries.dp_querier.DPQuerier href "" "lomas_server.dp_queries.dp_querier.DPQuerier"
Concrete implementation of the DPQuerier ABC for the DiffPrivLib library.
Methods:
-
complete_pipeline–Finalize the DiffPrivLib pipeline by injecting accountant and privacy constraints.
-
fit_model_on_data–Fit the DiffPrivLib pipeline on the dataset provided by the data connector.
-
cost–Estimate the privacy budget cost of running a DiffPrivLib query.
-
query–Run the query on the fitted DiffPrivLib pipeline and return the results.
-
handle_query–Handle DP query.
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
34 35 36 37 38 39 40 41 42 43 | |
complete_pipeline
#
complete_pipeline(feature_columns: list[str], target_columns: list[str] | None) -> None
Finalize the DiffPrivLib pipeline by injecting accountant and privacy constraints.
Steps
- Attach the shared budget accountant to all compatible steps.
- Add metadata-driven privacy constraints (
data_norm,bounds,bounds_X,bounds_y) to the first pipeline step when supported.
Parameters:
-
(feature_columns#list[str]) –List of feature columns used for training.
-
(target_columns#list[str] | None) –Optional list of target columns (required if
bounds_yis needed).
Raises:
-
InternalServerException–If pipeline is not initialized.
-
InvalidQueryException–If target bounds are required but not provided.
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
fit_model_on_data
#
fit_model_on_data(query_json: DiffPrivLibRequestModel) -> None
Fit the DiffPrivLib pipeline on the dataset provided by the data connector.
Steps
- Validate inputs (no overlap between feature and target columns).
- Select and preprocess relevant columns (handle missing data).
- Split data into training and test sets.
- Deserialize the pipeline and inject server parameters.
- Fit the pipeline while treating PrivacyLeakWarning as an error.
Parameters:
-
(query_json#DiffPrivLibRequestModel) –Request object describing feature/target columns, pipeline definition, and preprocessing options.
Raises:
-
InvalidQueryException–If feature/target columns overlap.
-
ExternalLibraryException–If DiffPrivLib fitting fails.
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
cost
#
cost(query_json: DiffPrivLibRequestModel) -> tuple[float, float]
Estimate the privacy budget cost of running a DiffPrivLib query.
Steps
- Fit the model on the dataset (including accountant injection).
- Retrieve the total budget consumed from the accountant.
Parameters:
-
(query_json#DiffPrivLibRequestModel) –The request object describing the query (features, targets, pipeline JSON).
Raises:
-
ExternalLibraryException–If the pipeline fitting fails.
Returns:
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
query
#
Run the query on the fitted DiffPrivLib pipeline and return the results.
Parameters:
-
(query_json#DiffPrivLibQueryModel) –The request object describing the query parameters.
Raises:
-
InternalServerException–If
queryis called beforecost(pipeline not initialized). -
ExternalLibraryException–If the underlying pipeline evaluation fails.
Returns:
-
DiffPrivLibQueryResult–DiffPrivLibQueryResult containing: - score: Model accuracy on the test set. - model: The trained DiffPrivLib pipeline.
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
handle_query
async
#
handle_query(query_json: QueryModel, user_name: str) -> QueryResponse
Handle DP query.
Parameters:
-
(query_json#QueryModel) –The input object of the query.
-
(user_name#str) –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:
-
QueryResponse(QueryResponse) –The response object. # TODO remove what is next. - 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.
Source code in server/lomas_server/dp_queries/dp_querier.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
split_train_test_data
#
split_train_test_data(
df: DataFrame, query_json: DiffPrivLibRequestModel
) -> tuple[DataFrame, DataFrame, DataFrame, DataFrame]
Split the data between train and test set.
Parameters:
-
(df#DataFrame) –dataframe with the data
-
(query_json#DiffPrivLibRequestModel) –user input query indication feature_columns (list[str]): columns from data to use as features target_columns (list[str]): columns from data to use as target (to predict) test_size (float): proportion of data in the test set test_train_split_seed (int): seed for the random train-test split
Returns:
-
x_train(DataFrame) –training data features
-
x_test(DataFrame) –testing data features
-
y_train(DataFrame) –training data target
-
y_test(DataFrame) –testing data target
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
get_dpl_bounds
#
Format metadata bounds of feature columns in format expected by DiffPrivLib.
Parameters:
Return
tuple of lower and upper bounds as expected by DiffPrivLib
Source code in server/lomas_server/dp_queries/dp_libraries/diffprivlib.py
247 248 249 250 251 252 253 254 255 256 257 258 259 | |
Classes:
-
OpenDPQuerier–Concrete implementation of the DPQuerier ABC for the OpenDP library.
Functions:
-
set_opendp_features_config–Enable opendp features based on config.
OpenDPQuerier
#
OpenDPQuerier(data_connector: DataConnector, admin_database: Proxy)
flowchart TD
lomas_server.dp_queries.dp_libraries.opendp.OpenDPQuerier[OpenDPQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier[DPQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier --> lomas_server.dp_queries.dp_libraries.opendp.OpenDPQuerier
click lomas_server.dp_queries.dp_libraries.opendp.OpenDPQuerier href "" "lomas_server.dp_queries.dp_libraries.opendp.OpenDPQuerier"
click lomas_server.dp_queries.dp_querier.DPQuerier href "" "lomas_server.dp_queries.dp_querier.DPQuerier"
Concrete implementation of the DPQuerier ABC for the OpenDP library.
Parameters:
-
(data_connector#DataConnector) –DataConnector for the dataset to query.
Methods:
-
cost–Estimate cost of query.
-
query–Perform the query and return the response.
-
handle_query–Handle DP query.
Source code in server/lomas_server/dp_queries/dp_libraries/opendp.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
cost
#
cost(query_json: OpenDPRequestModel) -> tuple[float, float]
Estimate cost of query.
Parameters:
-
(query_json#OpenDPRequestModel) –The request model 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.
Returns:
-
tuple[float, float]–tuple[float, float]: The tuple of costs, the first value is the epsilon cost, the second value is the delta value.
Source code in server/lomas_server/dp_queries/dp_libraries/opendp.py
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | |
query
#
Perform the query and return the response.
Parameters:
-
(query_json#OpenDPQueryModel) –The input model for the query.
Raises:
-
ExternalLibraryException–For exceptions from libraries external to this package.
Returns:
-
OpenDPQueryResult | OpenDPPolarsQueryResult–(Union[List, int, float]) query result
Source code in server/lomas_server/dp_queries/dp_libraries/opendp.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
handle_query
async
#
handle_query(query_json: QueryModel, user_name: str) -> QueryResponse
Handle DP query.
Parameters:
-
(query_json#QueryModel) –The input object of the query.
-
(user_name#str) –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:
-
QueryResponse(QueryResponse) –The response object. # TODO remove what is next. - 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.
Source code in server/lomas_server/dp_queries/dp_querier.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
set_opendp_features_config
#
set_opendp_features_config(features: OpenDPFeatures) -> None
Enable opendp features based on config.
See https://github.com/opendp/opendp/discussions/304
Also sets the "OPENDP_POLARS_LIB_PATH" environment variable for correctly creating private lazyframes from deserialized polars plans.
Source code in server/lomas_server/dp_queries/dp_libraries/opendp.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
Classes:
-
SmartnoiseSQLQuerier–Concrete implementation of the DPQuerier ABC for the SmartNoiseSQL library.
Functions:
-
set_mechanisms–Set privacy mechanisms on the Privacy object.
-
get_query_columns–Extract all column names used in a SQL query.
SmartnoiseSQLQuerier
#
SmartnoiseSQLQuerier(data_connector: DataConnector, admin_database: Proxy)
flowchart TD
lomas_server.dp_queries.dp_libraries.smartnoise_sql.SmartnoiseSQLQuerier[SmartnoiseSQLQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier[DPQuerier]
lomas_server.dp_queries.dp_querier.DPQuerier --> lomas_server.dp_queries.dp_libraries.smartnoise_sql.SmartnoiseSQLQuerier
click lomas_server.dp_queries.dp_libraries.smartnoise_sql.SmartnoiseSQLQuerier href "" "lomas_server.dp_queries.dp_libraries.smartnoise_sql.SmartnoiseSQLQuerier"
click lomas_server.dp_queries.dp_querier.DPQuerier href "" "lomas_server.dp_queries.dp_querier.DPQuerier"
Concrete implementation of the DPQuerier ABC for the SmartNoiseSQL library.
Methods:
-
cost–Estimate cost of query.
-
query–Performs the query and returns the response.
-
query_with_iter–Perform the query and return the response.
-
handle_query–Handle DP query.
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
25 26 27 28 29 30 31 32 | |
cost
#
cost(query_json: SmartnoiseSQLRequestModel) -> tuple[float, float]
Estimate cost of query.
Parameters:
-
(query_json#SmartnoiseSQLModelCost) –JSON request object for the query.
Raises:
-
ExternalLibraryException–For exceptions from libraries external to this package.
Returns:
-
tuple[float, float]–tuple[float, float]: The tuple of costs, the first value is the epsilon cost, the second value is the delta value.
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
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 | |
query
#
Performs the query and returns the response.
Parameters:
-
(query_json#SmartnoiseSQLQueryModel) –The request model object.
Returns: dict: The dictionary encoding of the result pd.DataFrame.
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
81 82 83 84 85 86 87 88 89 | |
query_with_iter
#
query_with_iter(
query_json: SmartnoiseSQLQueryModel, nb_iter: int = 0
) -> SmartnoiseSQLQueryResult
Perform the query and return the response.
Parameters:
-
(query_json#SmartnoiseSQLQueryModel) –Request object for the query.
-
(nb_iter#int, default:0) –Number of trials if output is Nan. Defaults to 0.
Raises:
-
ExternalLibraryException–For exceptions from libraries external to this package.
-
InvalidQueryException–If the budget values are too small to perform the query.
Returns:
-
SmartnoiseSQLQueryResult(SmartnoiseSQLQueryResult) –The dictionary encoding of the resulting pd.DataFrame.
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
handle_query
async
#
handle_query(query_json: QueryModel, user_name: str) -> QueryResponse
Handle DP query.
Parameters:
-
(query_json#QueryModel) –The input object of the query.
-
(user_name#str) –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:
-
QueryResponse(QueryResponse) –The response object. # TODO remove what is next. - 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.
Source code in server/lomas_server/dp_queries/dp_querier.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
set_mechanisms
#
set_mechanisms(privacy: Privacy, mechanisms: dict[str, str]) -> Privacy
Set privacy mechanisms on the Privacy object.
For more information see: https://docs.smartnoise.org/sql/advanced.html#overriding-mechanisms
Parameters:
Returns:
-
Privacy(Privacy) –The updated Privacy object.
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
get_query_columns
#
Extract all column names used in a SQL query.
Traverses the query AST (Abstract Syntax Tree) to find every column reference across SELECT, WHERE, GROUP BY, ORDER BY, etc. Assumes only one table is present in the query.
Parameters:
Returns:
Source code in server/lomas_server/dp_queries/dp_libraries/smartnoise_sql.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
Functions:
-
handle_missing_data–Impute missing data based on given imputation strategy for NaNs.
handle_missing_data
#
handle_missing_data(df: DataFrame, imputer_strategy: str) -> DataFrame
Impute missing data based on given imputation strategy for NaNs.
Parameters:
-
(df#DataFrame) –dataframe with the data
-
(imputer_strategy#str) –string to indicate imputatation for NaNs "drop": will drop all rows with missing values "mean": will replace values by the mean of the column values "median": will replace values by the median of the column values "most_frequent": : will replace values by the most frequent values
Raises:
-
InvalidQueryException–If the "imputer_strategy" does not exist
Returns:
-
df(DataFrame) –dataframe with the imputed data
Source code in server/lomas_server/dp_queries/dp_libraries/utils.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 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 | |
Classes:
-
DPQuerier–Abstract Base Class for Queriers to external DP library.
DPQuerier
#
DPQuerier(data_connector: DataConnector, admin_database: Proxy)
flowchart TD
lomas_server.dp_queries.dp_querier.DPQuerier[DPQuerier]
click lomas_server.dp_queries.dp_querier.DPQuerier href "" "lomas_server.dp_queries.dp_querier.DPQuerier"
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.
Parameters:
-
(data_connector#DataConnector) –The private dataset to query.
-
(admin_database#Proxy) –A Proxy for an initialized instance of an AdminDatabase.
Methods:
-
cost–Estimate cost of query.
-
query–Perform the query and return the response.
-
handle_query–Handle DP query.
Source code in server/lomas_server/dp_queries/dp_querier.py
35 36 37 38 39 40 41 42 43 44 45 46 47 | |
cost
abstractmethod
#
cost(query_json: RequestModelGeneric) -> tuple[float, float]
Estimate cost of query.
Parameters:
-
(query_json#RequestModelGeneric) –The input object of the request. Must be a subclass of LomasRequestModel.
Returns: tuple[float, float]: The tuple of costs, the first value is the epsilon cost, the second value is the delta value.
Source code in server/lomas_server/dp_queries/dp_querier.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
query
abstractmethod
#
query(query_json: QueryModelGeneric) -> QueryResultGeneric
Perform the query and return the response.
Parameters:
-
(query_json#QueryModelGeneric) –The input object of the query. Must be a subclass of QueryModel.
Returns:
-
QueryResultGeneric–dict | int | float | List[Any] | Any | str: The query result, to be added to the response dict.
Source code in server/lomas_server/dp_queries/dp_querier.py
62 63 64 65 66 67 68 69 70 71 72 73 74 | |
handle_query
async
#
handle_query(query_json: QueryModel, user_name: str) -> QueryResponse
Handle DP query.
Parameters:
-
(query_json#QueryModel) –The input object of the query.
-
(user_name#str) –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:
-
QueryResponse(QueryResponse) –The response object. # TODO remove what is next. - 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.
Source code in server/lomas_server/dp_queries/dp_querier.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
Functions:
-
get_dummy_dataset_for_query–Get a dummy dataset for a given query.
get_dummy_dataset_for_query
async
#
get_dummy_dataset_for_query(
admin_database: Proxy, query_json: DummyQueryModel
) -> InMemoryConnector
Get a dummy dataset for a given query.
Parameters:
-
(admin_database#Proxy) –A Proxy for an initialized instance of an AdminDatabase.
-
(query_json#RequestModel) –The request object for the query.
Returns:
-
InMemoryConnector(InMemoryConnector) –An in memory dummy dataset instance.
Source code in server/lomas_server/dp_queries/dummy_dataset.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | |
Classes:
-
PrivateDBCredentials–BaseModel for private database credentials.
-
S3CredentialsConfig–BaseModel for S3 database credentials.
-
AmqpConfig–BaseSettings for Advanced Message Queuing Protocol (AMQP).
-
DexAdminConfig– -
Server–BaseModel for uvicorn server configs.
-
Config–Server runtime config.
-
AdminConfig–Base model for settings for administrative tasks.
PrivateDBCredentials
#
flowchart TD
lomas_server.models.config.PrivateDBCredentials[PrivateDBCredentials]
click lomas_server.models.config.PrivateDBCredentials href "" "lomas_server.models.config.PrivateDBCredentials"
BaseModel for private database credentials.
-
API Reference
Server
get_dataset_credentials
-
API Reference
Server
get_dataset_credentials
S3CredentialsConfig
#
flowchart TD
lomas_server.models.config.S3CredentialsConfig[S3CredentialsConfig]
lomas_server.models.config.PrivateDBCredentials[PrivateDBCredentials]
lomas_server.models.config.PrivateDBCredentials --> lomas_server.models.config.S3CredentialsConfig
click lomas_server.models.config.S3CredentialsConfig href "" "lomas_server.models.config.S3CredentialsConfig"
click lomas_server.models.config.PrivateDBCredentials href "" "lomas_server.models.config.PrivateDBCredentials"
BaseModel for S3 database credentials.
AmqpConfig
#
flowchart TD
lomas_server.models.config.AmqpConfig[AmqpConfig]
click lomas_server.models.config.AmqpConfig href "" "lomas_server.models.config.AmqpConfig"
BaseSettings for Advanced Message Queuing Protocol (AMQP).
Methods:
dsn
#
dsn() -> str
Construct full DSN including credentials.
Source code in server/lomas_server/models/config.py
44 45 46 47 48 49 50 51 52 53 54 55 | |
DexAdminConfig
#
flowchart TD
lomas_server.models.config.DexAdminConfig[DexAdminConfig]
click lomas_server.models.config.DexAdminConfig href "" "lomas_server.models.config.DexAdminConfig"
Methods:
-
use_mtls–Using mTLS ?
Server
#
flowchart TD
lomas_server.models.config.Server[Server]
click lomas_server.models.config.Server href "" "lomas_server.models.config.Server"
BaseModel for uvicorn server configs.
Attributes:
-
submit_limit(float) –A limit on the rate which users can submit answers.
Config
#
flowchart TD
lomas_server.models.config.Config[Config]
click lomas_server.models.config.Config href "" "lomas_server.models.config.Config"
Server runtime config.
-
API Reference
Server
ConfigResponseconfig
- API Reference Server
AdminConfig
#
flowchart TD
lomas_server.models.config.AdminConfig[AdminConfig]
click lomas_server.models.config.AdminConfig href "" "lomas_server.models.config.AdminConfig"
Base model for settings for administrative tasks.
-
API Reference
Server
add_lomas_demo_data
Classes:
-
ConfigResponse–Model for response to server config queries.
ConfigResponse
#
flowchart TD
lomas_server.models.responses.ConfigResponse[ConfigResponse]
click lomas_server.models.responses.ConfigResponse href "" "lomas_server.models.responses.ConfigResponse"
Model for response to server config queries.
-
API Reference
Server
get_server_config
Attributes:
Classes:
-
LoggingAndTracingMiddleware–Middleware for logging and tracing incoming HTTP requests.
-
FastAPIMetricMiddleware–Middleware to collect and expose Prometheus metrics for a FastAPI application.
LoggingAndTracingMiddleware
#
flowchart TD
lomas_server.routes.middlewares.LoggingAndTracingMiddleware[LoggingAndTracingMiddleware]
click lomas_server.routes.middlewares.LoggingAndTracingMiddleware href "" "lomas_server.routes.middlewares.LoggingAndTracingMiddleware"
Middleware for logging and tracing incoming HTTP requests.
This middleware logs the incoming requests, including the user name the route being accessed, and any query parameters. Additionally, it creates a trace span to trace the user's request and adds attributes to the span related to the user name and query parameters.
Methods:
-
dispatch–Handles the request and performs logging and tracing.
dispatch
async
#
Handles the request and performs logging and tracing.
Logs the user name, the route and the query parameters. Creates a trace span to monitor the request and adds relevant attributes.
Parameters:
-
(request#Request) –The incoming request object.
-
(call_next#Callable) –A function that, when called, passes the request to the next middleware or request handler.
Returns:
-
Response(Response) –The HTTP response generated by calling
call_next(request).
Source code in server/lomas_server/routes/middlewares.py
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
FastAPIMetricMiddleware
#
flowchart TD
lomas_server.routes.middlewares.FastAPIMetricMiddleware[FastAPIMetricMiddleware]
click lomas_server.routes.middlewares.FastAPIMetricMiddleware href "" "lomas_server.routes.middlewares.FastAPIMetricMiddleware"
Middleware to collect and expose Prometheus metrics for a FastAPI application.
This middleware tracks various metrics related to HTTP requests, including:
- Total requests (fastapi_requests_total)
- Total responses (fastapi_responses_total)
- Exceptions raised (fastapi_exceptions_total)
- Request processing duration (fastapi_requests_duration_seconds)
- Current requests in progress (fastapi_requests_in_progress)
It also supports integration with an OpenTelemetry exporter for exporting metrics to a metrics collector (e.g., Prometheus or any other OTLP-compatible collector).
Parameters:
-
(app#ASGIApp) –The FastAPI application instance.
-
(app_name#str) –The name of the application used for metric labeling.
Methods:
-
dispatch–Processes HTTP request, records metrics and returns the HTTP response.
-
get_path–Attempts to match the request' route to a defined route.
Source code in server/lomas_server/routes/middlewares.py
117 118 119 120 121 122 123 124 125 126 | |
dispatch
async
#
Processes HTTP request, records metrics and returns the HTTP response.
This method performs the following steps:
1. Tracks the current request in progress using fastapi_requests_in_progress gauge.
2. Records the request count with fastapi_requests_total counter.
3. Records the time taken to process the request using
fastapi_requests_duration_seconds histogram.
4. Handles exceptions, if raised, and records the exception details using
fastapi_exceptions_total counter.
5. Records the response status code with fastapi_responses_total counter.
6. Decrements the in-progress request gauge after processing.
Parameters:
-
(request#Request) –The incoming HTTP request to be processed.
-
(call_next#RequestResponseEndpoint) –Endpoint that processes the request and returns a response.
Returns:
-
Response(Response) –The HTTP response after processing the request.
Raises:
-
BaseException–If an exception occurs during request processing, it is raised after logging it.
Source code in server/lomas_server/routes/middlewares.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
get_path
staticmethod
#
Attempts to match the request' route to a defined route.
Parameters:
-
(request#Request) –The HTTP request to check for a matching path.
Returns:
-
tuple[str, bool]–Tuple[str, bool]: A tuple containing: - The matched path (str) from the request URL. - Boolean (True if the path was handled by one of the routes).
Source code in server/lomas_server/routes/middlewares.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
Functions:
-
root–Redirect root endpoint to the state endpoint.
-
health_handler–HealthCheck endpoint: server alive.
-
status_handler–Job status endpoint.
-
get_state–Returns the current state dict of this server instance.
-
get_server_config–Returns the config of this server instance.
-
get_dataset_metadata–Retrieves metadata for a given dataset.
-
get_dummy_dataset–Generates and returns a dummy dataset.
-
get_initial_budget–Returns the initial budget for a user and dataset.
-
get_total_spent_budget–Returns the spent budget for a user and dataset.
-
get_remaining_budget–Returns the remaining budget for a user and dataset.
-
get_user_previous_queries–Returns the query history of a user on a specific dataset.
-
add_user–Adds a new user with an associated budget for a given dataset.
-
add_users_yaml–Add all users from a yaml file.
-
delete_user–Deletes the lomas user.
-
delete_collection–Drops the given collection from the administration database.
root
async
#
root() -> RedirectResponse
Redirect root endpoint to the state endpoint.
Returns:
-
JSONResponse(RedirectResponse) –The state of the server instance.
Source code in server/lomas_server/routes/routes_admin.py
41 42 43 44 45 46 47 48 | |
health_handler
async
#
health_handler() -> JSONResponse
HealthCheck endpoint: server alive.
Returns:
-
JSONResponse(JSONResponse) –"live"
Source code in server/lomas_server/routes/routes_admin.py
51 52 53 54 55 56 57 58 | |
status_handler
async
#
Job status endpoint.
Parameters:
-
(user_id#UserId) –The user id.
-
(request#Request) –The raw request.
-
(uid#UUID) –The job's unique id.
-
(response#Response) –The job status response.
Raises:
-
UnauthorizedAccessException–If the user does not have access to this job.
-
HTTPException–If the job does not exist.
Returns:
-
Job(Job) –The Job model for this uid.
Source code in server/lomas_server/routes/routes_admin.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
get_state
async
#
Returns the current state dict of this server instance.
Parameters:
Returns:
-
JSONResponse(JSONResponse) –The state of the server instance.
Source code in server/lomas_server/routes/routes_admin.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
get_server_config
async
#
get_server_config(_: UserId) -> ConfigResponse
Returns the config of this server instance.
Parameters:
Returns:
-
ConfigResponse(ConfigResponse) –The server config.
Source code in server/lomas_server/routes/routes_admin.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
get_dataset_metadata
#
get_dataset_metadata(
request: Request,
user_id: UserId,
query_json: LomasRequestModel = example_get_admin_db_data_body,
) -> TableMetadata
Retrieves metadata for a given dataset.
Parameters:
-
(request#Request) –Raw request object
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#LomasRequestModel, default:example_get_admin_db_data_body) –A JSON object containing the dataset_name key for indicating the dataset. Defaults to example_get_admin_db_data_body.
Raises:
-
ExternalLibraryException–For exceptions from libraries external to this package.
-
InternalServerException–For any other unforseen exceptions.
Returns:
-
TableMetadata(TableMetadata) –The metadata object for the specified dataset_name.
Source code in server/lomas_server/routes/routes_admin.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
get_dummy_dataset
#
get_dummy_dataset(
request: Request,
user_id: UserId,
query_json: GetDummyDataset = example_get_dummy_dataset_body,
) -> DummyDsResponse
Generates and returns a dummy dataset.
Parameters:
-
(request#Request) –Raw request object
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#GetDummyDataset, default:example_get_dummy_dataset_body) –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 example_get_dummy_dataset_body.
Raises:
-
ExternalLibraryException–For exceptions from libraries external to this package.
-
InternalServerException–For any other unforseen exceptions.
Returns:
-
JSONResponse(DummyDsResponse) –a dict with the dataframe as a dict, the column types and the list of datetime columns.
Source code in server/lomas_server/routes/routes_admin.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | |
get_initial_budget
#
get_initial_budget(
request: Request,
user_id: UserId,
query_json: LomasRequestModel = example_get_admin_db_data_body,
) -> InitialBudgetResponse
Returns the initial budget for a user and dataset.
Parameters:
-
(request#Request) –Raw request object.
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#LomasRequestModel, default:example_get_admin_db_data_body) –A JSON object containing: - dataset_name (str): The name of the dataset.
Defaults to example_get_admin_db_data_body.
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: JSONResponse: a JSON object with: - initial_epsilon (float): initial epsilon budget. - initial_delta (float): initial delta budget.
Source code in server/lomas_server/routes/routes_admin.py
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
get_total_spent_budget
#
get_total_spent_budget(
request: Request,
user_id: UserId,
query_json: LomasRequestModel = example_get_admin_db_data_body,
) -> SpentBudgetResponse
Returns the spent budget for a user and dataset.
Parameters:
-
(request#Request) –Raw request object.
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#LomasRequestModel, default:example_get_admin_db_data_body) –A JSON object containing: - dataset_name (str): The name of the dataset.
Defaults to example_get_admin_db_data_body.
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: JSONResponse: a JSON object with: - total_spent_epsilon (float): total spent epsilon budget. - total_spent_delta (float): total spent delta budget.
Source code in server/lomas_server/routes/routes_admin.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | |
get_remaining_budget
#
get_remaining_budget(
request: Request,
user_id: UserId,
query_json: LomasRequestModel = example_get_admin_db_data_body,
) -> RemainingBudgetResponse
Returns the remaining budget for a user and dataset.
Parameters:
-
(request#Request) –Raw request object.
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#LomasRequestModel, default:example_get_admin_db_data_body) –A JSON object containing: - dataset_name (str): The name of the dataset.
Defaults to example_get_admin_db_data_body.
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: JSONResponse: a JSON object with: - remaining_epsilon (float): remaining epsilon budget. - remaining_delta (float): remaining delta budget.
Source code in server/lomas_server/routes/routes_admin.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |
get_user_previous_queries
#
get_user_previous_queries(
request: Request,
user_id: UserId,
query_json: LomasRequestModel = example_get_admin_db_data_body,
) -> JSONResponse
Returns the query history of a user on a specific dataset.
Parameters:
-
(request#Request) –Raw request object.
-
(user_id#UserId) –A UserId object identifying the user.
-
(query_json#LomasRequestModel, default:example_get_admin_db_data_body) –A JSON object containing: - dataset_name (str): The name of the dataset.
Defaults to example_get_admin_db_data_body.
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:
-
JSONResponse(JSONResponse) –A JSON object containing: - previous_queries (list[dict]): a list of dictionaries containing the previous queries.
Source code in server/lomas_server/routes/routes_admin.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
add_user
#
Adds a new user with an associated budget for a given dataset.
Parameters:
Source code in server/lomas_server/routes/routes_admin.py
449 450 451 452 453 454 455 456 457 458 459 460 461 | |
add_users_yaml
#
Add all users from a yaml file.
Parameters:
-
(file#Path) –a path to the YAML file location
-
(clean#bool, default:False) –boolean flag True if drop current user collection False if keep current user collection
Source code in server/lomas_server/routes/routes_admin.py
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 | |
delete_user
#
Deletes the lomas user.
Parameters:
Source code in server/lomas_server/routes/routes_admin.py
483 484 485 486 487 488 489 490 491 492 493 494 495 | |
delete_collection
#
delete_collection(request: Request, _: UserId, collection_name: str) -> None
Drops the given collection from the administration database.
Parameters:
Source code in server/lomas_server/routes/routes_admin.py
498 499 500 501 502 503 504 505 506 507 508 509 510 | |
Functions:
-
smartnoise_sql_handler–Handles queries for the SmartNoiseSQL library.
-
dummy_smartnoise_sql_handler–Handles queries on dummy datasets for the SmartNoiseSQL library.
-
estimate_smartnoise_sql_cost–Estimates the privacy loss budget cost of a SmartNoiseSQL query.
-
smartnoise_synth_handler–Handles queries for the SmartNoiseSynth library.
-
dummy_smartnoise_synth_handler–Handles queries on dummy datasets for the SmartNoiseSynth library.
-
estimate_smartnoise_synth_cost–Computes the privacy loss budget cost of a SmartNoiseSynth query.
-
opendp_query_handler–Handles queries for the OpenDP Library.
-
dummy_opendp_query_handler–Handles queries on dummy datasets for the OpenDP library.
-
estimate_opendp_cost–Estimates the privacy loss budget cost of an OpenDP query.
-
diffprivlib_query_handler–Handles queries for the DiffPrivLib Library.
-
dummy_diffprivlib_query_handler–Handles queries on dummy datasets for the DiffPrivLib library.
-
estimate_diffprivlib_cost–Estimates the privacy loss budget cost of an DiffPrivLib query.
smartnoise_sql_handler
async
#
smartnoise_sql_handler(
user_id: UserId, request: Request, smartnoise_sql_query: SmartnoiseSQLQueryModel
) -> Job
Handles queries for the SmartNoiseSQL library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a SmartnoiseSQLQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
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 | |
dummy_smartnoise_sql_handler
async
#
dummy_smartnoise_sql_handler(
user_id: UserId, request: Request, smartnoise_sql_query: SmartnoiseSQLDummyQueryModel
) -> Job
Handles queries on dummy datasets for the SmartNoiseSQL library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a SmartnoiseSQLQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
estimate_smartnoise_sql_cost
async
#
estimate_smartnoise_sql_cost(
user_id: UserId, request: Request, smartnoise_sql_query: SmartnoiseSQLRequestModel
) -> Job
Estimates the privacy loss budget cost of a SmartNoiseSQL query.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a CostResponse containing the privacy loss cost of the input query.
Source code in server/lomas_server/routes/routes_dp.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
smartnoise_synth_handler
async
#
smartnoise_synth_handler(
user_id: UserId, request: Request, smartnoise_synth_query: SmartnoiseSynthQueryModel
) -> Job
Handles queries for the SmartNoiseSynth library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a SmartnoiseSynthModel
-
Job–or SmartnoiseSynthSamples.
Source code in server/lomas_server/routes/routes_dp.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
dummy_smartnoise_synth_handler
async
#
dummy_smartnoise_synth_handler(
user_id: UserId,
request: Request,
smartnoise_synth_query: SmartnoiseSynthDummyQueryModel,
) -> Job
Handles queries on dummy datasets for the SmartNoiseSynth library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a SmartnoiseSynthModel
-
Job–or SmartnoiseSynthSamples.
Source code in server/lomas_server/routes/routes_dp.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
estimate_smartnoise_synth_cost
async
#
estimate_smartnoise_synth_cost(
user_id: UserId, request: Request, smartnoise_synth_query: SmartnoiseSynthRequestModel
) -> Job
Computes the privacy loss budget cost of a SmartNoiseSynth query.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a CostResponse containing the privacy loss cost of the input query.
Source code in server/lomas_server/routes/routes_dp.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
opendp_query_handler
async
#
opendp_query_handler(
user_id: UserId, request: Request, opendp_query: OpenDPQueryModel
) -> Job
Handles queries for the OpenDP Library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing an OpenDPQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
dummy_opendp_query_handler
async
#
dummy_opendp_query_handler(
user_id: UserId, request: Request, opendp_query: OpenDPDummyQueryModel
) -> Job
Handles queries on dummy datasets for the OpenDP library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing an OpenDPQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
estimate_opendp_cost
async
#
estimate_opendp_cost(
user_id: UserId, request: Request, opendp_query: OpenDPRequestModel
) -> Job
Estimates the privacy loss budget cost of an OpenDP query.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a CostResponse containing the privacy loss cost of the input query.
Source code in server/lomas_server/routes/routes_dp.py
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
diffprivlib_query_handler
async
#
diffprivlib_query_handler(
user_id: UserId, request: Request, diffprivlib_query: DiffPrivLibQueryModel
) -> Job
Handles queries for the DiffPrivLib Library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a DiffPrivLibQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 | |
dummy_diffprivlib_query_handler
async
#
dummy_diffprivlib_query_handler(
user_id: UserId, request: Request, query_json: DiffPrivLibDummyQueryModel
) -> Job
Handles queries on dummy datasets for the DiffPrivLib library.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(request#Request) –Raw request object
-
(query_json#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:
-
Job(Job) –a scheduled Job resulting in a QueryResponse containing a DiffPrivLibQueryResult.
Source code in server/lomas_server/routes/routes_dp.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
estimate_diffprivlib_cost
async
#
estimate_diffprivlib_cost(
user_id: UserId, request: Request, diffprivlib_query: DiffPrivLibRequestModel
) -> Job
Estimates the privacy loss budget cost of an DiffPrivLib query.
Parameters:
-
(user_id#UserId) –A UserId object identifying the user.
-
(request#Request) –Raw request object
-
(diffprivlib_query#DiffPrivLibRequestModel) –The diffprivlib query body. 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_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:
-
Job(Job) –a scheduled Job resulting in a CostResponse containing the privacy loss cost of the input query.
Source code in server/lomas_server/routes/routes_dp.py
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
Functions:
-
process_response–Process responses queue into Jobs.
-
rabbitmq_connect_queue–Attempt with retries to connect to the queue.
-
rabbitmq_ctx–RabbitMQ queue context to connect and register callbacks.
-
timing_protection–Adds delays to requests response to protect against timing attack.
-
get_user_id_from_authenticator–Extracts the authenticator from the app state and calls its get_user_id method.
-
get_dataset_credentials–Search the list of private database credentials and.
-
handle_query_to_job–Submit Job to handles queries on private, dummy and cost datasets on a worker.
process_response
async
#
process_response(
queue: Queue, cls: type[QueryResponse | CostResponse], jobs: dict[UUID, Job]
) -> None
Process responses queue into Jobs.
Source code in server/lomas_server/routes/utils.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
rabbitmq_connect_queue
async
#
rabbitmq_connect_queue(
config: Config, reconnect_interval: int = 10, timeout: int = 120
) -> RobustConnection
Attempt with retries to connect to the queue.
Source code in server/lomas_server/routes/utils.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
rabbitmq_ctx
async
#
rabbitmq_ctx(app: FastAPI) -> AsyncIterator[None]
RabbitMQ queue context to connect and register callbacks.
Source code in server/lomas_server/routes/utils.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | |
timing_protection
#
timing_protection(func)
Adds delays to requests response to protect against timing attack.
Source code in server/lomas_server/routes/utils.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
get_user_id_from_authenticator
#
get_user_id_from_authenticator(
request: Request,
security_scopes: SecurityScopes,
auth_creds: HTTPAuthorizationCredentials,
) -> UserId
Extracts the authenticator from the app state and calls its get_user_id method.
Also adds the user_name to the request state to annotate the telemetry request span.
Parameters:
-
(request#Request) –The request to access the app and state.
-
(security_scopes#SecurityScopes) –The required scopes for the endpoint.
-
(auth_creds#Annotated[HTTPAuthorizationCredentials, Depends) –The HTTP bearer token.
Returns:
-
UserId(UserId) –A UserId instance extracted from the token.
Source code in server/lomas_server/routes/utils.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
get_dataset_credentials
#
get_dataset_credentials(
private_db_credentials: dict[int, PrivateDBCredentials],
db_type: PrivateDatabaseType,
credentials_name: str,
) -> PrivateDBCredentials
Search the list of private database credentials and.
returns the one that matches the database type and credentials name.
Parameters:
-
(private_db_credentials#Sequence[PrivateDBCredentials]) –The list of private database credentials.
-
(db_type#PrivateDatabaseType) –The type of the database.
Raises:
-
InternalServerException–If the credentials are not found.
Returns:
-
PrivateDBCredentials(PrivateDBCredentials) –The matching credentials.
Source code in server/lomas_server/routes/utils.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
handle_query_to_job
async
#
handle_query_to_job(
request: Request,
query: DummyQueryModel | QueryModel | LomasRequestModel,
user_name: str,
dp_library: DPLibraries,
) -> Job
Submit Job to handles queries on private, dummy and cost datasets on a worker.
Parameters:
-
(request#Request) –Raw request object
-
(query#DummyQueryModel | QueryModel | LomasRequestModel) –A Request or Query to be scheduled
-
(user_name#str) –The user name
-
(dp_library#DPLibraries) –Name of the DP library to use for the request
Raises:
-
UnauthorizedAccessException–A query is already ongoing for this user, the user does not exist or does not have access to the dataset.
Returns:
-
Job(Job) –A scheduled Job resulting in a QueryResponse containing the result of the query (specific to the library) as well as the cost of the query. or a CostResponse containing the epsilon, delta and privacy-loss budget cost for the request.
Source code in server/lomas_server/routes/utils.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
Classes:
-
FilterOutLiveSuccess–Filter out INFO logs: GET /api/live HTTP/1.1 200 OK.
Functions:
-
uvicorn_serve–Start the ASGI server for lomas.
FilterOutLiveSuccess
#
Filter out INFO logs: GET /api/live HTTP/1.1 200 OK.
uvicorn_serve
#
uvicorn_serve() -> None
Start the ASGI server for lomas.
Source code in server/lomas_server/uvicorn_serve.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
Classes:
-
TerminateTaskGroup–Exception raised to terminate a task group.
Functions:
-
handle_exceptions–Transform KNOWN_EXCEPTIONS into a status_code and message for serialization.
-
handle_cost_query–Handle Cost query into CostResponse.
-
handle_query–Handle DP query into QueryResponse.
-
handle_dummy_query–Handle DP-dummy query into QueryResponse.
-
process_message–General RabbitMQ Message handler -> processing -> response.
-
force_terminate_task_group–Used to force termination of a task group.
-
ask_exit–Signal handler for TaskGroup termination.
-
process_all_queues–Handle & await all pika processing queues.
-
run–Start the Worker loop.
TerminateTaskGroup
#
flowchart TD
lomas_server.worker.TerminateTaskGroup[TerminateTaskGroup]
click lomas_server.worker.TerminateTaskGroup href "" "lomas_server.worker.TerminateTaskGroup"
Exception raised to terminate a task group.
handle_exceptions
#
handle_exceptions(exc: BaseException) -> JSONResponse
Transform KNOWN_EXCEPTIONS into a status_code and message for serialization.
In case of unkown exception, wraps it up as if it were an InternalServerException. In case of internal exception, the error message is forwarded to avoid potentially disclosing sensitive information.
Source code in server/lomas_server/worker.py
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 82 83 84 85 86 87 88 89 90 91 | |
handle_cost_query
async
#
handle_cost_query(admin_database: Proxy, body: bytes) -> CostResponse | tuple[bytes, int]
Handle Cost query into CostResponse.
Source code in server/lomas_server/worker.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
handle_query
async
#
handle_query(admin_database: Proxy, body: bytes) -> QueryResponse | tuple[bytes, int]
Handle DP query into QueryResponse.
Source code in server/lomas_server/worker.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
handle_dummy_query
async
#
handle_dummy_query(
admin_database: Proxy, body: bytes
) -> QueryResponse | tuple[bytes, int]
Handle DP-dummy query into QueryResponse.
Source code in server/lomas_server/worker.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
process_message
async
#
process_message(
channel: Channel,
in_queue: str,
out_queue: str,
message_handler: Callable[[bytes], Any],
) -> None
General RabbitMQ Message handler -> processing -> response.
Source code in server/lomas_server/worker.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
force_terminate_task_group
async
#
force_terminate_task_group() -> Never
Used to force termination of a task group.
Source code in server/lomas_server/worker.py
229 230 231 | |
ask_exit
#
Signal handler for TaskGroup termination.
Source code in server/lomas_server/worker.py
234 235 236 237 | |
process_all_queues
async
#
process_all_queues(config: Config) -> None
Handle & await all pika processing queues.
Source code in server/lomas_server/worker.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
run
#
run() -> None
Start the Worker loop.
Source code in server/lomas_server/worker.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |