Utils
Miscellaneous utility functions for ApertureDB. This class contains a collection of helper functions to interact with the database.
Utils
Utils(client: Connector, verbose=False)
Bases: object
Helper methods to get information from aperturedb, or affect it's state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client | Connector | The underlying Connector. | required |
verbose | bool | Whether to print progress messages. Defaults to False. | False |
execute
execute(query, blobs=[], success_statuses=[0])
Execute a query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query | list | The query to execute. | required |
blobs | list | The blobs to send with the query. | [] |
success_statuses | list | The list of success statuses. | [0] |
Returns:
| Name | Type | Description |
|---|---|---|
result | The result of the query. | |
blobs | The blobs returned by the query. |
status
status()
Executes a GetStatus query. See GetStatus in the ApertureDB documentation for more information.
get_schema
get_schema(refresh=False)
Get the schema of the database. See GetSchema in the ApertureDB documentation for more information.
visualize_schema
visualize_schema(filename: str = None, format: str = 'png') -> Source
Visualize the schema of the database. Optionally save the visualization to a file in the specified format.
The returned object can be rendered to a file as follows:
s = utils.visualize_schema()
s.render("schema", format="png")
It can also be displayed inline in a Jupyter notebook:
from IPython.display import display
s = utils.visualize_schema()
display(s)
Relies on graphviz to be installed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename | str | The filename to save the visualization to. Default is None. | None |
format | str | The format to save the visualization to. Default is "png". | 'png' |
Returns:
| Name | Type | Description |
|---|---|---|
source | Source | The visualization of the schema. |
summary
summary()
Print a summary of the database.
This is essentially a call to GetSchema, with the results formatted in a more human-readable way.
create_entity_index
create_entity_index(class_name, property_key, property_type=None)
Create an index for an entity class. See CreateIndex in the ApertureDB documentation for more information.
create_connection_index
create_connection_index(class_name, property_key, property_type=None)
Create an index for a connection class. See CreateIndex in the ApertureDB documentation for more information.
remove_entity_index
remove_entity_index(class_name, property_key)
Remove an index for an entity class. See RemoveIndex in the ApertureDB documentation for more information.
remove_connection_index
remove_connection_index(class_name, property_key)
Remove an index for a connection class. See RemoveIndex in the ApertureDB documentation for more information.
count_images
count_images(constraints={}) -> int
Count the number of images in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints | dict | The constraints to apply to the query. See the | {} |
Returns:
| Name | Type | Description |
|---|---|---|
count | int | The number of images in the database. |
count_bboxes
count_bboxes(constraints=None) -> int
Count the number of bounding boxes in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints | dict | The constraints to apply to the query. See the | None |
Returns:
| Name | Type | Description |
|---|---|---|
count | int | The number of bounding boxes in the database. |
count_entities
count_entities(entity_class, constraints=None) -> int
Count the number of entities in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints | dict | The constraints to apply to the query. See the | None |
Returns:
| Name | Type | Description |
|---|---|---|
count | int | The number of entities in the database. |
count_connections
count_connections(connections_class, constraints=None) -> int
Count the number of connections in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraints | dict | The constraints to apply to the query. See the | None |
Returns:
| Name | Type | Description |
|---|---|---|
count | int | The number of connections in the database. |
add_descriptorset
add_descriptorset(name: str, dim: int, metric=['CS'], engine=['HNSW'], properties: Optional[Dict] = None) -> bool
Add a descriptor set to the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | The name of the descriptor set. | required |
dim | int | The dimension of the descriptors. | required |
metric | str | The metric to use for the descriptors. | ['CS'] |
engine | str | The engine to use for the descriptors. | ['HNSW'] |
properties | dict | The properties of the descriptor set. | None |
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
count_descriptorsets
count_descriptorsets() -> int
Count the number of descriptor sets in the database.
Returns:
| Name | Type | Description |
|---|---|---|
count | int | The number of descriptor sets in the database. |
get_descriptorset_list
get_descriptorset_list() -> List[str]
Get the list of descriptor sets in the database.
Returns:
| Name | Type | Description |
|---|---|---|
sets | list of str | The list of descriptor sets in the database. |
remove_descriptorset
remove_descriptorset(set_name: str) -> bool
Remove a descriptor set from the database.
See DeleteDescriptorSet in the ApertureDB documentation for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_name | str | The name of the descriptor set. | required |
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
remove_entities
remove_entities(class_name: str, batched: bool = False, batch_size: int = 10000) -> bool
Remove all entities of a given class from the database.
See DeleteEntity in the ApertureDB documentation for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name | str | The class of the entities to remove. | required |
batched | bool | Whether to batch the operation. Default is False. | False |
batch_size | int | The batch size to use. Default is 10000. | 10000 |
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
remove_connections
remove_connections(class_name, batched=False, batch_size=10000)
Remove all connections of a given class from the database.
See DeleteConnection in the ApertureDB documentation for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name | str | The class of the connections to remove. | required |
batched | bool | Whether to batch the operation. Default is False. | False |
batch_size | int | The batch size to use. Default is 10000. | 10000 |
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
remove_all_descriptorsets
remove_all_descriptorsets() -> bool
Remove all descriptor sets from the database, together with descriptors, indexes and connections.
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
get_indexed_props
get_indexed_props(class_name: str, type='entities') -> List[str]
Returns all the indexed properties for a given class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name | str | The class name. | required |
type | str | The type of the class. Default is "entities". | 'entities' |
Returns:
| Name | Type | Description |
|---|---|---|
indexed_props | list of str | The list of indexed properties. |
count_descriptors_in_set
count_descriptors_in_set(set_name: str) -> int
Count the number of descriptors in a descriptor set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
set_name | str | The name of the descriptor set. | required |
Returns:
| Name | Type | Description |
|---|---|---|
total | int | The number of descriptors in the set. |
get_indexes
get_indexes(target: Optional[str] = None, class_name: Optional[str] = None, property_key: Optional[str] = None, kind: Optional[str] = None) -> List[dict]
List index definitions, optionally filtered. See GetIndexes in the ApertureDB documentation for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target | str | "entity" or "connection". Defaults to both. | None |
class_name | str | Entity or connection class. | None |
property_key | str | Indexed property. | None |
kind | str | Index kind, such as "ordered". Defaults to all kinds. | None |
Returns:
| Name | Type | Description |
|---|---|---|
indexes | List[dict] | One dict per index with "target", "class", "property", "kind" and "params". |
remove_all_indexes
remove_all_indexes() -> bool
Remove all indexes from the database.
This may improve the performance of remove_all_objects. It may improve or degrade the performance of other operations.
Built-in indexes, which the server does not allow removing, are kept.
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
remove_all_objects
remove_all_objects() -> bool
Remove all objects from the database.
This includes images, videos, blobs, clips, descriptor sets, descriptors, bounding boxes, polygons, frames, entities, connections, indexes and connections.
Returns:
| Name | Type | Description |
|---|---|---|
success | bool | True if the operation was successful, False otherwise. |
user_log_message
user_log_message(message: str, level: str = 'INFO') -> None
Log a message to the user log.
This is useful because it can later be seen in Grafana, not only as log entries in the ApertureDB Logging dashboard, but also as event markers in the ApertureDB Status dashboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | The message to log. | required |
level | str | The level of the message. Default is "INFO". | 'INFO' |