falkordb.asyncio package

Submodules

falkordb.asyncio.cluster module

falkordb.asyncio.cluster.Cluster_Conn(conn, ssl, cluster_error_retry_attempts=3, startup_nodes=None, require_full_coverage=False, reinitialize_steps=5, read_from_replicas=False, address_remap=None)[source]
falkordb.asyncio.cluster.Is_Cluster(conn: Redis)[source]

falkordb.asyncio.falkordb module

class falkordb.asyncio.falkordb.FalkorDB(host='localhost', port=6379, password=None, socket_timeout=None, socket_connect_timeout=None, socket_keepalive=None, socket_keepalive_options=None, connection_pool=None, unix_socket_path=None, encoding='utf-8', encoding_errors='strict', retry_on_error=None, ssl=False, ssl_keyfile=None, ssl_certfile=None, ssl_cert_reqs='required', ssl_ca_certs=None, ssl_ca_data=None, ssl_check_hostname=False, max_connections=None, single_connection_client=False, health_check_interval=0, client_name=None, lib_name='FalkorDB', lib_version=None, username=None, retry=None, connect_func=None, credential_provider=None, protocol=2, cluster_error_retry_attempts=3, startup_nodes=None, require_full_coverage=False, reinitialize_steps=5, read_from_replicas=False, address_remap=None)[source]

Bases: object

Asynchronous FalkorDB Class for interacting with a FalkorDB server.

Supports both TCP and Unix socket connections.

Usage example::

from falkordb.asyncio import FalkorDB # connect to the database and select the ‘social’ graph db = FalkorDB() graph = db.select_graph(“social”)

# connect using a Unix socket db = FalkorDB.from_url(“unix:///path/to/redis.sock”) graph = db.select_graph(“social”)

# get a single ‘Person’ node from the graph and print its name response = await graph.query(“MATCH (n:Person) RETURN n LIMIT 1”) result = response.result_set person = result[0][0] print(person.properties[‘name’])

async aclose() None[source]

Close the underlying connection(s).

async config_get(name: str) int | str[source]

Retrieve a DB level configuration. For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

Args:

name (str): The name of the configuration.

Returns:

int or str: The configuration value.

async config_set(name: str, value=None) None[source]

Update a DB level configuration. For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

Args:

name (str): The name of the configuration. value: The value to set.

Returns:

None

classmethod from_url(url: str, **kwargs) FalkorDB[source]

Creates a new FalkorDB instance from a URL.

Args:

cls: The class itself. url (str): The URL. kwargs: Additional keyword arguments to pass to the

DB.from_url function.

Returns:

DB: A new DB instance.

Usage example:: db = FalkorDB.from_url(“falkor://[[username]:[password]]@localhost:6379”) db = FalkorDB.from_url(“falkors://[[username]:[password]]@localhost:6379”) db = FalkorDB.from_url(“unix://[username@]/path/to/socket.sock?db=0[&password=password]”)

async list_graphs() List[str][source]

Lists all graph names. See: https://docs.falkordb.com/commands/graph.list.html

Returns:

List: List of graph names.

select_graph(graph_id: str) AsyncGraph[source]

Selects a graph by creating a new Graph instance.

Args:

graph_id (str): The identifier of the graph.

Returns:

AsyncGraph: A new Graph instance associated with the selected graph.

async udf_delete(lib: str)[source]

Delete a User Defined Function (UDF) library.

Args:

lib (str): The name of the library to delete.

async udf_flush()[source]

Flush (remove) all User Defined Function (UDF) libraries.

async udf_list(lib: str | None = None, with_code: bool = False)[source]

List User Defined Function (UDF) libraries.

Args:
lib (str, optional): If provided, filter the list to

this specific library.

with_code (bool, optional): If True, include the library

source code in the result. Defaults to False.

Returns:

list: A list of UDF libraries and their metadata.

async udf_load(name: str, script: str, replace: bool = False)[source]

Load a User Defined Function (UDF) library.

Args:

name (str): The name of the library to load. script (str): The UDF script contents. replace (bool, optional): If True, replace an existing

library with the same name. Defaults to False.

falkordb.asyncio.graph module

class falkordb.asyncio.graph.AsyncGraph(client, name: str)[source]

Bases: Graph

Graph, collection of nodes and edges.

async call_procedure(procedure: str, read_only: bool = True, args: List | None = None, emit: List[str] | None = None) QueryResult[source]

Call a procedure.

Args:

procedure (str): The procedure to call. read_only (bool): Whether the procedure is read-only. args: Procedure arguments. emit: Procedure yield.

Returns:

QueryResult: The result of the procedure call.

async copy(clone: str)[source]

Creates a copy of graph

Args:

clone (str): Name of cloned graph

Returns:

AsyncGraph: the cloned graph

async create_edge_fulltext_index(relation: str, *properties) QueryResult[source]

Create a full-text index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#full-text-indexing

Args:

relation (str): The relation of the edge. properties: Variable number of property names to be indexed.

Returns:

Any: The result of the index creation query.

async create_edge_mandatory_constraint(relation: str, *properties)[source]

Create edge mandatory constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

The constraint is created asynchronously, use list constraints to pull on constraint creation status

Args:

relation (str): Edge relationship-type to apply constraint to properties: Variable number of property names to constrain

async create_edge_range_index(relation: str, *properties) QueryResult[source]

Create a range index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#creating-an-index-for-a-relationship-type

Args:

relation (str): The relation of the edge. properties: Variable number of property names to be indexed.

Returns:

Any: The result of the index creation query.

async create_edge_unique_constraint(relation: str, *properties)[source]

Create edge unique constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

The constraint is created asynchronously, use list constraints to pull on constraint creation status

Note: unique constraints require the existence of a range index over the constraint properties, this function will create any missing range indices

Args:

relation (str): Edge relationship-type to apply constraint to properties: Variable number of property names to constrain

async create_edge_vector_index(relation: str, *properties, dim: int = 0, similarity_function: str = 'euclidean') QueryResult[source]

Create a vector index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#vector-indexing

Args:

relation (str): The relation of the edge. properties: Variable number of property names to be indexed. dim (int, optional): The dimension of the vector. similarity_function (str, optional): The similarity function for the vector.

Returns:

Any: The result of the index creation query.

async create_node_fulltext_index(label: str, *properties) QueryResult[source]

Create a full-text index for a node. See: https://docs.falkordb.com/commands/graph.query.html#creating-a-full-text-index-for-a-node-label

Args:

label (str): The label of the node. properties: Variable number of property names to be indexed.

Returns:

Any: The result of the index creation query.

async create_node_mandatory_constraint(label: str, *properties)[source]

Create node mandatory constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

The constraint is created asynchronously, use list constraints to pull on constraint creation status

Args:

label (str): Node label to apply constraint to properties: Variable number of property names to constrain

async create_node_range_index(label: str, *properties) QueryResult[source]

Create a range index for a node. See: https://docs.falkordb.com/commands/graph.query.html#creating-an-index-for-a-node-label

Args:

label (str): The label of the node. properties: Variable number of property names to be indexed.

Returns:

Any: The result of the index creation query.

async create_node_unique_constraint(label: str, *properties)[source]

Create node unique constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

The constraint is created asynchronously, use list constraints to pull on constraint creation status

Note: unique constraints require the existence of a range index over the constraint properties, this function will create any missing range indices

Args:

label (str): Node label to apply constraint to properties: Variable number of property names to constrain

async create_node_vector_index(label: str, *properties, dim: int = 0, similarity_function: str = 'euclidean') QueryResult[source]

Create a vector index for a node. See: https://docs.falkordb.com/commands/graph.query.html#vector-indexing

Args:

label (str): The label of the node. properties: Variable number of property names to be indexed. dim (int, optional): The dimension of the vector. similarity_function (str, optional): The similarity function for the vector.

Returns:

Any: The result of the index creation query.

async delete() None[source]

Deletes the graph. See: https://docs.falkordb.com/commands/graph.delete.html

Returns:

None

async drop_edge_fulltext_index(label: str, attribute: str) QueryResult[source]

Drop a full-text index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-relationship-type

Args:

label (str): The label of the edge. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async drop_edge_mandatory_constraint(relation: str, *properties)[source]

Drop edge mandatory constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

Args:

label (str): Edge relationship-type to remove the constraint from properties: properties to remove constraint from

async drop_edge_range_index(label: str, attribute: str) QueryResult[source]

Drop a range index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-relationship-type

Args:

label (str): The label of the edge. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async drop_edge_unique_constraint(relation: str, *properties)[source]

Drop edge unique constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

Note: the constraint supporting range index is not removed

Args:

label (str): Edge relationship-type to remove the constraint from properties: properties to remove constraint from

async drop_edge_vector_index(label: str, attribute: str) QueryResult[source]

Drop a vector index for an edge. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-relationship-type

Args:

label (str): The label of the edge. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async drop_node_fulltext_index(label: str, attribute: str) QueryResult[source]

Drop a full-text index for a node. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-node-label

Args:

label (str): The label of the node. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async drop_node_mandatory_constraint(label: str, *properties)[source]

Drop node mandatory constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

Args:

label (str): Node label to remove the constraint from properties: properties to remove constraint from

async drop_node_range_index(label: str, attribute: str) QueryResult[source]

Drop a range index for a node. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-node-label

Args:

label (str): The label of the node. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async drop_node_unique_constraint(label: str, *properties)[source]

Drop node unique constraint See: https://docs.falkordb.com/commands/graph.constraint-create.html

Note: the constraint supporting range index is not removed

Args:

label (str): Node label to remove the constraint from properties: properties to remove constraint from

async drop_node_vector_index(label: str, attribute: str) QueryResult[source]

Drop a vector index for a node. See: https://docs.falkordb.com/commands/graph.query.html#deleting-an-index-for-a-node-label

Args:

label (str): The label of the node. attribute (str): The attribute to drop the index on.

Returns:

Any: The result of the index dropping query.

async explain(query: str, params=None) ExecutionPlan[source]

Get the execution plan for a given query. GRAPH.EXPLAIN returns an ExecutionPlan object. See: https://docs.falkordb.com/commands/graph.explain.html

Args:

query (str): The query for which to get the execution plan. params (dict): Query parameters.

Returns:

ExecutionPlan: The execution plan.

async list_constraints() List[Dict[str, object]][source]

Lists graph’s constraints

See: https://docs.falkordb.com/commands/graph.constraint-create.html#listing-constraints

Returns:

[Dict[str, object]]: list of constraints

async list_indices() QueryResult[source]

Retrieve a list of graph indices. See: https://docs.falkordb.com/commands/graph.query.html#procedures

Returns:

list: List of graph indices.

async profile(query: str, params=None) ExecutionPlan[source]

Execute a query and produce an execution plan augmented with metrics for each operation’s execution. Return an execution plan, with details on results produced by and time spent in each operation. See: https://docs.falkordb.com/commands/graph.profile.html

Args:

query (str): The query to profile. params (dict): Query parameters.

Returns:

ExecutionPlan: The profile information.

async query(q: str, params: Dict[str, object] | None = None, timeout: int | None = None) QueryResult[source]

Executes a query asynchronously against the graph. See: https://docs.falkordb.com/commands/graph.query.html

Args:

q (str): The query. params (dict): Query parameters. timeout (int): Maximum query runtime in milliseconds.

Returns:

QueryResult: query result set.

async ro_query(q: str, params: Dict[str, object] | None = None, timeout: int | None = None) QueryResult[source]

Executes a read-only query against the graph. See: https://docs.falkordb.com/commands/graph.ro_query.html

Args:

q (str): The query. params (dict): Query parameters. timeout (int): Maximum query runtime in milliseconds.

Returns:

QueryResult: query result set.

async slowlog()[source]

Get a list containing up to 10 of the slowest queries issued against the graph.

Each item in the list has the following structure: 1. a unix timestamp at which the log entry was processed 2. the issued command 3. the issued query 4. the amount of time needed for its execution, in milliseconds.

See: https://docs.falkordb.com/commands/graph.slowlog.html

Returns:

List: List of slow log entries.

async slowlog_reset()[source]

Reset the slowlog. See: https://docs.falkordb.com/commands/graph.slowlog.html

Returns:

None

falkordb.asyncio.graph_schema module

class falkordb.asyncio.graph_schema.GraphSchema(graph)[source]

Bases: object

The graph schema. Maintains the labels, properties and relationships of the graph.

clear()[source]

Clear the graph schema.

Returns:

None

async get_label(idx: int) str[source]

Returns a label by its index.

Args:

idx (int): The index of the label.

Returns:

str: The label.

async get_property(idx: int) str[source]

Returns a property by its index.

Args:

idx (int): The index of the property.

Returns:

str: The property.

async get_relation(idx: int) str[source]

Returns a relationship type by its index.

Args:

idx (int): The index of the relation.

Returns:

str: The relationship type.

async refresh(version: int) None[source]

Refresh the graph schema.

Args:

version (int): The version of the graph schema.

Returns:

None

async refresh_labels() None[source]

Refresh labels.

Returns:

None

async refresh_properties() None[source]

Refresh property keys.

Returns:

None

async refresh_relations() None[source]

Refresh relationship types.

Returns:

None

falkordb.asyncio.query_result module

class falkordb.asyncio.query_result.QueryResult(graph)[source]

Bases: object

Represents the result of a query operation on a graph.

property cached_execution: bool

Check if the query execution plan was cached.

Returns:

bool: True if the query execution plan was cached, False otherwise.

property indices_created: int

Get the number of indices created in the query.

Returns:

int: The number of indices created.

property indices_deleted: int

Get the number of indices deleted in the query.

Returns:

int: The number of indices deleted.

property labels_added: int

Get the number of labels added in the query.

Returns: int: The number of labels added.

property labels_removed: int

Get the number of labels removed in the query.

Returns:

int: The number of labels removed.

property nodes_created: int

Get the number of nodes created in the query.

Returns:

int: The number of nodes created.

property nodes_deleted: int

Get the number of nodes deleted in the query.

Returns:

int: The number of nodes deleted.

async parse(response)[source]

Parse the response from the server.

Args:

response: The response from the server.

property properties_removed: int

Get the number of properties removed in the query.

Returns:

int: The number of properties removed.

property properties_set: int

Get the number of properties set in the query.

Returns:

int: The number of properties set.

property relationships_created: int

Get the number of relationships created in the query.

Returns:

int: The number of relationships created.

property relationships_deleted: int

Get the number of relationships deleted in the query.

Returns:

int: The number of relationships deleted.

property run_time_ms: float

Get the server execution time of the query.

Returns:

float: The server execution time of the query in milliseconds.

class falkordb.asyncio.query_result.ResultSetScalarTypes(*values)[source]

Bases: Enum

Enumeration representing different scalar types in the query result set.

Attributes:

VALUE_UNKNOWN (int): Unknown scalar type (0) VALUE_NULL (int): Null scalar type (1) VALUE_STRING (int): String scalar type (2) VALUE_INTEGER (int): Integer scalar type (3) VALUE_BOOLEAN (int): Boolean scalar type (4) VALUE_DOUBLE (int): Double scalar type (5) VALUE_ARRAY (int): Array scalar type (6) VALUE_EDGE (int): Edge scalar type (7) VALUE_NODE (int): Node scalar type (8) VALUE_PATH (int): Path scalar type (9) VALUE_MAP (int): Map scalar type (10) VALUE_POINT (int): Point scalar type (11) VALUE_VECTORF32 (int): Vector scalar type (12) VALUE_DATETIME (int): DateTime scalar type (13) VALUE_DATE (int): Date scalar type (14) VALUE_TIME (int): Time scalar type (15) VALUE_DURATION (int): Duration scalar type (16)

VALUE_ARRAY = 6
VALUE_BOOLEAN = 4
VALUE_DATE = 14
VALUE_DATETIME = 13
VALUE_DOUBLE = 5
VALUE_DURATION = 16
VALUE_EDGE = 7
VALUE_INTEGER = 3
VALUE_MAP = 10
VALUE_NODE = 8
VALUE_NULL = 1
VALUE_PATH = 9
VALUE_POINT = 11
VALUE_STRING = 2
VALUE_TIME = 15
VALUE_UNKNOWN = 0
VALUE_VECTORF32 = 12
async falkordb.asyncio.query_result.parse_scalar(value, graph)[source]

Parse a scalar value from a value in the result set.

Args:

value: The value to parse. graph: The graph instance.

Returns:

Any: The parsed scalar value.

Module contents