Skip to main content

A Python library for Google Sheets with high-level API, automatic type inference, and efficient caching.

Project description

SmartSpread

A Python library for Google Sheets that extends gspread with a high-level API, automatic type inference, and efficient caching.

Features

  • Simple API: Intuitive interface for spreadsheet and tab operations
  • Multiple Data Formats: Work with DataFrames, list of dicts, or list of lists
  • Automatic Type Inference: Smart conversion of numeric, string, and None values
  • Efficient Caching: Minimizes API calls to stay within rate limits
  • Pandas Integration: Seamless DataFrame read/write operations
  • Row Operations: Update or insert rows based on column patterns

Installation

pip install smartspread

Quick Start

Authentication

  1. Create a Google Cloud Project
  2. Enable the Google Sheets API
  3. Create a service account and download credentials JSON
  4. Share your spreadsheet with the service account email

Basic Usage

from smartspread import SmartSpread

# Initialize with credentials
spread = SmartSpread(
    sheet_identifier="your-spreadsheet-id-or-name",
    key_file="path/to/credentials.json"
)

# Get or create a tab
tab = spread.tab("MyTab")

# Read data as DataFrame
df = tab.read_data()

# Modify data
tab.data["new_column"] = "value"

# Write back to Google Sheets
tab.write_data(overwrite_tab=True)

Update Rows by Pattern

# Update existing row or insert new one
tab.update_row_by_column_pattern(
    column="ID",
    value=123,
    updates={"Status": "completed", "Updated": "2024-01-01"}
)
tab.write_data(overwrite_tab=True)

Filter Data

# Filter rows by pattern
filtered = tab.filter_rows_by_column("Name", "Alice")
print(filtered)

Work with Different Formats

# DataFrame format (default)
tab_df = spread.tab("Sheet1", data_format="DataFrame")
df = tab_df.data  # pandas DataFrame

# List of dicts format
tab_dict = spread.tab("Sheet2", data_format="dict")
data = tab_dict.data  # [{"col1": "val1", ...}, ...]

# List of lists format
tab_list = spread.tab("Sheet3", data_format="list")
data = tab_list.data  # [["header1", "header2"], ["val1", "val2"], ...]

Refresh Data

# Reload data after external changes
tab.refresh()

# Refresh spreadsheet metadata
spread.refresh()

API Reference

SmartSpread

  • SmartSpread(sheet_identifier, key_file=None, service_account_data=None, user_email=None)
  • spread.tab(tab_name, data_format="DataFrame", keep_number_formatting=False) - Get or create tab
  • spread.tab_names - List all tab names
  • spread.tab_exists(tab_name) - Check if tab exists
  • spread.url - Get spreadsheet URL
  • spread.grant_access(email, role="owner") - Grant access to user
  • spread.refresh() - Clear cache and reload metadata

SmartTab

  • tab.read_data() - Read data from Google Sheets
  • tab.write_data(overwrite_tab=False, as_table=False) - Write data to Google Sheets
  • tab.update_row_by_column_pattern(column, value, updates) - Update or insert row
  • tab.filter_rows_by_column(column, pattern) - Filter rows by pattern
  • tab.refresh() - Reload data from Google Sheets
  • tab.data - Access the data (DataFrame, list of dicts, or list of lists)

Notes

  • Google Sheets API has rate limits (60 requests/minute for free tier)
  • SmartSpread uses caching to minimize API calls
  • Empty cells are represented as None in DataFrames
  • Integer columns use nullable Int64 dtype to preserve None values

Changelog

v1.1.3 (2024)

  • Fixed: pd.NA values now properly sanitized to None in list and dict output formats

v1.1.2 (2024)

  • Changed: Package renamed to smartspread (no underscore) for cleaner imports
  • Added: Backwards compatibility for from smart_spread import ... with deprecation warning

v1.1.1 (2024)

  • Fixed: JSON serialization error when using data_format="list" with nullable Int64 columns containing pd.NA values

License

MIT License - see LICENSE file for details.

Links

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

smartspread-1.1.3.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

smartspread-1.1.3-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file smartspread-1.1.3.tar.gz.

File metadata

  • Download URL: smartspread-1.1.3.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for smartspread-1.1.3.tar.gz
Algorithm Hash digest
SHA256 657c15e55f529c65487cd782195ca5b3e842d346eb75fbfeb89827f94a155919
MD5 31ecc270f606cf75879e9c81344f089b
BLAKE2b-256 bd3e170d1707b535e17efbb058a6410a36f9a96dbe34cb08b0f20b6d5018732c

See more details on using hashes here.

File details

Details for the file smartspread-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: smartspread-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for smartspread-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 70d4031871a481c1aa4f3e4d8b623217565d8aa0d854a00e135df216d954c07b
MD5 d015d33f3d6ce841d085baa9fcc89a47
BLAKE2b-256 b2ee56166283fc20d28920677cab9945ac0980f16f2b5779f66bbc652161df3e

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