Overview¶
matchbox.server
¶
Matchbox server.
Includes the API, and database adapters for various backends.
Modules:
-
api–Matchbox API.
-
base–Base classes and utilities for Matchbox database adapters.
-
postgresql–PostgreSQL adapter for Matchbox server.
-
uploads–Worker logic to process user uploads.
Classes:
-
MatchboxDBAdapter–An abstract base class for Matchbox database adapters.
-
MatchboxServerSettings–Settings for the Matchbox application.
MatchboxDBAdapter
¶
Bases: ABC
An abstract base class for Matchbox database adapters.
Methods:
-
query–Queries the database from an optional point of truth.
-
match–Matches an ID in a source resolution and returns the keys in the targets.
-
create_collection–Create a new collection.
-
get_collection–Get collection metadata.
-
list_collections–List all collection names.
-
delete_collection–Delete a collection and all its versions.
-
create_run–Create a new run.
-
set_run_mutable–Set the mutability of a run.
-
set_run_default–Set the default status of a run.
-
get_run–Get run metadata and resolutions.
-
delete_run–Delete a run and all its resolutions.
-
create_resolution–Writes a resolution to Matchbox.
-
get_resolution–Get a resolution from its path.
-
update_resolution–Updates resolution metadata.
-
delete_resolution–Delete a resolution from the database.
-
lock_resolution_data–Change resolution upload stage to PROCESSING.
-
unlock_resolution_data–Change resolution upload stage to READY.
-
get_resolution_stage–Retrieves upload stage of resolution data.
-
insert_source_data–Inserts hash data for a source resolution.
-
insert_model_data–Inserts results data for a model resolution.
-
get_model_data–Get the results for a model resolution.
-
validate_ids–Validates a list of IDs exist in the database.
-
dump–Dumps the entire database to a snapshot.
-
drop–Hard clear the database by dropping all tables and re-creating.
-
clear–Soft clear the database by deleting all rows but retaining tables.
-
restore–Restores the database from a snapshot.
-
delete_orphans–Deletes orphan clusters.
-
login–Upserts the user to the database.
-
get_user_groups–Get names of all groups a user belongs to.
-
list_groups–List all groups.
-
get_group–Get group details including members.
-
create_group–Create a new group.
-
delete_group–Delete a group.
-
add_user_to_group–Add a user to a group. Creates user if they don’t exist.
-
remove_user_from_group–Remove a user from a group.
-
check_permission–Check user permission against a resource.
-
get_permissions–Get all granted permissions against a resource.
-
grant_permission–Grants a permission on a resource.
-
revoke_permission–Revoke permission on a resource.
-
insert_judgement–Adds an evaluation judgement to the database.
-
get_judgements–Retrieves all evaluation judgements.
-
sample_for_eval–Sample a cluster to validate.
Attributes:
-
settings(MatchboxServerSettings) – -
sources(ListableAndCountable) – -
models(Countable) – -
source_clusters(Countable) – -
model_clusters(Countable) – -
all_clusters(Countable) – -
creates(Countable) – -
merges(Countable) – -
proposes(Countable) – -
source_resolutions(Countable) –
query
abstractmethod
¶
query(source: SourceResolutionPath, point_of_truth: ResolutionPath | None = None, threshold: int | None = None, return_leaf_id: bool = False, limit: int | None = None) -> Table
Queries the database from an optional point of truth.
Parameters:
-
(source¶SourceResolutionPath) –the resolution pathidentifying the source to query
-
(point_of_truth¶optional, default:None) –the resolution path to use for filtering results If not specified, will use the source resolution for the queried source
-
(threshold¶optional, default:None) –the threshold to use for creating clusters If None, uses the models’ default threshold If an integer, uses that threshold for the specified model, and the model’s cached thresholds for its ancestors
-
(return_leaf_id¶optional, default:False) –whether to return cluster ID of leaves
-
(limit¶optional, default:None) –the number to use in a limit clause. Useful for testing
Returns:
-
Table–The resulting matchbox IDs in Arrow format
match
abstractmethod
¶
match(key: str, source: SourceResolutionPath, targets: list[SourceResolutionPath], point_of_truth: ResolutionPath, threshold: int | None = None) -> list[Match]
Matches an ID in a source resolution and returns the keys in the targets.
Parameters:
-
(key¶str) –The key to match from the source.
-
(source¶SourceResolutionPath) –The path of the source resolution.
-
(targets¶list[SourceResolutionPath]) –The paths of the target source resolutions.
-
(point_of_truth¶ResolutionPath) –The path of the resolution to use for matching.
-
(threshold¶optional, default:None) –the threshold to use for creating clusters If None, uses the resolutions’ default threshold If an integer, uses that threshold for the specified resolution, and the resolution’s cached thresholds for its ancestors Will use these threshold values instead of the cached thresholds
create_collection
abstractmethod
¶
create_collection(name: CollectionName) -> Collection
Create a new collection.
Parameters:
-
(name¶CollectionName) –The name of the collection to create.
Returns:
-
Collection–A Collection object containing its metadata, versions, and resolutions.
get_collection
abstractmethod
¶
get_collection(name: CollectionName) -> Collection
Get collection metadata.
Parameters:
-
(name¶CollectionName) –The name of the collection to get.
Returns:
-
Collection–A Collection object containing its metadata, versions, and resolutions.
list_collections
abstractmethod
¶
list_collections() -> list[CollectionName]
delete_collection
abstractmethod
¶
delete_collection(name: CollectionName, certain: bool) -> None
Delete a collection and all its versions.
Parameters:
-
(name¶CollectionName) –The name of the collection to delete.
-
(certain¶bool) –Whether to delete the collection without confirmation.
create_run
abstractmethod
¶
create_run(collection: CollectionName) -> Run
Create a new run.
Parameters:
-
(collection¶CollectionName) –The name of the collection to create the run in.
Returns:
-
Run–A Run object containing its metadata and resolutions.
set_run_mutable
abstractmethod
¶
set_run_mutable(collection: CollectionName, run_id: RunID, mutable: bool) -> Run
set_run_default
abstractmethod
¶
set_run_default(collection: CollectionName, run_id: RunID, default: bool) -> Run
get_run
abstractmethod
¶
get_run(collection: CollectionName, run_id: RunID) -> Run
Get run metadata and resolutions.
Parameters:
-
(collection¶CollectionName) –The name of the collection containing the run.
-
(run_id¶RunID) –The ID of the run to get.
Returns:
-
Run–A Run object containing its metadata and resolutions.
delete_run
abstractmethod
¶
delete_run(collection: CollectionName, run_id: RunID, certain: bool) -> None
create_resolution
abstractmethod
¶
create_resolution(resolution: Resolution, path: ResolutionPath) -> None
Writes a resolution to Matchbox.
Parameters:
-
(resolution¶Resolution) –Resolution object with a source or model config
-
(path¶ResolutionPath) –The resolution path for the source
get_resolution
abstractmethod
¶
get_resolution(path: ResolutionPath) -> Resolution
Get a resolution from its path.
Parameters:
-
(path¶ResolutionPath) –The resolution path for the source
Returns:
-
Resolution–A Resolution object
update_resolution
abstractmethod
¶
update_resolution(resolution: Resolution, path: ResolutionPath) -> None
Updates resolution metadata.
It cannot be used to update a resolution’s fingerprint.
Parameters:
-
(resolution¶Resolution) –Resolution object with a source or model config
-
(path¶ResolutionPath) –The resolution path for the source
delete_resolution
abstractmethod
¶
delete_resolution(path: ResolutionPath, certain: bool) -> None
Delete a resolution from the database.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to delete.
-
(certain¶bool) –Whether to delete the model without confirmation.
lock_resolution_data
abstractmethod
¶
lock_resolution_data(path: ResolutionPath) -> None
Change resolution upload stage to PROCESSING.
This will lock uploading data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
unlock_resolution_data
abstractmethod
¶
unlock_resolution_data(path: ResolutionPath, complete: bool) -> None
Change resolution upload stage to READY.
This will unlock uploading data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
-
(complete¶bool) –Whether to label the resolution stage as COMPLETE.
get_resolution_stage
abstractmethod
¶
get_resolution_stage(path: ResolutionPath) -> UploadStage
Retrieves upload stage of resolution data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
insert_source_data
abstractmethod
¶
insert_source_data(path: SourceResolutionPath, data_hashes: Table) -> None
Inserts hash data for a source resolution.
Only possible if data fingerprint matches fingerprint declared when the resolution was created. Data can only be set once on a resolution.
Parameters:
-
(path¶SourceResolutionPath) –The path of the source resolution to index.
-
(data_hashes¶Table) –The Arrow table with the hash of each data row
insert_model_data
abstractmethod
¶
insert_model_data(path: ModelResolutionPath, results: Table) -> None
Inserts results data for a model resolution.
Only possible if data fingerprint matches fingerprint declared when the resolution was created. Data can only be set once on a resolution.
get_model_data
abstractmethod
¶
get_model_data(path: ModelResolutionPath) -> Table
Get the results for a model resolution.
validate_ids
abstractmethod
¶
dump
abstractmethod
¶
dump() -> MatchboxSnapshot
Dumps the entire database to a snapshot.
Returns:
-
MatchboxSnapshot–A MatchboxSnapshot object of type “postgres” with the database’s current state.
drop
abstractmethod
¶
clear
abstractmethod
¶
restore
abstractmethod
¶
restore(snapshot: MatchboxSnapshot) -> None
Restores the database from a snapshot.
Parameters:
-
(snapshot¶MatchboxSnapshot) –A MatchboxSnapshot object of type “postgres” with the database’s state
Raises:
-
TypeError–If the snapshot is not compatible with PostgreSQL
delete_orphans
abstractmethod
¶
delete_orphans() -> int
Deletes orphan clusters.
Orphan clusters are clusters recorded in the Clusters table but that are not referenced in other tables.
login
abstractmethod
¶
get_user_groups
abstractmethod
¶
get_group
abstractmethod
¶
create_group
abstractmethod
¶
create_group(group: Group) -> None
Create a new group.
Arg
group: The group to create
Raises:
-
MatchboxGroupAlreadyExistsError–If group name taken.
delete_group
abstractmethod
¶
Delete a group.
Parameters:
-
(name¶GroupName) –The name of the group to delete
-
(certain¶bool, default:False) –Whether to delete the group without confirmation.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
-
MatchboxSystemGroupError–If attempting to delete a system group.
-
MatchboxDeletionNotConfirmed–If certain=False.
add_user_to_group
abstractmethod
¶
Add a user to a group. Creates user if they don’t exist.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
remove_user_from_group
abstractmethod
¶
Remove a user from a group.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
-
MatchboxUserNotFoundError–If user doesn’t exist.
check_permission
abstractmethod
¶
check_permission(user_name: str, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> bool
Check user permission against a resource.
Parameters:
-
(user_name¶str) –The username to check.
-
(permission¶PermissionType) –The permission type to check
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to check. One of “system” or a collection name
get_permissions
abstractmethod
¶
get_permissions(resource: Literal[SYSTEM] | CollectionName) -> list[PermissionGrant]
Get all granted permissions against a resource.
Parameters:
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to get permissions for. One of “system” or a collection name
grant_permission
abstractmethod
¶
grant_permission(group_name: GroupName, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> None
Grants a permission on a resource.
Parameters:
-
(group_name¶GroupName) –The name of the group to grant permission to
-
(permission¶PermissionType) –The permission to grant
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to grant permission on. One of “system” or a collection name
revoke_permission
abstractmethod
¶
revoke_permission(group_name: GroupName, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> None
Revoke permission on a resource.
Parameters:
-
(group_name¶GroupName) –The name of the group to revoke permission of
-
(permission¶PermissionType) –The permission to revoke
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to revoke permission from. One of “system” or a collection name
insert_judgement
abstractmethod
¶
get_judgements
abstractmethod
¶
sample_for_eval
abstractmethod
¶
MatchboxServerSettings
¶
Bases: BaseSettings
Settings for the Matchbox application.
Methods:
-
check_settings–Check that legal combinations of settings are provided.
Attributes:
-
batch_size(int) – -
backend_type(MatchboxBackends) – -
datastore(MatchboxDatastoreSettings) – -
task_runner(Literal['api', 'celery']) – -
redis_uri(str | None) – -
uploads_expiry_minutes(int | None) – -
authorisation(bool) – -
public_key(SecretStr | None) – -
log_level(LogLevelType) –
matchbox.server.base
¶
Base classes and utilities for Matchbox database adapters.
Classes:
-
MatchboxBackends–The available backends for Matchbox.
-
MatchboxSnapshot–A snapshot of the Matchbox database.
-
MatchboxDatastoreSettings–Settings specific to the datastore configuration.
-
MatchboxServerSettings–Settings for the Matchbox application.
-
BackendManager–Manages the Matchbox backend instance and settings.
-
Countable–A protocol for objects that can be counted.
-
Listable–A protocol for objects that can be listed.
-
ListableAndCountable–A protocol for objects that can be counted and listed.
-
MatchboxDBAdapter–An abstract base class for Matchbox database adapters.
Functions:
-
get_backend_settings–Get the appropriate settings class based on the backend type.
-
get_backend_class–Get the appropriate backend class based on the backend type.
-
settings_to_backend–Create backend adapter with injected settings.
-
initialise_matchbox–Initialise the Matchbox backend based on environment variables.
Attributes:
-
PERMISSION_GRANTS(dict[PermissionType, list[PermissionType]]) –A global variable that defines the permission hierarchy.
PERMISSION_GRANTS
module-attribute
¶
PERMISSION_GRANTS: dict[PermissionType, list[PermissionType]] = {READ: [READ, WRITE, ADMIN], WRITE: [WRITE, ADMIN], ADMIN: [ADMIN]}
A global variable that defines the permission hierarchy.
Keys are the permission, values are a list of permissions that would grant the permission.
For example, only PermissionType.ADMIN can grant PermissionType.ADMIN,
but any permission implies PermissionType.READ.
MatchboxBackends
¶
MatchboxSnapshot
¶
Bases: BaseModel
A snapshot of the Matchbox database.
Methods:
-
check_serialisable–Validate that the value can be serialised to JSON.
Attributes:
-
backend_type(MatchboxBackends) – -
data(dict[str, Any]) –
MatchboxDatastoreSettings
¶
Bases: BaseSettings
Settings specific to the datastore configuration.
Methods:
-
get_client–Returns an S3 client for the datastore.
Attributes:
-
host(str | None) – -
port(int | None) – -
access_key_id(SecretStr | None) – -
secret_access_key(SecretStr | None) – -
default_region(str | None) – -
cache_bucket_name(str) –
get_client
¶
Returns an S3 client for the datastore.
Creates S3 buckets if they don’t exist.
MatchboxServerSettings
¶
Bases: BaseSettings
Settings for the Matchbox application.
Methods:
-
check_settings–Check that legal combinations of settings are provided.
Attributes:
-
batch_size(int) – -
backend_type(MatchboxBackends) – -
datastore(MatchboxDatastoreSettings) – -
task_runner(Literal['api', 'celery']) – -
redis_uri(str | None) – -
uploads_expiry_minutes(int | None) – -
authorisation(bool) – -
public_key(SecretStr | None) – -
log_level(LogLevelType) –
BackendManager
¶
Manages the Matchbox backend instance and settings.
Methods:
-
initialise–Initialise the backend with the given settings.
-
get_backend–Get the backend instance.
-
get_settings–Get the backend settings.
initialise
classmethod
¶
initialise(settings: MatchboxServerSettings) -> None
Initialise the backend with the given settings.
Countable
¶
Listable
¶
ListableAndCountable
¶
A protocol for objects that can be counted and listed.
Methods:
MatchboxDBAdapter
¶
Bases: ABC
An abstract base class for Matchbox database adapters.
Methods:
-
query–Queries the database from an optional point of truth.
-
match–Matches an ID in a source resolution and returns the keys in the targets.
-
create_collection–Create a new collection.
-
get_collection–Get collection metadata.
-
list_collections–List all collection names.
-
delete_collection–Delete a collection and all its versions.
-
create_run–Create a new run.
-
set_run_mutable–Set the mutability of a run.
-
set_run_default–Set the default status of a run.
-
get_run–Get run metadata and resolutions.
-
delete_run–Delete a run and all its resolutions.
-
create_resolution–Writes a resolution to Matchbox.
-
get_resolution–Get a resolution from its path.
-
update_resolution–Updates resolution metadata.
-
delete_resolution–Delete a resolution from the database.
-
lock_resolution_data–Change resolution upload stage to PROCESSING.
-
unlock_resolution_data–Change resolution upload stage to READY.
-
get_resolution_stage–Retrieves upload stage of resolution data.
-
insert_source_data–Inserts hash data for a source resolution.
-
insert_model_data–Inserts results data for a model resolution.
-
get_model_data–Get the results for a model resolution.
-
validate_ids–Validates a list of IDs exist in the database.
-
dump–Dumps the entire database to a snapshot.
-
drop–Hard clear the database by dropping all tables and re-creating.
-
clear–Soft clear the database by deleting all rows but retaining tables.
-
restore–Restores the database from a snapshot.
-
delete_orphans–Deletes orphan clusters.
-
login–Upserts the user to the database.
-
get_user_groups–Get names of all groups a user belongs to.
-
list_groups–List all groups.
-
get_group–Get group details including members.
-
create_group–Create a new group.
-
delete_group–Delete a group.
-
add_user_to_group–Add a user to a group. Creates user if they don’t exist.
-
remove_user_from_group–Remove a user from a group.
-
check_permission–Check user permission against a resource.
-
get_permissions–Get all granted permissions against a resource.
-
grant_permission–Grants a permission on a resource.
-
revoke_permission–Revoke permission on a resource.
-
insert_judgement–Adds an evaluation judgement to the database.
-
get_judgements–Retrieves all evaluation judgements.
-
sample_for_eval–Sample a cluster to validate.
Attributes:
-
settings(MatchboxServerSettings) – -
sources(ListableAndCountable) – -
models(Countable) – -
source_clusters(Countable) – -
model_clusters(Countable) – -
all_clusters(Countable) – -
creates(Countable) – -
merges(Countable) – -
proposes(Countable) – -
source_resolutions(Countable) –
query
abstractmethod
¶
query(source: SourceResolutionPath, point_of_truth: ResolutionPath | None = None, threshold: int | None = None, return_leaf_id: bool = False, limit: int | None = None) -> Table
Queries the database from an optional point of truth.
Parameters:
-
(source¶SourceResolutionPath) –the resolution pathidentifying the source to query
-
(point_of_truth¶optional, default:None) –the resolution path to use for filtering results If not specified, will use the source resolution for the queried source
-
(threshold¶optional, default:None) –the threshold to use for creating clusters If None, uses the models’ default threshold If an integer, uses that threshold for the specified model, and the model’s cached thresholds for its ancestors
-
(return_leaf_id¶optional, default:False) –whether to return cluster ID of leaves
-
(limit¶optional, default:None) –the number to use in a limit clause. Useful for testing
Returns:
-
Table–The resulting matchbox IDs in Arrow format
match
abstractmethod
¶
match(key: str, source: SourceResolutionPath, targets: list[SourceResolutionPath], point_of_truth: ResolutionPath, threshold: int | None = None) -> list[Match]
Matches an ID in a source resolution and returns the keys in the targets.
Parameters:
-
(key¶str) –The key to match from the source.
-
(source¶SourceResolutionPath) –The path of the source resolution.
-
(targets¶list[SourceResolutionPath]) –The paths of the target source resolutions.
-
(point_of_truth¶ResolutionPath) –The path of the resolution to use for matching.
-
(threshold¶optional, default:None) –the threshold to use for creating clusters If None, uses the resolutions’ default threshold If an integer, uses that threshold for the specified resolution, and the resolution’s cached thresholds for its ancestors Will use these threshold values instead of the cached thresholds
create_collection
abstractmethod
¶
create_collection(name: CollectionName) -> Collection
Create a new collection.
Parameters:
-
(name¶CollectionName) –The name of the collection to create.
Returns:
-
Collection–A Collection object containing its metadata, versions, and resolutions.
get_collection
abstractmethod
¶
get_collection(name: CollectionName) -> Collection
Get collection metadata.
Parameters:
-
(name¶CollectionName) –The name of the collection to get.
Returns:
-
Collection–A Collection object containing its metadata, versions, and resolutions.
list_collections
abstractmethod
¶
list_collections() -> list[CollectionName]
delete_collection
abstractmethod
¶
delete_collection(name: CollectionName, certain: bool) -> None
Delete a collection and all its versions.
Parameters:
-
(name¶CollectionName) –The name of the collection to delete.
-
(certain¶bool) –Whether to delete the collection without confirmation.
create_run
abstractmethod
¶
create_run(collection: CollectionName) -> Run
Create a new run.
Parameters:
-
(collection¶CollectionName) –The name of the collection to create the run in.
Returns:
-
Run–A Run object containing its metadata and resolutions.
set_run_mutable
abstractmethod
¶
set_run_mutable(collection: CollectionName, run_id: RunID, mutable: bool) -> Run
set_run_default
abstractmethod
¶
set_run_default(collection: CollectionName, run_id: RunID, default: bool) -> Run
get_run
abstractmethod
¶
get_run(collection: CollectionName, run_id: RunID) -> Run
Get run metadata and resolutions.
Parameters:
-
(collection¶CollectionName) –The name of the collection containing the run.
-
(run_id¶RunID) –The ID of the run to get.
Returns:
-
Run–A Run object containing its metadata and resolutions.
delete_run
abstractmethod
¶
delete_run(collection: CollectionName, run_id: RunID, certain: bool) -> None
create_resolution
abstractmethod
¶
create_resolution(resolution: Resolution, path: ResolutionPath) -> None
Writes a resolution to Matchbox.
Parameters:
-
(resolution¶Resolution) –Resolution object with a source or model config
-
(path¶ResolutionPath) –The resolution path for the source
get_resolution
abstractmethod
¶
get_resolution(path: ResolutionPath) -> Resolution
Get a resolution from its path.
Parameters:
-
(path¶ResolutionPath) –The resolution path for the source
Returns:
-
Resolution–A Resolution object
update_resolution
abstractmethod
¶
update_resolution(resolution: Resolution, path: ResolutionPath) -> None
Updates resolution metadata.
It cannot be used to update a resolution’s fingerprint.
Parameters:
-
(resolution¶Resolution) –Resolution object with a source or model config
-
(path¶ResolutionPath) –The resolution path for the source
delete_resolution
abstractmethod
¶
delete_resolution(path: ResolutionPath, certain: bool) -> None
Delete a resolution from the database.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to delete.
-
(certain¶bool) –Whether to delete the model without confirmation.
lock_resolution_data
abstractmethod
¶
lock_resolution_data(path: ResolutionPath) -> None
Change resolution upload stage to PROCESSING.
This will lock uploading data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
unlock_resolution_data
abstractmethod
¶
unlock_resolution_data(path: ResolutionPath, complete: bool) -> None
Change resolution upload stage to READY.
This will unlock uploading data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
-
(complete¶bool) –Whether to label the resolution stage as COMPLETE.
get_resolution_stage
abstractmethod
¶
get_resolution_stage(path: ResolutionPath) -> UploadStage
Retrieves upload stage of resolution data.
Parameters:
-
(path¶ResolutionPath) –The path of the resolution to target.
insert_source_data
abstractmethod
¶
insert_source_data(path: SourceResolutionPath, data_hashes: Table) -> None
Inserts hash data for a source resolution.
Only possible if data fingerprint matches fingerprint declared when the resolution was created. Data can only be set once on a resolution.
Parameters:
-
(path¶SourceResolutionPath) –The path of the source resolution to index.
-
(data_hashes¶Table) –The Arrow table with the hash of each data row
insert_model_data
abstractmethod
¶
insert_model_data(path: ModelResolutionPath, results: Table) -> None
Inserts results data for a model resolution.
Only possible if data fingerprint matches fingerprint declared when the resolution was created. Data can only be set once on a resolution.
get_model_data
abstractmethod
¶
get_model_data(path: ModelResolutionPath) -> Table
Get the results for a model resolution.
validate_ids
abstractmethod
¶
dump
abstractmethod
¶
dump() -> MatchboxSnapshot
Dumps the entire database to a snapshot.
Returns:
-
MatchboxSnapshot–A MatchboxSnapshot object of type “postgres” with the database’s current state.
drop
abstractmethod
¶
clear
abstractmethod
¶
restore
abstractmethod
¶
restore(snapshot: MatchboxSnapshot) -> None
Restores the database from a snapshot.
Parameters:
-
(snapshot¶MatchboxSnapshot) –A MatchboxSnapshot object of type “postgres” with the database’s state
Raises:
-
TypeError–If the snapshot is not compatible with PostgreSQL
delete_orphans
abstractmethod
¶
delete_orphans() -> int
Deletes orphan clusters.
Orphan clusters are clusters recorded in the Clusters table but that are not referenced in other tables.
login
abstractmethod
¶
get_user_groups
abstractmethod
¶
get_group
abstractmethod
¶
create_group
abstractmethod
¶
create_group(group: Group) -> None
Create a new group.
Arg
group: The group to create
Raises:
-
MatchboxGroupAlreadyExistsError–If group name taken.
delete_group
abstractmethod
¶
Delete a group.
Parameters:
-
(name¶GroupName) –The name of the group to delete
-
(certain¶bool, default:False) –Whether to delete the group without confirmation.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
-
MatchboxSystemGroupError–If attempting to delete a system group.
-
MatchboxDeletionNotConfirmed–If certain=False.
add_user_to_group
abstractmethod
¶
Add a user to a group. Creates user if they don’t exist.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
remove_user_from_group
abstractmethod
¶
Remove a user from a group.
Raises:
-
MatchboxGroupNotFoundError–If group doesn’t exist.
-
MatchboxUserNotFoundError–If user doesn’t exist.
check_permission
abstractmethod
¶
check_permission(user_name: str, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> bool
Check user permission against a resource.
Parameters:
-
(user_name¶str) –The username to check.
-
(permission¶PermissionType) –The permission type to check
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to check. One of “system” or a collection name
get_permissions
abstractmethod
¶
get_permissions(resource: Literal[SYSTEM] | CollectionName) -> list[PermissionGrant]
Get all granted permissions against a resource.
Parameters:
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to get permissions for. One of “system” or a collection name
grant_permission
abstractmethod
¶
grant_permission(group_name: GroupName, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> None
Grants a permission on a resource.
Parameters:
-
(group_name¶GroupName) –The name of the group to grant permission to
-
(permission¶PermissionType) –The permission to grant
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to grant permission on. One of “system” or a collection name
revoke_permission
abstractmethod
¶
revoke_permission(group_name: GroupName, permission: PermissionType, resource: Literal[SYSTEM] | CollectionName) -> None
Revoke permission on a resource.
Parameters:
-
(group_name¶GroupName) –The name of the group to revoke permission of
-
(permission¶PermissionType) –The permission to revoke
-
(resource¶Literal[SYSTEM] | CollectionName) –The resource to revoke permission from. One of “system” or a collection name
insert_judgement
abstractmethod
¶
get_judgements
abstractmethod
¶
sample_for_eval
abstractmethod
¶
get_backend_settings
¶
get_backend_settings(backend_type: MatchboxBackends) -> type[MatchboxServerSettings]
Get the appropriate settings class based on the backend type.
get_backend_class
¶
get_backend_class(backend_type: MatchboxBackends) -> type[MatchboxDBAdapter]
Get the appropriate backend class based on the backend type.
settings_to_backend
¶
settings_to_backend(settings: MatchboxServerSettings) -> MatchboxDBAdapter
Create backend adapter with injected settings.
initialise_matchbox
¶
Initialise the Matchbox backend based on environment variables.