Skip to main content

Lightweight helpers for running local Neo4j instances and scripting bulk Cypher workloads.

Project description

neo4j-helpers

Utilities for scripting Neo4j workflows from Python. The package bundles a handful of small helpers you can mix and match:

  • Neo4jDatabaseHelper – thin wrapper around the official driver for common admin tasks
  • CypherDispatcher – thread-based worker pool for running a Cypher statement concurrently
  • Neo4jLocalTools – utilities for working with a locally installed Neo4j distribution
  • BvecReader / IvecReader – streaming readers for ANN vector datasets (Faiss .bvecs/.ivecs)

The project currently targets Python 3.10+ and the Neo4j Python driver >= 5.0.

Installation

pip install neo4j-helpers

Or, for local development inside this repository:

python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -e '.[dev]'

Quickstart

from neo4j_helpers import (
    CypherDispatcher,
    Neo4jDatabaseHelper,
    Neo4jInfo,
    Neo4jLocalTools,
)

neo_info = Neo4jInfo.GetDefaultLocalHost()
helper = Neo4jDatabaseHelper(neo_info)

if not helper.is_db_exists():
    helper.create_db()

with CypherDispatcher(neo_info, "CREATE (:Person {name: $name})") as dispatcher:
    for name in ["Ada", "Grace", "Linus"]:
        dispatcher.submit({"name": name})

local = Neo4jLocalTools("~/neo4j/instances/local")
local.start_server(wait=True)
# ...
local.stop_server(wait=True)

Vector dataset helpers stream binary records without loading entire files:

from neo4j_helpers import BvecReader

reader = BvecReader("~/bigann/bigann_base.bvecs.gz")
for vector in reader.iter_vectors(limit=2):
    print(len(vector), vector[:8])

Development Workflow

  • Run the test suite with python3 -m pytest
  • Linting relies on the standard library venv + pip install -e '.[dev]'
  • Temporary environment variables used in examples:
    export VECTOR_FILTER_BVECS_PATH='~/bigann/bigann_base.bvecs.gz'
    export VECTOR_FILTER_IMPORT_DIR='~/neo4j/import/sample-dbs/vector-filter-v2'
    export NEO4J_HOME='~/neo4j/instances/local/'
    

Releasing

  1. Update pyproject.toml and src/neo4j_helpers/__init__.py with the next version.
  2. Build the distribution artifacts:
    python -m build
    
  3. Inspect the generated dist/ archives (optional but recommended).
  4. Upload to PyPI (or TestPyPI first):
    twine upload dist/*
    

If you are publishing to TestPyPI, pass --repository testpypi to twine upload.

Internal Reference Notes

These notes remain from the original utilities project – feel free to move them elsewhere if they no longer belong in the public README.

  • Authenticate with Google Cloud:
    gcloud auth application-default login --no-launch-browser
    gcloud compute config-ssh
    
  • JVM tuning for vector imports (requires a JDK providing incubator vectors):
    export JVM_OPTS="--add-modules jdk.incubator.vector"
    
  • Sample inline Neo4j admin import command:
    /opt/neo4j/bin/neo4j-admin database import full \
        --schema=/mnt/neo4j-import/sample-dbs/vector-filter-v2/vector-filter-schema.cypher \
        --nodes=CHUNK=/mnt/neo4j-import/sample-dbs/vector-filter-v2/chunks.csv \
        --nodes=DOCUMENT=/mnt/neo4j-import/sample-dbs/vector-filter-v2/documents.csv \
        --nodes=PROJECT=/mnt/neo4j-import/sample-dbs/vector-filter-v2/projects.csv \
        --nodes=AUTHOR=/mnt/neo4j-import/sample-dbs/vector-filter-v2/authors.csv \
        --relationships=PART_OF=/mnt/neo4j-import/sample-dbs/vector-filter-v2/chunk-doc.csv \
        --relationships=WRITTEN_FOR=/mnt/neo4j-import/sample-dbs/vector-filter-v2/doc-proj.csv \
        --relationships=WRITTEN_BY=/mnt/neo4j-import/sample-dbs/vector-filter-v2/doc-author.csv \
        --overwrite-destination=true \
        --report-file=/mnt/neo4j-import/sample-dbs/vector-filter-v2/report.txt \
        --verbose \
        vector.filter.v2
    

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

neo4j_helpers-0.1.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

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

neo4j_helpers-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file neo4j_helpers-0.1.0.tar.gz.

File metadata

  • Download URL: neo4j_helpers-0.1.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for neo4j_helpers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b069057b06bbbfc870b4980509c9082317d45f77377e5aca71176490ba4933e1
MD5 a9d70b096609ec9a56eed844217f17de
BLAKE2b-256 b7f7d3baafdf1ab02af9e9b4e01ded3881a981d332e10679a082d5856a36d16d

See more details on using hashes here.

File details

Details for the file neo4j_helpers-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: neo4j_helpers-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for neo4j_helpers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea6ba94e6cb6c964143b3886d09d5bcfec79a8e0d19885afa5bc8d294cfcf679
MD5 3270596721705a5ab4db587ca60fa835
BLAKE2b-256 fb3a712b784c08c814bb6f4892feb355434be64114c04c02153d9deabffa3832

See more details on using hashes here.

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