Tool for transferring select data from one active Neo4j instance to another.
Project description
git s# Neo4j Transfer
A Python tool for efficiently transferring selected data from one Neo4j instance to another, with support for batch processing, progress tracking, and transfer metadata.
Features
- Selective Data Transfer: Transfer specific node labels and relationship types
- Batch Processing: Efficient large-scale transfers with configurable batch sizes
- Progress Tracking: Real-time progress updates during transfers
- Transfer Metadata: Optional augmentation with source element IDs and timestamps
- Undo Capability: Remove transferred data using the original transfer specification
- Database Reset: Option to clear target database before transfer
- Stoppable Transfers: Cancel long-running transfers gracefully
Documentation
Installation
From GitHub (Development)
pip install git+https://github.com/jalakoo/neo4j-transfer.git@main
From PyPI (When Available)
pip install neo4j-transfer
Quick Start
Basic Transfer
from neo4j_transfer import Neo4jCredentials, TransferSpec, transfer
# Define source and target database credentials
source_creds = Neo4jCredentials(
uri="bolt://localhost:7687",
username="neo4j",
password="source_password",
database="neo4j"
)
target_creds = Neo4jCredentials(
uri="bolt://localhost:7688",
username="neo4j",
password="target_password",
database="neo4j"
)
# Specify what to transfer
spec = TransferSpec(
node_labels=["Person", "Company"],
relationship_types=["WORKS_FOR", "OWNS"]
)
# Execute the transfer
result = transfer(source_creds, target_creds, spec)
print(f"Transfer completed: {result.nodes_created} nodes, {result.relationships_created} relationships")
Transfer with Progress Tracking
from neo4j_transfer import transfer_generator
# Use the generator for real-time progress updates
for update in transfer_generator(source_creds, target_creds, spec):
if hasattr(update, 'records_completed'):
progress = update.float_completed()
print(f"Progress: {progress:.1%}")
Transfer with Metadata Augmentation
spec = TransferSpec(
node_labels=["Person"],
relationship_types=["KNOWS"],
should_append_data=True, # Add transfer metadata
element_id_key="_source_element_id",
timestamp_key="_transfer_timestamp"
)
Undo a Transfer
from neo4j_transfer import undo
# Remove all data transferred with this spec
undo(target_creds, spec)
Advanced Usage
Database Reset Before Transfer
spec = TransferSpec(
node_labels=["Person"],
overwrite_target=True, # Clear target database first
batch_size=10000
)
Stoppable Transfer
gen = transfer_generator(source_creds, target_creds, spec)
controller = next(gen) # Get the controller
# In another thread or after some condition:
controller.request_stop()
# Continue consuming updates
for update in gen:
# Process updates until stop is requested
pass
API Reference
Neo4jCredentials
Credentials for accessing a Neo4j database instance.
uri(str): The URI address of the Neo4j databasepassword(str): The password for authenticationusername(str, optional): Username (default: "neo4j")database(str, optional): Database name (default: "neo4j")
TransferSpec
Configuration for data transfer between Neo4j instances.
node_labels(list[str]): Node labels to transferrelationship_types(list[str], optional): Relationship types to transfershould_append_data(bool): Add transfer metadata to copied data (default: True)element_id_key(str): Property key for source element ID (default: "_transfer_element_id")timestamp_key(str): Property key for transfer timestamp (default: "_transfer_timestamp")overwrite_target(bool): Clear target database before transfer (default: False)batch_size(int): Batch size for transfers (default: 10000)
UploadResult
Result object containing transfer statistics.
nodes_created(int): Number of nodes createdrelationships_created(int): Number of relationships createdrecords_total(int): Total records processedrecords_completed(int): Records completedwas_successful(bool): Whether transfer succeededseconds_to_complete(float): Transfer durationfloat_completed(): Returns completion percentage as float (0.0-1.0)
Requirements
- Python 3.11+
- Neo4j 4.0+
- Access to both source and target Neo4j instances
License
MIT License - see LICENSE.txt for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neo4j_transfer-0.2.0.tar.gz.
File metadata
- Download URL: neo4j_transfer-0.2.0.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.0 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47c152e0860224a9ca7c05573145598a79e7ada5db126a6890adc79e2c7cec33
|
|
| MD5 |
823544bba69d9c0af903580cca046a4a
|
|
| BLAKE2b-256 |
25eda395fd9e0fc5d83289808dc73ca1ed0fca27ccd0f59afb2362b9898792b4
|
File details
Details for the file neo4j_transfer-0.2.0-py3-none-any.whl.
File metadata
- Download URL: neo4j_transfer-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.12.0 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efb6ddf7368c172f97b4ef96ef8b4c531258553df93bee54c0acf8596075bad0
|
|
| MD5 |
70cfe5e9fa442392c50676639a8ad289
|
|
| BLAKE2b-256 |
d583d4cfe377f3803da12c90fcd2804da0ed410d2b557012b57570c0f765bdb3
|