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 multiple interfaces:

  1. FalkorDB Graph API - A graph database interface using Cypher queries
  2. Redis API - Traditional Redis key-value operations (via redislite compatibility)
  3. Async API - Asynchronous versions of both FalkorDB and Redis interfaces for async/await usage

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)

Async API

FalkorDBLite provides async/await support for non-blocking operations. This is particularly useful for web applications, concurrent workloads, and high-performance scenarios.

Async FalkorDB Graph Operations

Use AsyncFalkorDB and AsyncGraph for asynchronous graph database operations:

import asyncio
from redislite.async_falkordb_client import AsyncFalkorDB

async def main():
    # Create an async FalkorDB instance
    db = AsyncFalkorDB('/tmp/falkordb_async.db')
    
    # Select a graph
    g = db.select_graph('social')
    
    # Create nodes asynchronously using parameterized queries
    await g.query(
        'CREATE (p:Person {name: $name, age: $age}) RETURN p',
        params={'name': 'Alice', 'age': 30}
    )
    await g.query(
        'CREATE (p:Person {name: $name, age: $age}) RETURN p',
        params={'name': 'Bob', 'age': 25}
    )
    
    # Create a relationship using parameterized queries
    await g.query(
        '''
        MATCH (a:Person {name: $name_a}), (b:Person {name: $name_b})
        CREATE (a)-[r:KNOWS]->(b)
        RETURN r
        ''',
        params={'name_a': 'Alice', 'name_b': 'Bob'}
    )
    
    # Query the graph asynchronously
    result = await g.query('MATCH (p:Person) RETURN p.name, p.age')
    for row in result.result_set:
        print(row)
    
    # Read-only query
    result = await g.ro_query('MATCH (p:Person)-[r:KNOWS]->(f) RETURN p.name, f.name')
    
    # Clean up
    await g.delete()
    await db.close()

# Run the async function
asyncio.run(main())

Async Redis Operations

Use AsyncRedis for asynchronous Redis key-value operations:

import asyncio
from redislite.async_client import AsyncRedis

async def main():
    # Create an async Redis connection
    redis_conn = AsyncRedis('/tmp/redis_async.db')
    
    # Async set and get
    await redis_conn.set('key', 'value')
    value = await redis_conn.get('key')
    print(value)  # b'value'
    
    # Multiple operations concurrently
    await asyncio.gather(
        redis_conn.set('key1', 'value1'),
        redis_conn.set('key2', 'value2'),
        redis_conn.set('key3', 'value3'),
    )
    
    # Get all keys
    keys = await redis_conn.keys()
    print(keys)
    
    await redis_conn.close()

asyncio.run(main())

Async Context Manager

Both AsyncFalkorDB and AsyncRedis support async context managers for automatic cleanup:

import asyncio
from redislite.async_falkordb_client import AsyncFalkorDB

async def main():
    async with AsyncFalkorDB('/tmp/falkordb.db') as db:
        g = db.select_graph('social')
        result = await g.query(
            'CREATE (n:Person {name: $name}) RETURN n',
            params={'name': 'Alice'}
        )
        print(result.result_set)
    # Connection is automatically closed

asyncio.run(main())

Concurrent Graph Operations

The async API enables efficient concurrent operations:

import asyncio
from redislite.async_falkordb_client import AsyncFalkorDB

async def create_person(graph, name, age):
    """Create a person node asynchronously"""
    query = 'CREATE (p:Person {name: $name, age: $age}) RETURN p'
    return await graph.query(query, params={'name': name, 'age': age})

async def main():
    db = AsyncFalkorDB('/tmp/social.db')
    g = db.select_graph('social')
    
    # Create multiple nodes concurrently
    people = [
        ('Alice', 30),
        ('Bob', 25),
        ('Carol', 28),
        ('Dave', 35),
    ]
    
    # Execute all creates concurrently
    await asyncio.gather(
        *[create_person(g, name, age) for name, age in people]
    )
    
    # Query all people
    result = await g.query('MATCH (p:Person) RETURN p.name, p.age ORDER BY p.name')
    for row in result.result_set:
        print(f"{row[0]}, age {row[1]}")
    
    await g.delete()
    await db.close()

asyncio.run(main())

For complete async API documentation including web framework integration, see docs/ASYNC_API.md.

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.10.0.tar.gz (23.7 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.10.0-cp314-cp314-manylinux_2_39_x86_64.whl (36.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

falkordblite-0.10.0-cp314-cp314-manylinux_2_39_aarch64.whl (34.6 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ ARM64

falkordblite-0.10.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl (17.8 MB view details)

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

falkordblite-0.10.0-cp313-cp313-manylinux_2_39_x86_64.whl (36.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

falkordblite-0.10.0-cp313-cp313-manylinux_2_39_aarch64.whl (34.6 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ ARM64

falkordblite-0.10.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl (17.8 MB view details)

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

falkordblite-0.10.0-cp312-cp312-manylinux_2_39_x86_64.whl (36.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

falkordblite-0.10.0-cp312-cp312-manylinux_2_39_aarch64.whl (34.6 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ ARM64

falkordblite-0.10.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl (17.8 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for falkordblite-0.10.0.tar.gz
Algorithm Hash digest
SHA256 65a72abafd30711f699c15571df6959edb8901605053ce940ccdd837832e709b
MD5 6cf628c9f963d37d1f1f3ea0153a3f2a
BLAKE2b-256 7003afbb6e0f03c302aa9b64a38e1a2c43664f86921f0dcbf03ec9e31da06ac6

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b36665ebd9e2d5e38b401b34f7ba6f0b22e5b88cbc817971c8c1d71a8ad305f7
MD5 4901b9bba2b92957e5befb3d6ad8dd2b
BLAKE2b-256 3fa66eba83964a0633aeee698a1fbd23b954ce39ee4cfd7eced73f52d95ca89a

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp314-cp314-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp314-cp314-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 6cd10bb1b0e35946e0e4c06bd0c16298fe6df70e8e18bc055db0d60359c7271c
MD5 bbde407cb04cf450e170cde4b8a887b7
BLAKE2b-256 611376932987b43286443088be9d1ebdbc6999ac084d5c40dbfe4a4704aa264b

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.0-cp314-cp314-manylinux_2_39_aarch64.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.10.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp314-cp314-macosx_10_15_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 5eff806e09902b36f34a7c058de0dcf237f0ae047d2b39c0423a5d6a52193341
MD5 b04a85faa7b06d743d5a43f70d3fa753
BLAKE2b-256 ab57eb2ac5824f7831fcb550468cc504a944adfee1b0c5a09b4bc684b0217976

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 7d52a3665f6de30cbffc5809a1c6d722492c95bf8dae4a7ee108ca58da939b25
MD5 c71d66a9dedca3bfffa610b7eb12543f
BLAKE2b-256 2ecfd792cf46292f7756f96727916e77ebf9821371e22bff65ed8e90db6b80b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp313-cp313-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp313-cp313-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 ce1bd408ebaafc3dbdf39e860888382aae69de2b3c949dadfd132779130b99b2
MD5 e8f6ca56d42bfd0c209cf50748a91506
BLAKE2b-256 29b363f9b1168c4d1abbee4418a0a165496f57cd4b93a261cb481272ce353890

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.0-cp313-cp313-manylinux_2_39_aarch64.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.10.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp313-cp313-macosx_10_13_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 54a051cbc0bb25b30e65f46ddb1b63149a80bb7004c97615d39c491d492a6d9b
MD5 18dcff4f6b24eece58840f718930093d
BLAKE2b-256 f61e18612dc9e75e5c02a281a49d97b56b5504eb5907f971c68e8a5801033f36

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 ee9659bd0c7cdf0c2532977f2ec8bf1d1ab01cb3b6776e50c67046481f3162c7
MD5 8393eb640cf5531619f5d2fb18eb0e2b
BLAKE2b-256 8a5ed343c5249bd24c6614e8c1b718a73bb9f68beb2cf90464bc51c9436d25af

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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.10.0-cp312-cp312-manylinux_2_39_aarch64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp312-cp312-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 bfe1f47ae03decdc0ad111ec82606bac82ee6cdd7fea04cbcff1283608cc2d2e
MD5 ee468b4a424b8da35d78bd0387bb16d3
BLAKE2b-256 61173ec180ca7c2e79a0c3e9912ac04b446e733745cd944845fe4306be016efd

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.0-cp312-cp312-manylinux_2_39_aarch64.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.10.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for falkordblite-0.10.0-cp312-cp312-macosx_10_13_x86_64.macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 741fda166170513db1815d5369870e47d44da2e9b85320fddbc50c88a7338d51
MD5 0084a5f95692707ad7144636814ac35b
BLAKE2b-256 0e4339d8cf13964784447676d24f0cefa3bdc99c10e647c71e6a4172d302dcac

See more details on using hashes here.

Provenance

The following attestation bundles were made for falkordblite-0.10.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