Skip to main content

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

  1. Go to the Google Cloud Console.
  2. Create a new project.
  3. Go to APIs & Services > Library and enable:
    • Google Sheets API
    • Google Drive API
  4. Go to APIs & Services > Credentials.
  5. Click Create Credentials > Service Account.
  6. Once created, go to the Keys tab and click Add Key > Create New Key (JSON).
  7. Download the file and rename it to credentials.json in 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

  1. Initialization: Data is synced from the source into a hidden local SQLite DB (.db_cache/).
  2. Operations: All CRUD reflects immediately in the fast SQLite cache.
  3. 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

py_sheet_db-0.1.1.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_sheet_db-0.1.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

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

Hashes for py_sheet_db-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c0bbae6f61581f98311a389d02037d282b19abe2c8b7b598e2d380575392f04e
MD5 c9ae255e7cf4c29b186cc5be82a26d57
BLAKE2b-256 86ced18da50763a8772615e0b9a56ffa9d042bc7565b736d6c03b67e0cffeb4e

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for py_sheet_db-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24312c9bd5887acbba05181595a3f90e6939a4cf2a98a5679945f4f7f9ea8bf8
MD5 1841c334629b267897dec99720fd43f8
BLAKE2b-256 df04b8e7a2ce9e04fcbfce21fcf9744b3c9b0af08e5846a429ed641ab0dc0556

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page