Skip to main content

A Python library for using Google Sheets as a database because I felt a need to make it.

Project description

GSheetsDB

A Python library for using Google Sheets as a database. This library provides a simple interface to perform database-like operations on Google Sheets.

py-gsheets-db

PyPI version Python Versions License: MIT

Features

  • Simple CRUD operations (Create, Read, Update, Delete)
  • Easy to use API
  • Type hints for better IDE support
  • Comprehensive error handling
  • Flexible querying options

Installation

pip install py-gsheets-db

Prerequisites

Before using the library, you need to:

  1. Set up Google Sheets API:

    • Go to Google Cloud Console
    • Create a new project
    • Enable Google Sheets API
    • Create service account credentials
    • Download the credentials JSON file
  2. Create a Google Sheet and get its ID (from the URL)

  3. Share your Google Sheet with the service account email (found in your credentials JSON)

Usage

from py_gsheets_db import GSheetsDB

# Initialize the database
db = GSheetsDB(
    credentials_path='path/to/credentials.json',
    spreadsheet_id='your-spreadsheet-id'
)

# Create a new table
db.create_table('users', ['id', 'name', 'email'])

# Insert data
db.insert('users', {
    'id': '1',
    'name': 'John Doe',
    'email': 'john@example.com'
})

# Select data
all_users = db.select('users')
specific_columns = db.select('users', columns=['name', 'email'])

# Update data
db.update(
    'users',
    where={'id': '1'},
    values={'name': 'John Smith'}
)

# Delete data
db.delete('users', where={'id': '1'})

API Reference

GSheetsDB

__init__(credentials_path: str, spreadsheet_id: str)

Initialize the Google Sheets database connection.

create_table(table_name: str, columns: List[str]) -> bool

Create a new worksheet (table) in the spreadsheet.

insert(table_name: str, data: Dict[str, Any]) -> bool

Insert a new row into the specified table.

select(table_name: str, columns: Optional[List[str]] = None) -> List[Dict[str, Any]]

Select data from the specified table.

update(table_name: str, where: Dict[str, Any], values: Dict[str, Any]) -> bool

Update rows in the specified table that match the where condition.

delete(table_name: str, where: Dict[str, Any]) -> bool

Delete rows from the specified table that match the where condition.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

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

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_gsheets_db-0.1.1.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

py_gsheets_db-0.1.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file py_gsheets_db-0.1.1.tar.gz.

File metadata

  • Download URL: py_gsheets_db-0.1.1.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_gsheets_db-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e04790eb1f8647a5cf33ddc356e96380b8b0b2cb027d8a3802c39db3fd143e5b
MD5 8f8bfe3f8d3ed6a529308246e25aebd5
BLAKE2b-256 5d96f2d62c453d580c766f9ee57c6b70c789e024376539024575c0a10b8b3665

See more details on using hashes here.

File details

Details for the file py_gsheets_db-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_gsheets_db-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for py_gsheets_db-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be5318898e027e6969889d39aec90482e367c984c90cf6cdf508bb252223e0e0
MD5 a248403563d5f537ed495daeb9b67434
BLAKE2b-256 f3cac781882ba1e2524ba3dbca2ebfc96f6a4f12d8d4b9619873de7c649ec2dc

See more details on using hashes here.

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