Skip to main content

A framework for transforming tabular (CSV, SQL) and hierarchical data (JSON, XML) into property graphs and ingesting them into graph databases (ArangoDB, Neo4j, TigerGraph). Features automatic PostgreSQL schema inference.

Project description

GraFlo graflo logo

A framework for transforming tabular (CSV, SQL) and hierarchical data (JSON, XML) into property graphs and ingesting them into graph databases (ArangoDB, Neo4j, TigerGraph, FalkorDB, Memgraph).

⚠️ Package Renamed: This package was formerly known as graphcast.

Python PyPI version PyPI Downloads License: BSL pre-commit DOI

Core Concepts

Property Graphs

graflo works with property graphs, which consist of:

  • Vertices: Nodes with properties and optional unique identifiers
  • Edges: Relationships between vertices with their own properties
  • Properties: Both vertices and edges may have properties

Schema

The Schema defines how your data should be transformed into a graph and contains:

  • Vertex Definitions: Specify vertex types, their properties, and unique identifiers
    • Fields can be specified as strings (backward compatible) or typed Field objects with types (INT, FLOAT, STRING, DATETIME, BOOL)
    • Type information enables better validation and database-specific optimizations
  • Edge Definitions: Define relationships between vertices and their properties
    • Weight fields support typed definitions for better type safety
  • Resource Mapping: describe how data sources map to vertices and edges
  • Transforms: Modify data during the casting process
  • Automatic Schema Inference: Generate schemas automatically from PostgreSQL 3NF databases

Resources

Resources are your data sources that can be:

  • Table-like: CSV files, database tables
  • JSON-like: JSON files, nested data structures

Features

  • Graph Transformation Meta-language: A powerful declarative language to describe how your data becomes a property graph:
    • Define vertex and edge structures with typed fields
    • Set compound indexes for vertices and edges
    • Use blank vertices for complex relationships
    • Specify edge constraints and properties with typed weight fields
    • Apply advanced filtering and transformations
  • Typed Schema Definitions: Enhanced type support throughout the schema system
    • Vertex fields support types (INT, FLOAT, STRING, DATETIME, BOOL) for better validation
    • Edge weight fields can specify types for improved type safety
    • Backward compatible: fields without types default to None (suitable for databases like ArangoDB)
  • 🚀 PostgreSQL Schema Inference: Automatically generate schemas from PostgreSQL 3NF databases - No manual schema definition needed!
    • Introspect PostgreSQL schemas to identify vertex-like and edge-like tables
    • Automatically map PostgreSQL data types to graflo Field types (INT, FLOAT, STRING, DATETIME, BOOL)
    • Infer vertex configurations from table structures with proper indexes
    • Infer edge configurations from foreign key relationships
    • Create Resource mappings from PostgreSQL tables automatically
    • Direct database access - ingest data without exporting to files first
  • Async ingestion: Efficient async/await-based ingestion pipeline for better performance
  • Parallel processing: Use as many cores as you have
  • Database support: Ingest into ArangoDB, Neo4j, TigerGraph, FalkorDB, and Memgraph using the same API (database agnostic). Source data from PostgreSQL and other SQL databases.
  • Server-side filtering: Efficient querying with server-side filtering support (TigerGraph REST++ API)

Documentation

Full documentation is available at: growgraph.github.io/graflo

Installation

pip install graflo

Usage Examples

Simple ingest

from suthing import FileHandle

from graflo import Schema, Caster, Patterns
from graflo.db.connection.onto import ArangoConfig

schema = Schema.from_dict(FileHandle.load("schema.yaml"))

# Option 1: Load config from docker/arango/.env (recommended)
conn_conf = ArangoConfig.from_docker_env()

# Option 2: Load from environment variables
# Set: ARANGO_URI, ARANGO_USERNAME, ARANGO_PASSWORD, ARANGO_DATABASE
conn_conf = ArangoConfig.from_env()

# Option 3: Load with custom prefix (for multiple configs)
# Set: USER_ARANGO_URI, USER_ARANGO_USERNAME, USER_ARANGO_PASSWORD, USER_ARANGO_DATABASE
user_conn_conf = ArangoConfig.from_env(prefix="USER")

# Option 4: Create config directly
# conn_conf = ArangoConfig(
#     uri="http://localhost:8535",
#     username="root",
#     password="123",
#     database="mygraph",  # For ArangoDB, 'database' maps to schema/graph
# )
# Note: If 'database' (or 'schema_name' for TigerGraph) is not set,
# Caster will automatically use Schema.general.name as fallback

from graflo.util.onto import FilePattern
import pathlib

# Create Patterns with file patterns
patterns = Patterns()
patterns.add_file_pattern(
    "work",
    FilePattern(regex="\Sjson$", sub_path=pathlib.Path("./data"), resource_name="work")
)

# Or use resource_mapping for simpler initialization
# patterns = Patterns(
#     _resource_mapping={
#         "work": "./data/work.json",
#     }
# )

schema.fetch_resource()

from graflo.hq.caster import IngestionParams
from graflo.hq import GraphEngine

# Option 1: Use GraphEngine for schema definition and ingestion (recommended)
engine = GraphEngine()
ingestion_params = IngestionParams(
    clean_start=False,  # Set to True to wipe existing database
    # max_items=1000,  # Optional: limit number of items to process
    # batch_size=10000,  # Optional: customize batch size
)

engine.define_and_ingest(
    schema=schema,
    output_config=conn_conf,  # Target database config
    patterns=patterns,  # Source data patterns
    ingestion_params=ingestion_params,
    clean_start=False,  # Set to True to wipe existing database
)

# Option 2: Use Caster directly (schema must be defined separately)
# from graflo.hq import GraphEngine
# engine = GraphEngine()
# engine.define_schema(schema=schema, output_config=conn_conf, clean_start=False)
# 
# caster = Caster(schema)
# caster.ingest(
#     output_config=conn_conf,
#     patterns=patterns,
#     ingestion_params=ingestion_params,
# )

PostgreSQL Schema Inference

from graflo.hq import GraphEngine
from graflo.db.connection.onto import PostgresConfig, ArangoConfig
from graflo import Caster
from graflo.onto import DBType

# Connect to PostgreSQL
postgres_config = PostgresConfig.from_docker_env()  # or PostgresConfig.from_env()

# Create GraphEngine and infer schema from PostgreSQL 3NF database
# Connection is automatically managed inside infer_schema()
engine = GraphEngine(target_db_flavor=DBType.ARANGO)
schema = engine.infer_schema(
    postgres_config,
    schema_name="public",  # PostgreSQL schema name
)

# Define schema in target database (optional, can also use define_and_ingest)
target_config = ArangoConfig.from_docker_env()
engine.define_schema(
    schema=schema,
    output_config=target_config,
    clean_start=False,
)

# Use the inferred schema with Caster for ingestion
caster = Caster(schema)
# ... continue with ingestion

Development

To install requirements

git clone git@github.com:growgraph/graflo.git && cd graflo
uv sync --dev

Tests

Test databases

Quick Start: To start all test databases at once, use the convenience scripts from the docker folder:

cd docker
./start-all.sh    # Start all services
./stop-all.sh      # Stop all services
./cleanup-all.sh   # Remove containers and volumes

Individual Services: To start individual databases, navigate to each database folder and run:

Spin up Arango from arango docker folder by

docker-compose --env-file .env up arango

Neo4j from neo4j docker folder by

docker-compose --env-file .env up neo4j

TigerGraph from tigergraph docker folder by

docker-compose --env-file .env up tigergraph

FalkorDB from falkordb docker folder by

docker-compose --env-file .env up falkordb

and Memgraph from memgraph docker folder by

docker-compose --env-file .env up memgraph

To run unit tests

pytest test

Note: Tests require external database containers (ArangoDB, Neo4j, TigerGraph, FalkorDB, Memgraph) to be running. CI builds intentionally skip test execution. Tests must be run locally with the required database images started (see Test databases section above).

Requirements

  • Python 3.11+ (Python 3.11 and 3.12 are officially supported)
  • python-arango
  • sqlalchemy>=2.0.0 (for PostgreSQL and SQL data sources)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

graflo-1.4.4.tar.gz (198.7 kB view details)

Uploaded Source

Built Distribution

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

graflo-1.4.4-py3-none-any.whl (236.7 kB view details)

Uploaded Python 3

File details

Details for the file graflo-1.4.4.tar.gz.

File metadata

  • Download URL: graflo-1.4.4.tar.gz
  • Upload date:
  • Size: 198.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for graflo-1.4.4.tar.gz
Algorithm Hash digest
SHA256 3aa2a7fbc86f2efb3e7bdf2a3f7ca2526c392cdb343a1404f4d2e4a0d9dd7fbf
MD5 21c83f3228108225e71124461da77dd1
BLAKE2b-256 5a74372559ab627bb5f61feb2f2ebd4c3baa42ef7c083b0b75a87b4a973c56cd

See more details on using hashes here.

File details

Details for the file graflo-1.4.4-py3-none-any.whl.

File metadata

  • Download URL: graflo-1.4.4-py3-none-any.whl
  • Upload date:
  • Size: 236.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for graflo-1.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9edf8f4e35b6ffa7a8bc6122d678be7e0ca47cc5f72d841302d4f8890f374b53
MD5 f13af55a909187edb517e1c7347ebbf1
BLAKE2b-256 f96184914cf060430b1c064cc9f419805d8f2a731ec09cf000f7d25d906fd83b

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