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.

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.0.tar.gz (5.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_gsheets_db-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_gsheets_db-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 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.0.tar.gz
Algorithm Hash digest
SHA256 12d99c899c0fb80c26f5f8a7ff1c1804f6bfbd37b74e952976cda0d548e082b6
MD5 1631e0264c1bc57fd6ac0f9a4a1c1faa
BLAKE2b-256 b347767c86df96255fdbe27b99478f0ceffc67f627659cbaf4cee21cc43d0d69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_gsheets_db-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccca298e00c1189a49235156ea5b0fca938cf83cc2ce9c913d975ae8cb431413
MD5 41fbe85b1ab0614e23b4ea941d276425
BLAKE2b-256 a86bda39787297301da880ee8ce7629d8648cb9c0fedcd350cd406478e4d3768

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