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
flowchart TD
matchbox.server.MatchboxDBAdapter[MatchboxDBAdapter]
click matchbox.server.MatchboxDBAdapter href "" "matchbox.server.MatchboxDBAdapter"
An abstract base class for Matchbox database adapters.
By default the database should contain the users, groups and permissions found in DEFAULT_GROUPS and DEFAULT_PERMISSIONS.
Methods:
-
query–Queries the database from an optional resolution.
-
match–Match an ID in a source step and return 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 steps.
-
delete_run–Delete a run and all its steps.
-
create_step–Write a step to Matchbox.
-
get_step–Get a step from its path.
-
update_step–Update step metadata.
-
delete_step–Delete a step from the database.
-
lock_step_data–Change step upload stage to PROCESSING.
-
unlock_step_data–Change step upload stage to READY.
-
get_step_stage–Retrieve upload stage of step data.
-
insert_source_data–Insert hash data for a source step.
-
insert_model_data–Insert results data for a model step.
-
insert_resolver_data–Insert resolver cluster assignments for a resolver step.
-
get_model_data–Get the results for a model step.
-
get_resolver_data–Get cluster assignments for a resolver step.
-
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) – -
resolvers(Countable) – -
source_clusters(Countable) – -
model_clusters(Countable) – -
all_clusters(Countable) – -
creates(Countable) – -
merges(Countable) – -
proposes(Countable) – -
source_steps(Countable) – -
users(Countable) –
query
abstractmethod
¶
query(source: SourceStepPath, resolver: ResolverStepPath | None = None, return_leaf_id: bool = False, limit: int | None = None) -> Table
Queries the database from an optional resolution.
Parameters:
-
(source¶SourceStepPath) –The step path identifying the source to query.
-
(resolver¶optional, default:None) –The resolver path to use for filtering results. If not specified, the source step is used for the queried source.
-
(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: SourceStepPath, targets: list[SourceStepPath], resolver: ResolverStepPath) -> list[Match]
Match an ID in a source step and return the keys in the targets.
Parameters:
-
(key¶str) –The key to match from the source.
-
(source¶SourceStepPath) –The path of the source step.
-
(targets¶list[SourceStepPath]) –The paths of the target source steps.
-
(resolver¶ResolverStepPath) –The resolver path to use for matching.
create_collection
abstractmethod
¶
create_collection(name: CollectionName, permissions: list[PermissionGrant]) -> Collection
Create a new collection.
Parameters:
-
(name¶CollectionName) –The collection name
-
(permissions¶list[PermissionGrant]) –A list of permissions to grant
Returns:
-
Collection–A Collection object containing its metadata, versions, and steps.
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 steps.
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 steps.
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 steps.
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 steps.
delete_run
abstractmethod
¶
delete_run(collection: CollectionName, run_id: RunID, certain: bool) -> None
create_step
abstractmethod
¶
get_step
abstractmethod
¶
update_step
abstractmethod
¶
delete_step
abstractmethod
¶
lock_step_data
abstractmethod
¶
unlock_step_data
abstractmethod
¶
get_step_stage
abstractmethod
¶
get_step_stage(path: StepPath) -> UploadStage
insert_source_data
abstractmethod
¶
insert_source_data(path: SourceStepPath, data_hashes: Table) -> None
Insert hash data for a source step.
Only possible if data fingerprint matches fingerprint declared when the step was created. Data can only be set once on a step.
Parameters:
-
(path¶SourceStepPath) –The path of the source step to index.
-
(data_hashes¶Table) –The Arrow table with the hash of each data row
insert_model_data
abstractmethod
¶
insert_model_data(path: ModelStepPath, results: Table) -> None
Insert results data for a model step.
Only possible if data fingerprint matches fingerprint declared when the step was created. Data can only be set once on a step.
insert_resolver_data
abstractmethod
¶
insert_resolver_data(path: ResolverStepPath, data: Table) -> None
Insert resolver cluster assignments for a resolver step.
get_model_data
abstractmethod
¶
get_model_data(path: ModelStepPath) -> Table
Get the results for a model step.
get_resolver_data
abstractmethod
¶
get_resolver_data(path: ResolverStepPath) -> Table
Get cluster assignments for a resolver step.
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
¶
login(user: User) -> LoginResponse
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
flowchart TD
matchbox.server.MatchboxServerSettings[MatchboxServerSettings]
click matchbox.server.MatchboxServerSettings href "" "matchbox.server.MatchboxServerSettings"
Settings for the Matchbox application.
Methods:
-
validate_public_key–Validate and normalise PEM public key format.
-
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(SecretBytes | 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.
-
DEFAULT_GROUPS(list[Group]) –The default groups and users that should be in any fresh Matchbox backend.
-
DEFAULT_PERMISSIONS(list[tuple[PermissionGrant, BackendResourceType, str | None]]) –The default permissions that should be granted in any fresh Matchbox backend.
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.
DEFAULT_GROUPS
module-attribute
¶
DEFAULT_GROUPS: list[Group] = [Group(name=PUBLIC, description='Unauthenticated users.', is_system=True, members=[User(user_name=PUBLIC, email=None)]), Group(name='admins', description='System administrators.', is_system=True)]
The default groups and users that should be in any fresh Matchbox backend.
DEFAULT_PERMISSIONS
module-attribute
¶
DEFAULT_PERMISSIONS: list[tuple[PermissionGrant, BackendResourceType, str | None]] = [(PermissionGrant(group_name=ADMINS, permission=ADMIN), SYSTEM, None)]
The default permissions that should be granted in any fresh Matchbox backend.
A list of tuples in the form:
- The permission to grant
- The resource type to grant it on
- The resource name to grant it on, if applicable
MatchboxBackends
¶
MatchboxSnapshot
¶
Bases: BaseModel
flowchart TD
matchbox.server.base.MatchboxSnapshot[MatchboxSnapshot]
click matchbox.server.base.MatchboxSnapshot href "" "matchbox.server.base.MatchboxSnapshot"
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
flowchart TD
matchbox.server.base.MatchboxDatastoreSettings[MatchboxDatastoreSettings]
click matchbox.server.base.MatchboxDatastoreSettings href "" "matchbox.server.base.MatchboxDatastoreSettings"
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
flowchart TD
matchbox.server.base.MatchboxServerSettings[MatchboxServerSettings]
click matchbox.server.base.MatchboxServerSettings href "" "matchbox.server.base.MatchboxServerSettings"
Settings for the Matchbox application.
Methods:
-
validate_public_key–Validate and normalise PEM public key format.
-
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(SecretBytes | 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
¶
flowchart TD
matchbox.server.base.ListableAndCountable[ListableAndCountable]
matchbox.server.base.Countable[Countable]
matchbox.server.base.Listable[Listable]
matchbox.server.base.Countable --> matchbox.server.base.ListableAndCountable
matchbox.server.base.Listable --> matchbox.server.base.ListableAndCountable
click matchbox.server.base.ListableAndCountable href "" "matchbox.server.base.ListableAndCountable"
click matchbox.server.base.Countable href "" "matchbox.server.base.Countable"
click matchbox.server.base.Listable href "" "matchbox.server.base.Listable"
A protocol for objects that can be counted and listed.
Methods:
MatchboxDBAdapter
¶
Bases: ABC
flowchart TD
matchbox.server.base.MatchboxDBAdapter[MatchboxDBAdapter]
click matchbox.server.base.MatchboxDBAdapter href "" "matchbox.server.base.MatchboxDBAdapter"
An abstract base class for Matchbox database adapters.
By default the database should contain the users, groups and permissions found in DEFAULT_GROUPS and DEFAULT_PERMISSIONS.
Methods:
-
query–Queries the database from an optional resolution.
-
match–Match an ID in a source step and return 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 steps.
-
delete_run–Delete a run and all its steps.
-
create_step–Write a step to Matchbox.
-
get_step–Get a step from its path.
-
update_step–Update step metadata.
-
delete_step–Delete a step from the database.
-
lock_step_data–Change step upload stage to PROCESSING.
-
unlock_step_data–Change step upload stage to READY.
-
get_step_stage–Retrieve upload stage of step data.
-
insert_source_data–Insert hash data for a source step.
-
insert_model_data–Insert results data for a model step.
-
insert_resolver_data–Insert resolver cluster assignments for a resolver step.
-
get_model_data–Get the results for a model step.
-
get_resolver_data–Get cluster assignments for a resolver step.
-
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) – -
resolvers(Countable) – -
source_clusters(Countable) – -
model_clusters(Countable) – -
all_clusters(Countable) – -
creates(Countable) – -
merges(Countable) – -
proposes(Countable) – -
source_steps(Countable) – -
users(Countable) –
query
abstractmethod
¶
query(source: SourceStepPath, resolver: ResolverStepPath | None = None, return_leaf_id: bool = False, limit: int | None = None) -> Table
Queries the database from an optional resolution.
Parameters:
-
(source¶SourceStepPath) –The step path identifying the source to query.
-
(resolver¶optional, default:None) –The resolver path to use for filtering results. If not specified, the source step is used for the queried source.
-
(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: SourceStepPath, targets: list[SourceStepPath], resolver: ResolverStepPath) -> list[Match]
Match an ID in a source step and return the keys in the targets.
Parameters:
-
(key¶str) –The key to match from the source.
-
(source¶SourceStepPath) –The path of the source step.
-
(targets¶list[SourceStepPath]) –The paths of the target source steps.
-
(resolver¶ResolverStepPath) –The resolver path to use for matching.
create_collection
abstractmethod
¶
create_collection(name: CollectionName, permissions: list[PermissionGrant]) -> Collection
Create a new collection.
Parameters:
-
(name¶CollectionName) –The collection name
-
(permissions¶list[PermissionGrant]) –A list of permissions to grant
Returns:
-
Collection–A Collection object containing its metadata, versions, and steps.
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 steps.
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 steps.
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 steps.
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 steps.
delete_run
abstractmethod
¶
delete_run(collection: CollectionName, run_id: RunID, certain: bool) -> None
create_step
abstractmethod
¶
get_step
abstractmethod
¶
update_step
abstractmethod
¶
delete_step
abstractmethod
¶
lock_step_data
abstractmethod
¶
unlock_step_data
abstractmethod
¶
get_step_stage
abstractmethod
¶
get_step_stage(path: StepPath) -> UploadStage
insert_source_data
abstractmethod
¶
insert_source_data(path: SourceStepPath, data_hashes: Table) -> None
Insert hash data for a source step.
Only possible if data fingerprint matches fingerprint declared when the step was created. Data can only be set once on a step.
Parameters:
-
(path¶SourceStepPath) –The path of the source step to index.
-
(data_hashes¶Table) –The Arrow table with the hash of each data row
insert_model_data
abstractmethod
¶
insert_model_data(path: ModelStepPath, results: Table) -> None
Insert results data for a model step.
Only possible if data fingerprint matches fingerprint declared when the step was created. Data can only be set once on a step.
insert_resolver_data
abstractmethod
¶
insert_resolver_data(path: ResolverStepPath, data: Table) -> None
Insert resolver cluster assignments for a resolver step.
get_model_data
abstractmethod
¶
get_model_data(path: ModelStepPath) -> Table
Get the results for a model step.
get_resolver_data
abstractmethod
¶
get_resolver_data(path: ResolverStepPath) -> Table
Get cluster assignments for a resolver step.
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
¶
login(user: User) -> LoginResponse
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.