Demo application that uses FastAPI and Neo4j.
The demo application uses neo4j and FastAPI. Data is modelled and then ingested into Neo4j Graph database using the Neo4j Data Importer and the FastAPI endpoint are used to query the Neo4j database.
Northwind dataset is used for this demo application. Northwind dataset can be accessed via the below link:
https://gist.github.com/maruthiprithivi/072b526e20fe16a29f98db07f569861d
The dataset has the following entities – Orders, Employee, Customer, Product, Supplier and Categories. The data relationship are as follows:
- Customer – place - order
- Orders have products
- Suppliers supply products
- Products are in different categories
- Orders are shipped to an Address
- Suppliers located at a particular address
Arrow App is used to create a Graph data model. The json export of the data model can be found in directory.
Neo4j Data importer can be used to import small datasets, model and ingest data into Neo4j database.
Neo4j Data importer can be accessed via below link:
https://data-importer.graphapp.io
The data is ingested into Neo4j database by running the data importer.
Neo4j browser app can be used to run Cypher queries.
app-neo4j-fastapi/
├── .env
├── .gitignore
├── __init__.py
├── config.py
├── cypher-queries/
│ └── cypher.txt
├── files/
│ ├── processed-northwind-categories.csv
│ ├── processed-northwind-customers.csv
│ ├── processed-northwind-employees.csv
│ ├── processed-northwind-orders.csv
│ ├── processed-northwind-products.csv
│ ├── processed-northwind-suppliers.csv
│ └── processed-northwond-order-details.csv
├── images/
│ ├── api-endpoints.jpg
│ ├── data-importer-status.jpg
│ ├── data-importer.jpg
│ ├── data-model.jpg
│ └── neo_sandbox.jpg
├── LICENSE
├── main.py
├── models/
│ └── models.py
├── neo4j_importer_model.json
├── pandas.ipynb
├── README.md
└── requirements.txt
The application uses Python 3.9.13.
The setup process involves the following steps:
- Clone the repo on local
git clone
- Create and activate virtual environment - venv
# Create venv
python3 -m venv venv
# Activate venv
source venv/bin/activate
- Install requirements.txt
pip install -r requirements.txt
-
Create Blank Database in Neo4j AuraDB - https://neo4j.com/cloud/platform/aura-graph-database/?ref=nav-get-started-cta
-
Import the Data Model JSON in Data Importer UI - https://data-importer.graphapp.io
- Add files from
/files
folder - Open model
neo4j_importer_model.json
- Add files from
-
Run Data Importer to ingest data into Neo4j database
- Go back to the Neo4j AuraDB console and click Explore
- This will open
https://browser.neo4j.io
- Enter the credentials
- Select the neo4j database
- This will open
- Set Neo4j BOLT URL, username, password and database in
.env
file - Run FastAPI application
uvicorn main:app --reload
- Access Swagger UI
- Perform CRUD operations using the API endpoints
The application can be run using the Dockerfile.
To start the Docker service
- Set the credentials in
/app/.env
file - Run the docker compose
docker compose up