FalkorDB Python Client

1.6.0 · active · verified Wed Apr 15

FalkorDB is a high-performance Knowledge Graph database tailored for Large Language Models (LLMs), leveraging sparse matrices and linear algebra for efficient querying with OpenCypher. The `falkordb` Python client provides an interface for interacting with a FalkorDB server instance. It is currently at version 1.6.0 and maintains an active release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a running FalkorDB instance, select or create a graph, insert data using Cypher queries, and retrieve results. It's crucial to have a FalkorDB server running (e.g., via Docker) before executing this code.

import os
from falkordb import FalkorDB

# Ensure FalkorDB server is running, e.g., via Docker:
# docker run -p 6379:6379 -p 3000:3000 -it --rm -v ./data:/var/lib/falkordb/data falkordb/falkordb

# Connect to FalkorDB (default host/port)
db = FalkorDB(host=os.environ.get('FALKORDB_HOST', 'localhost'), port=int(os.environ.get('FALKORDB_PORT', 6379)))

# Select a graph (or create if it doesn't exist)
g = db.select_graph('social')

# Create some data
create_query = """
CREATE (alice:User {id: 1, name: 'Alice', email: 'alice@example.com'})
CREATE (bob:User {id: 2, name: 'Bob', email: 'bob@example.com'})
CREATE (alice)-[:FRIENDS_WITH {since: 2020}]->(bob)
"""
g.query(create_query)

# Query the data
query = """
MATCH (u1:User)-[f:FRIENDS_WITH]->(u2:User)
RETURN u1.name, u2.name, f.since
"""

result = g.query(query)

# Print results
for record in result.result_set:
    print(f"{record[0]} is friends with {record[1]} since {record[2]}")

# Close the connection (important for resource management)
db.close()

view raw JSON →