Skip to main content

A database-like interface for Google Sheets

Project description

Google Sheets as Backend (GSAB)

A Python library that enables using Google Sheets as a database backend with features like schema validation and encryption.

Features

  • 🔒 Secure Google Sheets integration with OAuth2
  • 📊 Schema validation and type checking
  • 🔐 Field-level encryption for sensitive data
  • 🌐 Async/await support
  • 📝 Comprehensive logging

Installation

pip install gsheets-db

Quick Start

  1. Set up Google Cloud Project and enable Google Sheets API:

    • Go to Google Cloud Console
    • Create a new project or select existing one
    • Enable Google Sheets API
    • Create OAuth 2.0 credentials
    • Download credentials JSON file
  2. Set up environment variables:

GOOGLE_CREDENTIALS_PATH=/path/to/credentials.json
ENCRYPTION_KEY=your-encryption-key
  1. Basic Usage:
from gsab import SheetConnection, Schema, Field, FieldType, SheetManager

# Define your schema
schema = Schema("users", [
    Field("id", FieldType.INTEGER, required=True, unique=True),
    Field("email", FieldType.STRING, required=True),
    Field("password", FieldType.STRING, required=True, encrypted=True)
])

# Connect and use
async def main():
    connection = SheetConnection()
    await connection.connect()
    
    sheet_manager = SheetManager(connection, schema)
    
    # Create a new sheet
    sheet = await sheet_manager.create_sheet("Users Data")
    
    # Insert data
    await sheet_manager.insert({
        "id": 1,
        "email": "user@example.com",
        "password": "secretpass123"  # Will be automatically encrypted
    })

Schema Definition

Define your data structure with type checking and validation:

from gsab import Schema, Field, FieldType, ValidationRule

schema = Schema("users", [
    Field("id", FieldType.INTEGER, required=True, unique=True),
    Field("email", FieldType.STRING, required=True),
    Field("age", FieldType.INTEGER, min_value=0, max_value=150),
    Field("password", FieldType.STRING, required=True, encrypted=True)
])

Security Features

Field Encryption

Sensitive data is automatically encrypted when the field is marked with encrypted=True:

# Fields marked as encrypted will be automatically handled
schema = Schema("users", [
    Field("ssn", FieldType.STRING, encrypted=True),
    Field("credit_card", FieldType.STRING, encrypted=True)
])

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

PyPI version Tests codecov

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

gsab-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

gsab-0.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file gsab-0.1.0.tar.gz.

File metadata

  • Download URL: gsab-0.1.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for gsab-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7b77aa8ea0c67fd54e29fb3cf4a69e0966412cc18ef7bdc5dfa04dc199e1f4e
MD5 d75d79e04af76e762f1659775efb6cdf
BLAKE2b-256 671fb4a2a3aa9384746780b142043898729a59e518ac08e3ff45a4ecb5d1672d

See more details on using hashes here.

File details

Details for the file gsab-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gsab-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for gsab-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b8552ff1e9255f30ff562a38c7729c1d92ed8659b72d468132f08e6409d6e304
MD5 092ae83e53c8266c553be644734522c3
BLAKE2b-256 68a7e8a413a9f2afe0663363aeee855504b4d4652522e361369fc084bda27bca

See more details on using hashes here.

Supported by

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