Skip to main content

Python bindings for Velr, an embedded openCypher graph database built on SQLite

Project description

Velr

Velr is an embedded property-graph database from Velr.ai, written in Rust, built on top of SQLite (persisting to a standard SQLite database file) and queried using the openCypher language.

It runs in-process and is designed for local, embedded, and edge use cases.

This package provides the Python bindings for Velr. It wraps a bundled native runtime with a C ABI, implemented in Rust, and exposes a small, Pythonic API for executing Cypher queries, streaming result tables, working with transactions, and exporting results to Arrow, pandas, and Polars.

For the main Velr public entry point, see velr-ai/velr.
For the Velr website, see velr.ai.

Community

We’d love to have you join the Velr community.


Release status

Velr is currently in public alpha.

  • The Python API and query support are still evolving.
  • openCypher coverage is already substantial, but some features are still missing.
  • During the 0.2.x series, we do not guarantee database migration or on-disk database compatibility between releases.
  • Starting with the 0.3.x series, we intend to guarantee internal database compatibility within the branch.

Velr is already usable for real workflows and representative use cases, but rough edges remain and the API is not yet stable.

Velr 1.0 is focused on strong openCypher compatibility.
Vector search, time-series, and federation are planned as post-1.0 capabilities.


Installation

Install from PyPI:

pip install velr

For Arrow / dataframe workflows, install the optional Python dependencies you want to use:

pip install pyarrow pandas polars

Licensing in simple terms

  • The Python binding source code in this package is licensed under MIT.
  • The bundled native runtime binaries may be used and freely redistributed in unmodified form under the terms of LICENSE.runtime.

Quick start

from velr.driver import Velr

MOVIES_CREATE = r"""
CREATE
  (keanu:Person:Actor {name:'Keanu Reeves', born:1964}),
  (nolan:Person:Director {name:'Christopher Nolan'}),
  (matrix:Movie {title:'The Matrix', released:1999, genres:['Sci-Fi','Action']}),
  (inception:Movie {title:'Inception', released:2010, genres:['Sci-Fi','Heist']}),
  (keanu)-[:ACTED_IN {roles:['Neo']}]->(matrix),
  (nolan)-[:DIRECTED]->(inception);
"""

with Velr.open(None) as db:
    db.run(MOVIES_CREATE)

    with db.exec_one(
        "MATCH (m:Movie {title:'Inception'}) "
        "RETURN m.title AS title, m.released AS year, m.genres AS genres"
    ) as table:
        print(table.column_names())

        with table.rows() as rows:
            row = next(rows)

    title, year, genres = row
    print(title.as_python())
    print(year.as_python())
    print(genres.as_python())

Open a file-backed database instead of an in-memory database:

from velr.driver import Velr

with Velr.open("mygraph.db") as db:
    db.run("CREATE (:Person {name:'Alice'})")

Open an existing database for reads only:

from velr.driver import Velr

with Velr.open_readonly("mygraph.db") as db:
    with db.exec_one("MATCH (n) RETURN count(n) AS count") as table:
        print(table.collect(lambda row: [cell.as_python() for cell in row]))

open_readonly() never creates, initializes, migrates, or repairs a database. The file must already exist and have the current Velr schema version. Use Velr.open() from import and maintenance code when initialization or migration is intended.


Query model

A query may produce zero or more result tables.

Velr exposes three main ways to run Cypher:

  • run() executes a query or script and drains all result tables.
  • exec() returns a stream of result tables.
  • exec_one() expects exactly one result table.

run()

Use run() when you only care about side effects:

with Velr.open(None) as db:
    db.run("CREATE (:Movie {title:'Interstellar', released:2014})")

exec_one()

Use exec_one() when the query should yield exactly one table:

with Velr.open(None) as db:
    db.run("CREATE (:Person {name:'Alice', age:30})")

    with db.exec_one("MATCH (p:Person) RETURN p.name AS name, p.age AS age") as table:
        print(table.column_names())
        print(table.collect(lambda row: [cell.as_python() for cell in row]))

exec()

Use exec() when a query or script may produce multiple result tables:

with Velr.open(None) as db:
    db.run(MOVIES_CREATE)

    with db.exec(
        "MATCH (m:Movie {title:'The Matrix'}) RETURN m.title AS title; "
        "MATCH (m:Movie {title:'Inception'}) RETURN m.released AS released"
    ) as stream:
        for table in stream.iter_tables():
            print(table.column_names())
            print(table.collect(lambda row: [cell.as_python() for cell in row]))

Table lifetime and ownership

Table lifetime depends on how a table was obtained.

Tables from exec()

Tables pulled from exec() are stream-scoped.

They remain valid while the producing stream remains open, and closing the stream closes any still-open tables produced by that stream.

with db.exec("MATCH (n) RETURN n") as stream:
    table = stream.next_table()
    # table is valid here

# stream is now closed, so any still-open table from it is also closed

Tables from exec_one()

Tables returned by exec_one() are parent-scoped, not stream-scoped.

  • Velr.exec_one() returns a table parented to the connection.
  • VelrTx.exec_one() returns a table parented to the transaction.

That means the returned table remains usable after the internal stream logic used by exec_one() has finished.

Even so, tables should still be closed when no longer needed, ideally by using them as context managers.


Rows and cells

Rows are exposed through Rows. Each yielded row is a tuple of Cell objects.

Cell.as_python() converts values to normal Python objects:

  • NULLNone
  • BOOLbool
  • INT64int
  • DOUBLEfloat
  • TEXTstr by default
  • JSONstr by default, or parsed Python objects with parse_json=True

Example:

with db.exec_one("MATCH (p:Person) RETURN p.name AS name, p.age AS age") as table:
    with table.rows() as rows:
        for row in rows:
            print(row[0].as_python(), row[1].as_python())

For convenience and safety, TEXT and JSON payloads are copied into Python bytes as rows are read, so row contents remain valid after the next fetch.


Transactions and savepoints

Use begin_tx() to open a transaction:

from velr.driver import Velr

with Velr.open(None) as db:
    with db.begin_tx() as tx:
        tx.run("CREATE (:Movie {title:'Interstellar', released:2014})")
        tx.commit()

If a transaction context exits without commit(), it is rolled back.

After commit() or rollback(), a transaction can no longer be used.

Savepoints

Velr supports two savepoint styles:

  • savepoint() creates a scoped, handle-owned savepoint.
  • savepoint_named(name) creates a transaction-owned named savepoint.

Scoped savepoints are owned by the Python handle:

  • dropping the handle closes the savepoint
  • release() releases it
  • rollback() rolls back to it and releases it

Named savepoints are owned by the transaction:

  • dropping the returned Python handle does not remove the named savepoint
  • rollback_to(name) rolls back to that named savepoint, discards any newer named savepoints, and keeps the target named savepoint active
  • release_savepoint(name) releases a named savepoint by name; the named savepoint must be the most recent active named savepoint
  • release() or rollback() on a named savepoint handle consume that named savepoint

Active named savepoints are released automatically during commit() so that surviving changes are preserved in the committed transaction.

Example:

with Velr.open(None) as db:
    with db.begin_tx() as tx:
        tx.run("CREATE (:Temp {k:'outer'})")

        tx.savepoint_named("sp1")
        tx.run("CREATE (:Temp {k:'a'})")

        tx.savepoint_named("sp2")
        tx.run("CREATE (:Temp {k:'b'})")

        tx.rollback_to("sp1")  # undoes a and b, drops sp2, keeps sp1 active
        tx.run("CREATE (:Temp {k:'c'})")

        tx.release_savepoint("sp1")
        tx.commit()

pandas / Polars / PyArrow interop

Velr can export result tables as Arrow IPC and convert them into:

  • pyarrow.Table
  • pandas.DataFrame
  • polars.DataFrame

pandas

with Velr.open(None) as db:
    db.run(MOVIES_CREATE)

    df = db.to_pandas(
        "MATCH (m:Movie) "
        "RETURN m.title AS title, m.released AS released "
        "ORDER BY released"
    )
    print(df)

Polars

with Velr.open(None) as db:
    db.run(MOVIES_CREATE)

    df = db.to_polars(
        "MATCH (m:Movie) "
        "RETURN m.title AS title, m.released AS released "
        "ORDER BY released"
    )
    print(df)

PyArrow

with Velr.open(None) as db:
    db.run(MOVIES_CREATE)

    tbl = db.to_pyarrow(
        "MATCH (m:Movie) "
        "RETURN m.title AS title, m.released AS released "
        "ORDER BY released"
    )
    print(tbl)

Export from an existing table

with db.exec_one("MATCH (m:Movie) RETURN m.title AS title") as table:
    pa_tbl = table.to_pyarrow()
    df = table.to_pandas()
    pl_df = table.to_polars()

Binding Arrow, pandas, Polars, NumPy, and records

Velr can also bind external columnar data under a logical name and query it from Cypher.

Supported bind helpers include:

  • bind_arrow()
  • bind_pandas()
  • bind_polars()
  • bind_numpy()
  • bind_records()

Bind a pandas DataFrame

import pandas as pd
from velr.driver import Velr

df = pd.DataFrame(
    [
        {"name": "Alice", "age": 30},
        {"name": "Bob", "age": 41},
    ]
)

with Velr.open(None) as db:
    db.bind_pandas("_people", df)

    db.run("""
    UNWIND BIND('_people') AS r
    CREATE (:Person {name:r.name, age:r.age})
    """)

    out = db.to_pandas("MATCH (p:Person) RETURN p.name AS name, p.age AS age ORDER BY age")
    print(out)

Bind a list of dicts

rows = [
    {"name": "Alice", "age": 30},
    {"name": "Bob", "age": 41},
]

with Velr.open(None) as db:
    db.bind_records("_people", rows)
    db.run("""
    UNWIND BIND('_people') AS r
    CREATE (:Person {name:r.name, age:r.age})
    """)

Explain support

Velr exposes explain traces through:

  • Velr.explain()
  • Velr.explain_analyze()
  • VelrTx.explain()
  • VelrTx.explain_analyze()

These return an ExplainTrace, which can be navigated incrementally or fully materialized with snapshot().

with Velr.open(None) as db:
    with db.explain("MATCH (p:Person) RETURN p.name AS name") as xp:
        print(xp.to_compact_string())

Query language support

Velr supports most of openCypher, but some features are not yet implemented.

Notable current limitations:

  • Driver-level query parameters (for example $name)
  • The query planner does not yet use indexes in all cases where expected.

Supported functions

Velr currently supports these openCypher functions:

Scalars

  • id()
  • type()
  • length()
  • nodes()
  • relationships()
  • coalesce()
  • labels()
  • properties()
  • keys()

Aggregates

  • count()
  • sum()
  • avg()
  • min()
  • max()
  • collect()

Thread safety

Velr connections and active result handles are not safe for concurrent use from multiple threads.

If you need parallelism:

  • open one connection per thread
  • do not share active connections
  • do not share transactions, streams, tables, row iterators, or explain traces across threads

Platform support

The Python package wraps a bundled native runtime implemented in Rust.

Supported distributions may include prebuilt binary wheels for common platforms. Where binary wheels are available, the compiled runtime is included with the package.

Currently bundled targets:

* macOS (arm64)
* Linux x86_64
* Linux aarch64
* Windows x86_64

License

See LICENSE and LICENSE.runtime for the full license texts.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

velr-0.2.13-cp314-cp314-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.14Windows x86-64

velr-0.2.13-cp314-cp314-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ x86-64

velr-0.2.13-cp314-cp314-manylinux_2_34_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.34+ ARM64

velr-0.2.13-cp314-cp314-macosx_11_0_universal2.whl (2.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ universal2 (ARM64, x86-64)

velr-0.2.13-cp313-cp313-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.13Windows x86-64

velr-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

velr-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

velr-0.2.13-cp313-cp313-macosx_11_0_universal2.whl (2.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ universal2 (ARM64, x86-64)

velr-0.2.13-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12Windows x86-64

velr-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

velr-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

velr-0.2.13-cp312-cp312-macosx_11_0_universal2.whl (2.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ universal2 (ARM64, x86-64)

File details

Details for the file velr-0.2.13-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: velr-0.2.13-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for velr-0.2.13-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 b2515dcdd27652fd674671608068900c32e23c00789b9b19713a5574307a2d14
MD5 1491e0069e195fd19e280f35ef598b69
BLAKE2b-256 06bf04e96a007e2709810bbb993d68c23236c8447acc2d6a6644c9dd95db5190

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp314-cp314-win_amd64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp314-cp314-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp314-cp314-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 429ad2225ccd1a394bc2a790c36a4712acdf38179e383559375906f3cfb91590
MD5 6141d630a8683c387acf59e4d441c74d
BLAKE2b-256 67e674f753f30bdd224865e26e44b6d8ef46de79fad392f66180f6fc9cbbe483

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp314-cp314-manylinux_2_34_x86_64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp314-cp314-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp314-cp314-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 73f891d6a3c8b19151bb876fc1169f18c8e88e3e2a1e4120bdb069d998be802e
MD5 18bea0c85eee1e541acea069eea06791
BLAKE2b-256 0324d9c004a86061b1ec46f52dec2f0f1f764bfb412c9e602b8e7de0f7399228

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp314-cp314-manylinux_2_34_aarch64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp314-cp314-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp314-cp314-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 69ec1651472ce602feab1c609e25065cfffc27ce0211893167687cd362df4b55
MD5 13cca5ba63630ab64f3a43b800012ff5
BLAKE2b-256 aa87e073d579c03d5dea0683ad267b9e45b064bff188d5693104a98eeb37b8e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp314-cp314-macosx_11_0_universal2.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: velr-0.2.13-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for velr-0.2.13-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2ad065d141e976fb2c797f1c8c6a01e3e46b46ca97687eae5be470b9b3110491
MD5 399e9d72d498bd9e44e3dd1e470e83b5
BLAKE2b-256 aa98c8c2db3e7cc2bc9b25ac7e9c22dec07f7a0d86fc6e4cab14a643d7a4beb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp313-cp313-win_amd64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f094dec7c5993a3f9866d5ccfe0f7f5dbf1f7ef14c983e8ff234ad2fa632b4ad
MD5 323723796b65a9ef94f98aad21bcc922
BLAKE2b-256 44487de889da835d806072c3067e994e3b7819934885fd7947709e5ee027beda

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 672f3dcedaf5759e13121cc0ca43d817ad6f53cb9918d4ff9d3341cc282d01fa
MD5 8f15dbb21518daa4a8c93b86d052b121
BLAKE2b-256 3ef5be0ee0b7d91f8d211663a4998eb513fd1b6663a585700f587ef6c0857475

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp313-cp313-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 75ec6699bdbb3d432fc4787c1bdebda9e33156632583df0bd023f3396e0ab9d2
MD5 4b78f4ac86a8012e17cf43795ae1fc14
BLAKE2b-256 5ba6f08932ed6ecffc930e185fb533e110f30d6fba73eb17ce0ca1eedc044156

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp313-cp313-macosx_11_0_universal2.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: velr-0.2.13-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.2 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for velr-0.2.13-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 cc935cdef5464ca1a73d8404568c8f84d4c535639d4035d93bbc980011538564
MD5 276c04100d58528e0c0a4167fe6e9369
BLAKE2b-256 124ea6ed48f71680629de796cbdc4b65ecf796eb37bac01fb3ab6710a878fb06

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp312-cp312-win_amd64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 1f3f67e9a63e768c36ff7ba55087d7af24c931d3c474fc1c46309f7d852e8c1a
MD5 2b94f43dc25e3d9894a1db9d7157a11b
BLAKE2b-256 21e91857e676c35ea2cfd144736e6befe9bf84bdd100e80cbb3da388732dbf3d

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3057e0d5c2130779fd4d8b9e98d1f7523082e3176f94ce51146d907978858aee
MD5 f1750ae2f4ab9e322fea27d19dde4b6d
BLAKE2b-256 c4562a779ae0ea08494560aef04822cd77a99f9c424566ce19f823cfd249e600

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp312-cp312-manylinux_2_34_aarch64.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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

File details

Details for the file velr-0.2.13-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for velr-0.2.13-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 b4b352691396bab99f7bcf2dc3db366b3e4279fdd27071d239cbeaaf7d81920e
MD5 ef8514ae6f378576ea14cc45971780b7
BLAKE2b-256 d134e6a6ace26981d5369f0df785a2de9a079ec2be856bb687d6ef23838a1bec

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.13-cp312-cp312-macosx_11_0_universal2.whl:

Publisher: publish-pypi.yml on velr-ai/velr-repo

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