Skip to content

Kineviz/spannergraph-graphxr-api

Repository files navigation

GraphXR Spanner Graph Connector

A FastAPI-based service that enables GraphXR to connect and visualize graph data stored in Google Cloud Spanner Graph. This API service acts as a bridge between GraphXR and Spanner Graph, allowing interactive graph data exploration and visualization.

Prerequisites

  • Google Cloud Platform account
  • Google Cloud Spanner instance
  • Google Cloud credentials (credentials.json)

Project Setup

  1. Clone the repository
  2. Place your credentials.json file in the project root directory
  3. Create a .env file with the following variables or set them in the docker-compose.yml file:
ENVIRONMENT=development
SPANNER_INSTANCE=transit
SPANNER_DATABASE=transitdb
GOOGLE_CLOUD_PROJECT=code4demo
GRAPH_NAME=TransitGraph

Running the Application

Using Docker Compose (Recommended)

  1. Build and start the container:
docker-compose up --build

The API will be available at http://localhost:8000

Manual Setup

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000 

Connect Spanner Graph with GraphXR Grove

To connect the API with GraphXR Grove, follow these steps:

  1. Access GraphXR Grove through one of these options:

    Notice: The demo link uses a trial database which may not always be accessible. If you encounter connection issues, please set up your own project following the instructions below.

    • Create your own project in GraphXR Grove
  2. If creating your own project:

  3. You should see a UI like this:

Spanner Graph Grove UI

Spanner Graph Demo

API Endpoints

  • GET /api/v1/spanner/schema: Retrieve database schema information
  • POST /api/v1/spanner/execute: Execute graph queries
  • GET /api/v1/spanner/samples: Get predefined query samples

Environment Variables

Variable Description Default
ENVIRONMENT Application environment development
SPANNER_INSTANCE Google Cloud Spanner instance name transit
SPANNER_DATABASE Spanner database name transitdb
GOOGLE_CLOUD_PROJECT Google Cloud project ID -
GRAPH_NAME Name of the graph in Spanner TransitGraph

Project Structure

.
├── main.py              # FastAPI application entry point
├── routes/              # API route handlers
├── models/              # Pydantic models
├── docker-compose.yml   # Docker compose configuration
├── Dockerfile          # Docker build instructions
├── requirements.txt    # Python dependencies
└── samples.yaml        # Sample queries configuration

Data Source

The demo data used in this project is sourced from TransitFraudDemo, which provides sample transit data for demonstration purposes.

Security Notes

  • The application currently allows all CORS origins (*)
  • Ensure your credentials.json is properly secured and not committed to version control
  • Review the .gitignore file to ensure sensitive files are not tracked

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published