https://github.com/sjrusso8/fastapi-lakehouse
Connect FastAPI to a Databricks Lakehouse
https://github.com/sjrusso8/fastapi-lakehouse
databricks fastapi fastapi-template lakehouse
Last synced: 2 months ago
JSON representation
Connect FastAPI to a Databricks Lakehouse
- Host: GitHub
- URL: https://github.com/sjrusso8/fastapi-lakehouse
- Owner: sjrusso8
- Created: 2022-07-14T13:48:06.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-14T18:16:54.000Z (about 3 years ago)
- Last Synced: 2025-03-27T05:11:34.967Z (7 months ago)
- Topics: databricks, fastapi, fastapi-template, lakehouse
- Language: Python
- Homepage:
- Size: 34.2 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI and Databricks Lakehouse CRUD Example
A FastAPI example using a Databricks backend. The goal is to demonstrate that FastAPI can be connected with the Databricks Lakehouse architecture and perform CRUD activities.
## Setup
This example uses Poetry. Install [Poetry](https://python-poetry.org/) and run `poetry install` to install the dependenices.
### Prerequisites
1. Have access to a Databricks Workspace
2. An existing cluster or SQL warehouse
3. Can create a Databricks PAT token### Configuration
Follow the [Databricks Guide](https://docs.databricks.com/dev-tools/python-sql-connector.html#get-started) to collect the below cluster details:
- **Server Hostname**
- **HTTP Path**
- **PAT Token**Add those values into a `.env` file similar to the one provided in `.env.example`
(Optional) Make sure the cluster you are targeting is already on. If the cluster is off, the first response will take additional time waiting for the cluster to come online.
### Create Fake User Data
Import the `.dbc` file under '/data/create_faker_data.dbc' into your Databricks workspace and run the notebook. This will create a Delta table for `users` under the a database `fastapi`.
## Run FastAPI
In the parent folder of this repo run the below command to start the FastAPI server.
`uvicorn app.main:app --reload`
And you're all set! You now have a FastAPI running on a Lakehouse.
## Acknowledgements
This example depends [sqlalchemy-databricks](https://github.com/crflynn/sqlalchemy-databricks) created by [crflynn](https://github.com/crflynn).
It is a thin wrapper for the [databricks-sql-connector](https://docs.databricks.com/dev-tools/python-sql-connector.html) and the [PyHive SQLAlchemy](https://github.com/dropbox/PyHive#sqlalchemy) libraries