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.
- Google Cloud Platform account
- Google Cloud Spanner instance
- Google Cloud credentials (credentials.json)
- Clone the repository
- Place your
credentials.json
file in the project root directory - 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
- Build and start the container:
docker-compose up --build
The API will be available at http://localhost:8000
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn main:app --host 0.0.0.0 --port 8000
To connect the API with GraphXR Grove, follow these steps:
-
Access GraphXR Grove through one of these options:
- Use the shared demo link: Spanner Graph Transit Demo
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
-
If creating your own project:
- Open GraphXR
- Create a new project
- In the Grove panel:
- Import spanner-graph.grove
- Connect to http://localhost:8000 using the Grove
-
You should see a UI like this:
GET /api/v1/spanner/schema
: Retrieve database schema informationPOST /api/v1/spanner/execute
: Execute graph queriesGET /api/v1/spanner/samples
: Get predefined query samples
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 |
.
├── 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
The demo data used in this project is sourced from TransitFraudDemo, which provides sample transit data for demonstration purposes.
- 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