A unified database interface for Google Sheets, Excel, and CSV.
Project description
py-sheet-db: Unified Tabular Database
A "plug and play" Python library that treats Google Sheets, Excel files, and CSV directories as relational databases. It features unified caching, schema validation, and multi-format support.
Features
- Multi-Format Support: One API for Google Sheets,
.xlsx, and.csv. - Fast CRUD: Uses a local SQLite cache for near-instant operations.
- No Data Loss: Changes are tracked locally and synchronized via
flush(). - Relational Views: Perform Joins and Filters across multiple sheets or formats.
- Schema Validation: Enforce data types and required fields across any storage format.
Installation
pip install gspread google-auth pandas openpyxl
Quick Start
PySheetDB can automatically detect the driver or you can set it explicitly using the driver_type parameter.
from py_sheet_db import PySheetDB
# 1. Automatic Detection
db = PySheetDB("data.xlsx")
# 2. Explicit Type Selection ('excel', 'csv', or 'gsheets')
db = PySheetDB("my_data_folder", driver_type='csv')
# 3. Google Sheets (requires credentials.json)
db = PySheetDB("credentials.json", driver_type='gsheets', spreadsheet_id='YOUR_ID')
# Or use the helper:
db = PySheetDB.connect_gsheets("credentials.json")
Schema Validation
Enforce data types and required fields. py-sheet-db will attempt to auto-cast types (e.g., string to int) when possible.
from py_sheet_db import Schema
user_schema = Schema({
'id': int,
'name': str,
'email': str,
'balance': float
})
users = db.table('Users', schema=user_schema)
users.insert({'id': 1, 'name': 'Alice', 'email': 'alice@example.com', 'balance': 50.5})
Relational Views (Joins & Filters)
You can create virtual views that merge data from multiple tables using a SQL-like interface powered by Pandas.
# 1. Define your tables
orders = db.table('Orders')
products = db.table('Products')
# 2. Create a View
# Join Orders and Products on 'product_id'
order_details = db.view('OrderDetails', [orders, products]) \
.join(orders, products, on='product_id', how='left') \
.filter(lambda df: df[df['status'] == 'completed'])
# 3. Get results as a list of dicts
results = order_details.get_data()
CRUD Operations
# Access a Table
users = db.table('Users')
# Insert
users.insert({'id': 1, 'name': 'Alice'})
# Find (Returns list of dicts)
admin = users.find(role='admin')
# Find One
bob = users.find_one(id=102)
# Flush to source (GSheets/Excel/CSV)
db.flush()
Google Sheets Setup
To use Google Sheets, you need a Service Account JSON key file.
1. Get Google Credentials
- Go to the Google Cloud Console.
- Create a new project.
- Go to APIs & Services > Library and enable:
- Google Sheets API
- Google Drive API
- Go to APIs & Services > Credentials.
- Click Create Credentials > Service Account.
- Once created, go to the Keys tab and click Add Key > Create New Key (JSON).
- Download the file and rename it to
credentials.jsonin your project folder.
2. Share the Spreadsheet
- Once you have your service account email (e.g.,
account-name@project-id.iam.gserviceaccount.com), you must Share your Google Spreadsheet with this email address with "Editor" permissions. - Alternatively, if you use
db.create_database("Name"), the library creates a new spreadsheet owned by the service account. You may still need to share it with your personal email to see it in your browser.
How it works
- Initialization: Data is synced from the source into a hidden local SQLite DB (
.db_cache/). - Operations: All CRUD reflects immediately in the fast SQLite cache.
- Synchronization:
db.flush()(or automatic exit hook) pushes "dirty" rows back to the primary storage.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_sheet_db-0.1.1.tar.gz.
File metadata
- Download URL: py_sheet_db-0.1.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0bbae6f61581f98311a389d02037d282b19abe2c8b7b598e2d380575392f04e
|
|
| MD5 |
c9ae255e7cf4c29b186cc5be82a26d57
|
|
| BLAKE2b-256 |
86ced18da50763a8772615e0b9a56ffa9d042bc7565b736d6c03b67e0cffeb4e
|
Provenance
The following attestation bundles were made for py_sheet_db-0.1.1.tar.gz:
Publisher:
publish.yml on nishant-sg/py-db-sheet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_sheet_db-0.1.1.tar.gz -
Subject digest:
c0bbae6f61581f98311a389d02037d282b19abe2c8b7b598e2d380575392f04e - Sigstore transparency entry: 1408120723
- Sigstore integration time:
-
Permalink:
nishant-sg/py-db-sheet@f8cd685c0e519a62e4f87504ebf7f7eda82dca23 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/nishant-sg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8cd685c0e519a62e4f87504ebf7f7eda82dca23 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_sheet_db-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py_sheet_db-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24312c9bd5887acbba05181595a3f90e6939a4cf2a98a5679945f4f7f9ea8bf8
|
|
| MD5 |
1841c334629b267897dec99720fd43f8
|
|
| BLAKE2b-256 |
df04b8e7a2ce9e04fcbfce21fcf9744b3c9b0af08e5846a429ed641ab0dc0556
|
Provenance
The following attestation bundles were made for py_sheet_db-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on nishant-sg/py-db-sheet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_sheet_db-0.1.1-py3-none-any.whl -
Subject digest:
24312c9bd5887acbba05181595a3f90e6939a4cf2a98a5679945f4f7f9ea8bf8 - Sigstore transparency entry: 1408120825
- Sigstore integration time:
-
Permalink:
nishant-sg/py-db-sheet@f8cd685c0e519a62e4f87504ebf7f7eda82dca23 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/nishant-sg
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f8cd685c0e519a62e4f87504ebf7f7eda82dca23 -
Trigger Event:
push
-
Statement type: