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.

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'})")

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 missing features:

  • REMOVE clause
  • 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.2-cp313-cp313-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.13Windows x86-64

velr-0.2.2-cp313-cp313-manylinux_2_34_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

velr-0.2.2-cp313-cp313-manylinux_2_34_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

velr-0.2.2-cp313-cp313-macosx_11_0_universal2.whl (1.6 MB view details)

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

velr-0.2.2-cp312-cp312-win_amd64.whl (1.6 MB view details)

Uploaded CPython 3.12Windows x86-64

velr-0.2.2-cp312-cp312-manylinux_2_34_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

velr-0.2.2-cp312-cp312-manylinux_2_34_aarch64.whl (1.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

velr-0.2.2-cp312-cp312-macosx_11_0_universal2.whl (1.6 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for velr-0.2.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a2a2e991270d41ceccde3fc217c1f3ce2a8b5071570a9e0d8cca44238744a1a6
MD5 3640d26f470633791e51324ee3ec5145
BLAKE2b-256 35775099d90caf42fef1fbf43876a21d0ce83045981a5dee473cfb1d6de4778e

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 945bfc4ad33525b449712e44f644949b2eda076ce805997da95bcd1cc192f4a6
MD5 9268f79af678f714162fbebe35968d08
BLAKE2b-256 7e0f0ac1e107e7553d1f7190c4b6ae65f349d8c94805e4d113bedcfb120258a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1e52f58b1b18f9ef6b7d5417ee9d3ea2f7a6a3fb2b1623f7d6d8c4c9d11a85ea
MD5 2f1b659193b4e2f5b1219c10e89f097a
BLAKE2b-256 24989316e332c54f847113ae54a14c8c7e7d36cf725c92648f8258bafe96c629

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp313-cp313-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp313-cp313-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 605b92949ef0587f77776660fe43421b437bcee115095dbad17e199dd9922a58
MD5 183e009f49d06e5b4117356922f9dd46
BLAKE2b-256 d68872b8d03061efc587aed5d6be04511d4c48434b6505605520401d31882efa

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp312-cp312-win_amd64.whl.

File metadata

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

File hashes

Hashes for velr-0.2.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7ba91e6f6e484b1a91aee6a22bc883c15ab024771178ceabf6fcafab76c4f1a6
MD5 fcd25fcc1111a51fffa1d48c78f79fa3
BLAKE2b-256 5a31472e9faaa7e506ef122e7b0059248e07b6cc8cd15e49a8e74c37a5fc930a

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8e609608f764ec0491aa047c01ac1c03e88b6c8443e0cf46e871d79a906c3a00
MD5 c68f199f87b7b21df03278e3ae2bd062
BLAKE2b-256 5bbaefcd7482ebd70dff0202bf12bffc66be7536671349a7dff47e817f7e55c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ef192400968b2e7c7ea1c8074868abb856faf53350f74fc3ea2d8e3e6df43bef
MD5 ef075cc528e7509c2fbd9efbf82a74ed
BLAKE2b-256 02430fa86b78d482fb9d1cf176656312a6a6b40b37e0516cf518c65a0ce0bc27

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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.2-cp312-cp312-macosx_11_0_universal2.whl.

File metadata

File hashes

Hashes for velr-0.2.2-cp312-cp312-macosx_11_0_universal2.whl
Algorithm Hash digest
SHA256 25395a38de0bbb782f85dc93a0f19ae67983210158af49fe1c9514a5a30a6353
MD5 975d32af2defb11cbc53997eda015693
BLAKE2b-256 175d8a5f0362a35295faa69b9d6536d53eb7628c3bf5ca3c50fe2eaee5ccf4af

See more details on using hashes here.

Provenance

The following attestation bundles were made for velr-0.2.2-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