Skip to main content

FalkorDB embedded in a Python package

Project description

FalkorDBLite

CI Publish to PyPI Coverage License

Description

FalkorDBLite is a self-contained Python interface to the FalkorDB graph database.

It provides enhanced versions of the Redis-Py Python bindings with FalkorDB graph database functionality. Key features include:

  • Easy to use - It provides a built-in Redis server with FalkorDB module that is automatically installed, configured and managed when the bindings are used.
  • Graph Database - Full support for FalkorDB graph operations using Cypher queries through a simple Python API.
  • Flexible - Create a single server shared by multiple programs or multiple independent servers with graph capabilities.
  • Compatible - Provides both Redis key-value operations and FalkorDB graph operations in a unified interface.
  • Secure - Uses a secure default Redis configuration that is only accessible by the creating user on the computer system it is run on.

Installation

To install falkordblite, simply:

$ pip install falkordblite

Verifying Installation

After installation, you can verify that everything is working correctly:

$ python verify_install.py

This will test:

  • Package imports
  • FalkorDB instance creation
  • Basic graph operations

Requirements

The falkordblite module requires Python 3.12 or higher.

Runtime Requirements

The package requires the following Python packages (automatically installed with pip):

  • redis>=4.5 - Redis Python client
  • psutil - Process and system utilities
  • setuptools>38.0 - Build system

macOS Runtime Requirements

Important: The FalkorDB module requires the OpenMP runtime library (libomp). If you encounter an error like Library not loaded: /opt/homebrew/opt/libomp/lib/libomp.dylib, install it using Homebrew:

brew install libomp

Getting Started

FalkorDBLite provides two main interfaces:

  1. FalkorDB Graph API - A graph database interface using Cypher queries
  2. Redis API - Traditional Redis key-value operations (via redislite compatibility)

The package includes both Redis and the FalkorDB module, automatically configured and managed.

Examples

Here are some examples of using the falkordblite module.

Using FalkorDB Graph Database

Here we create a graph database, add some nodes and relationships, and query them using Cypher:

from redislite.falkordb_client import FalkorDB

# Create a FalkorDB instance with embedded Redis + FalkorDB
db = FalkorDB('/tmp/falkordb.db')

# Select a graph
g = db.select_graph('social')

# Create nodes with Cypher
result = g.query('CREATE (p:Person {name: "Alice", age: 30}) RETURN p')
result = g.query('CREATE (p:Person {name: "Bob", age: 25}) RETURN p')

# Create a relationship
result = g.query('''
    MATCH (a:Person {name: "Alice"}), (b:Person {name: "Bob"})
    CREATE (a)-[r:KNOWS]->(b)
    RETURN r
''')

# Query the graph
result = g.query('MATCH (p:Person) RETURN p.name, p.age')
for row in result.result_set:
    print(row)

# Read-only query
result = g.ro_query('MATCH (p:Person)-[r:KNOWS]->(f) RETURN p.name, f.name')

# Delete the graph when done
g.delete()

Using Redis Key-Value Operations

You can still use traditional Redis operations alongside graph operations:

from redislite import Redis

redis_connection = Redis('/tmp/redis.db')
redis_connection.keys()
# []
redis_connection.set('key', 'value')
# True
redis_connection.get('key')
# b'value'

Persistence

FalkorDB data persists between sessions. Open the same database file to access previously stored graphs:

from redislite.falkordb_client import FalkorDB

# Open the same database
db = FalkorDB('/tmp/falkordb.db')
g = db.select_graph('social')

# Data from previous session is still there
result = g.query('MATCH (p:Person) RETURN p.name')
for row in result.result_set:
    print(row)

Compatibility

It's possible to MonkeyPatch the normal Redis classes to allow modules that use Redis to use the redislite classes. Here we patch Redis and use the redis_collections module.

import redislite.patch
redislite.patch.patch_redis()
import redis_collections

td = redis_collections.Dict()
td['foo'] = 'bar'
td.keys()
# ['foo']

Running and using Multiple servers

Redislite will start a new server if the redis rdb filename isn't specified or is new. In this example we start 10 separate redis servers and set the value of the key 'servernumber' to a different value in each server.

Then we access the value of 'servernumber' and print it.

import redislite

servers = {}
for redis_server_number in range(10):
    servers[redis_server_number] = redislite.Redis()
    servers[redis_server_number].set('servernumber', redis_server_number)

for redis_server in servers.values():
    print(redis_server.get('servernumber'))
# b'0'
# b'1'
# b'2'
# b'3'
# b'4'
# b'5'
# b'6'
# b'7'
# b'8'
# b'9'

Multiple Servers with different configurations in the same script

It's possible to spin up multiple instances with different configuration settings for the Redis server. Here is an example that sets up 2 redis server instances. One instance is configured to listen on port 8002, the second instance is a read-only slave of the first instance.

import redislite

master = redislite.Redis(serverconfig={'port': '8002'})
slave = redislite.Redis(serverconfig={'slaveof': "127.0.0.1 8002"})
slave.keys()
# []
master.set('key', 'value')
# True
master.keys()
# ['key']
slave.keys()
# ['key']

FalkorDB-Specific Features

Graph Database with Cypher Queries

FalkorDBLite provides full support for graph database operations using Cypher queries:

from redislite.falkordb_client import FalkorDB

db = FalkorDB('/tmp/graphs.db')
g = db.select_graph('social')

# Create a graph with nodes and relationships
g.query('''
    CREATE (alice:Person {name: "Alice", age: 30}),
           (bob:Person {name: "Bob", age: 25}),
           (carol:Person {name: "Carol", age: 28}),
           (alice)-[:KNOWS]->(bob),
           (bob)-[:KNOWS]->(carol),
           (alice)-[:KNOWS]->(carol)
''')

# Find all friends of Alice
result = g.query('''
    MATCH (p:Person {name: "Alice"})-[:KNOWS]->(friend)
    RETURN friend.name, friend.age
''')
for row in result.result_set:
    print(f"Friend: {row[0]}, Age: {row[1]}")

Multiple Graphs

Work with multiple independent graphs in the same database:

from redislite.falkordb_client import FalkorDB

db = FalkorDB('/tmp/multi.db')

# Create different graphs for different domains
users = db.select_graph('users')
products = db.select_graph('products')
transactions = db.select_graph('transactions')

# Each graph is independent
users.query('CREATE (u:User {name: "Alice"})')
products.query('CREATE (p:Product {name: "Laptop"})')

# List all graphs
all_graphs = db.list_graphs()
print(all_graphs)

More Information

FalkorDBLite combines the power of Redis and FalkorDB graph database in an embedded Python package.

FalkorDBLite is Free software under the New BSD license, see LICENSE.txt for details.

Building from Source

If you want to build FalkorDBLite from source instead of using the PyPI package, follow these instructions.

System Requirements for Building

Linux

Make sure Python development headers and build tools are available when building from source.

On Ubuntu/Debian systems, install them with:

apt-get install python3-dev build-essential

On Redhat/Fedora systems, install them with:

yum install python3-devel gcc make

macOS

To build FalkorDBLite on macOS from the sdist package, you will need the XCode command line utilities installed. If you do not have xcode installed on recent macOS releases, they can be installed by running:

xcode-select --install

Windows

Redislite can be installed on newer releases of Windows 10 under the Bash on Ubuntu shell.

Install it using the instructions at https://msdn.microsoft.com/commandline/wsl/install_guide

Then start the bash shell and install the python-dev package as follows:

apt-get install python-dev

Building and Installing

To build from source:

$ pip install -r requirements.txt
$ python setup.py install

Development Installation

For development or working from source in a virtual environment:

# Create and activate a virtual environment
$ python3 -m venv venv
$ source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install build dependencies
$ pip install setuptools wheel

# Install runtime dependencies
$ pip install -r requirements.txt

# Build the project (this compiles Redis and copies binaries automatically)
$ python setup.py build

# Install in editable mode for development
$ pip install -e .

The python setup.py build command will:

  • Compile Redis from source
  • Download the FalkorDB module
  • Automatically copy binaries to redislite/bin/ with proper permissions

Note: If you encounter issues, see TROUBLESHOOTING.md for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

falkordblite-0.4.0.tar.gz (16.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

falkordblite-0.4.0-cp314-cp314-manylinux_2_39_x86_64.whl (40.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

falkordblite-0.4.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl (21.9 MB view details)

Uploaded CPython 3.14macOS 10.15+ x86-64macOS 15.0+ ARM64

falkordblite-0.4.0-cp313-cp313-manylinux_2_39_x86_64.whl (40.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

falkordblite-0.4.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl (21.9 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64macOS 15.0+ ARM64

falkordblite-0.4.0-cp312-cp312-manylinux_2_39_x86_64.whl (40.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

falkordblite-0.4.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl (21.9 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64macOS 15.0+ ARM64

File details

Details for the file falkordblite-0.4.0.tar.gz.

File metadata

  • Download URL: falkordblite-0.4.0.tar.gz
  • Upload date:
  • Size: 16.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for falkordblite-0.4.0.tar.gz
Algorithm Hash digest
SHA256 66d7d2393aa7e075351e785272462d08b2c3660e7a35326007297d778cdaa0bb
MD5 f3f810adc058217409642fae4a51676c
BLAKE2b-256 a624f1435e3ac5c4495eb1efde3752afffc6784b9086f1a36b1e3cbe10199b78

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0.tar.gz:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7a7b79146abfbcc19b7f049acba8c3a586c3f4e08111c324b397503a947a260c
MD5 67fd24cb6afee7f5e437fb3077ccd6fe
BLAKE2b-256 6ba33dd22958a845a898eb26176be0d69431a560bdeeedb0a814f5a790bb51c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp314-cp314-manylinux_2_39_x86_64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 909452c7b4d3cb9c4971f93bda3dcc7372cc880a0ee711cbda2ef8533309b26e
MD5 10a106270d02df19471e89c242be01aa
BLAKE2b-256 69130d3c89877db6042827986ca37c3f97854db70b91db6efb1adef77c4112d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 dcc99f9ba97eaf83b5b5fe102343d8af1e1f547d4663c2adffed14c012b6d3dd
MD5 f74797514ed0b12ccc66e565c04489ef
BLAKE2b-256 6e7587320fa7e095fe4414fb0e2b0f2ded716942caf213e1b29a67bedf1a6005

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp313-cp313-manylinux_2_39_x86_64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2ce312be773d334f0981c7895a624a5536ef4ea9e817f94923dbd9f865097a92
MD5 8e85d503a321a8866f768973fe20f26c
BLAKE2b-256 49dfbce76cbefb647f4138b29e326831cba7c505960d0090522916eb5ecc1a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6f7c213e28ac844167e6462b871dc09e9b3c1e528f5de962a228880b232e8bf1
MD5 f1ef3ffcbe1c5aa2979b1ecc56c4a4fd
BLAKE2b-256 2558af1f58a04def57f873df4cc287e4d127fd12fd4fcf3706230027dbf2d8cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp312-cp312-manylinux_2_39_x86_64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file falkordblite-0.4.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.4.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 8eeab6267dca99a8c43f3f810b93da17ea121f11588b6637c0f8155602ddbcd9
MD5 1f96fd9e81023d4161f5d60973356c76
BLAKE2b-256 79ada8e543f8ab9152868d7939ad948a1f3d5bd09a8d8c7909a573c03bc6df8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.4.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl:

Publisher: publish.yml on FalkorDB/falkordblite

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page