Google Sheets
API Reference - Google Sheets#
Complete API reference for the wolpie.gsheets module.
Authentication#
_gauth
#
Classes#
GAuth
#
Google authentication handler for service accounts.
This class manages Google service account credentials and provides authentication for Google API services.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logger
|
Logger | None
|
Optional logger instance for logging. |
None
|
credentials_path
|
Path | None
|
Path to the service account JSON file. |
None
|
credentials_info
|
CredentialsInfo | None
|
CredentialsInfo object with service account details. |
None
|
scopes
|
list[str] | None
|
List of OAuth scopes to request. |
None
|
**kwargs
|
Any
|
Additional keyword arguments passed to credentials. |
{}
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If neither credentials_info nor credentials_path is provided. |
Example
Source code in src/wolpie/gsheets/_gauth.py
Functions#
credentials_from_env
#
Load Google service account credentials from environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
The prefix for environment variable names. Default is "G". |
'G'
|
Returns:
| Type | Description |
|---|---|
CredentialsInfo
|
A CredentialsInfo object containing the credentials. |
Example
Source code in src/wolpie/gsheets/_gauth.py
Sheets Client#
_gsheets
#
Classes#
SheetMainProperties
#
SheetProperty
#
GSheets
#
Google Sheets API client for reading and writing spreadsheet data.
This class provides a high-level interface for interacting with Google Sheets, including reading values, writing values, and managing sheet metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
SERVICE_NAME |
str
|
The Google API service name ("sheets"). |
GSHEETS_API_VERSION |
str
|
The Google Sheets API version to use. |
GSHEETS_NUM_RETRIES |
int
|
Number of retries for failed API requests. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
g_auth
|
GAuth
|
GAuth instance with valid credentials. |
required |
spreadsheet_id
|
str
|
The ID of the Google Spreadsheet to interact with. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid authentication credentials are provided. |
RuntimeError
|
If the spreadsheet doesn't have auto recalc set to ON_CHANGE. |
Example
from wolpie.gsheets import GAuth, GSheets
from pathlib import Path
# Authenticate and create client
auth = GAuth(credentials_path=Path("service-account.json"))
sheets = GSheets(auth, spreadsheet_id="your-spreadsheet-id")
# Read values
values = sheets.read_values("Sheet1!A1:B10")
# Write values
sheets.write_values("Sheet1!A1", [[1, 2], [3, 4]])
Source code in src/wolpie/gsheets/_gsheets.py
Attributes#
GSHEETS_API_VERSION
class-attribute
instance-attribute
#
GSHEETS_NUM_RETRIES
class-attribute
instance-attribute
#
Functions#
as_datetime
#
Source code in src/wolpie/gsheets/_gsheets.py
read_cells
#
read_cells(
sheet,
cell_range=None,
major_dimension=ROWS,
value_renderer_option=UNFORMATTED_VALUE,
date_time_render_option=SERIAL_NUMBER,
num_retries=None,
)
Source code in src/wolpie/gsheets/_gsheets.py
update_cells
#
update_cells(
sheet,
body,
cell_range=None,
value_input_option=USER_ENTERED,
include_values_in_response=False,
response_value_render_option=UNFORMATTED_VALUE,
response_date_time_render_option=SERIAL_NUMBER,
num_retries=None,
)
Source code in src/wolpie/gsheets/_gsheets.py
Functions#
Google Types#
gt
#
Classes#
AutoRecalc
#
NumberFormatType
#
NumberFormat
#
Color
#
ThemeColorType
#
ColorStyle
#
Border
#
Borders
#
Padding
#
HorizontalAlign
#
VerticalAlign
#
WrapStrategy
#
TextDirection
#
Bases: StrEnum
HyperlinkDisplayType
#
Bases: StrEnum
TextRotation
#
IterativeCalculationSettings
#
ThemeColorPair
#
SpreadsheetTheme
#
SpreadsheetProperties
#
ErrorValue
#
ExtendedValue
#
TextFormatRun
#
ConditionType
#
RelativeDate
#
ConditionValue
#
BooleanCondition
#
DataValidationRule
#
PivotGroupMetadata
#
SortOrder
#
PivotGroupSortValueBucket
#
ManualRuleGroup
#
HistogramRule
#
DateTimeRuleType
#
PivotGroupRule
#
PivotGroupLimit
#
PivotFilterCriteria
#
PivotFilterSpec
#
PivotValueSummarizeFunction
#
PivotValueCalculatedDisplayType
#
Bases: StrEnum
Attributes#
PIVOT_VALUE_CALCULATED_DISPLAY_TYPE_UNSPECIFIED
class-attribute
instance-attribute
#
PIVOT_VALUE_CALCULATED_DISPLAY_TYPE_UNSPECIFIED = (
"PIVOT_VALUE_CALCULATED_DISPLAY_TYPE_UNSPECIFIED"
)
PERCENT_OF_ROW_TOTAL
class-attribute
instance-attribute
#
PERCENT_OF_COLUMN_TOTAL
class-attribute
instance-attribute
#
PERCENT_OF_GRAND_TOTAL
class-attribute
instance-attribute
#
PivotValueLayout
#
DataExecutionState
#
DataExecutionErrorCode
#
Bases: StrEnum
Attributes#
DATA_EXECUTION_ERROR_CODE_UNSPECIFIED
class-attribute
instance-attribute
#
UNSUPPORTED_DATA_TYPE
class-attribute
instance-attribute
#
DUPLICATE_COLUMN_NAMES
class-attribute
instance-attribute
#
TOO_MANY_CHARS_PER_CELL
class-attribute
instance-attribute
#
MISSING_COLUMN_ALIAS
class-attribute
instance-attribute
#
OBJECT_IN_ERROR_STATE
class-attribute
instance-attribute
#
OBJECT_SPEC_INVALID
class-attribute
instance-attribute
#
DATA_EXECUTION_CANCELLED
class-attribute
instance-attribute
#
DataExecutionStatus
#
GridRange
#
DataSourceTableColumnSelectionType
#
FilterSpec
#
DataSourceFormula
#
DisplayFormat
#
RichLinkProperties
#
PersonProperties
#
ChipRun
#
DeveloperMetadataLocationType
#
Dimension
#
DimensionRange
#
DeveloperMetadataLocation
#
DeveloperMetadataVisibility
#
DeveloperMetadata
#
DimensionProperties
#
GridData
#
BooleanRule
#
InterpolationPointType
#
InterpolationPoint
#
GradientRule
#
ConditionalFormatRule
#
Editors
#
BasicFilter
#
TextPosition
#
DataSourceChartProperties
#
ChartHiddenDimensionStrategy
#
BasicChartSpec
#
Bases: TypedDict
EmbeddedChart
#
BandedRange
#
DimensionGroup
#
Slicer
#
ColumnType
#
TableColumnProperties
#
TableRowsProperties
#
DataSourceColumn
#
DataSourceSheetProperties
#
NamedRange
#
BigQueryTableSpec
#
BigQueryDataSourceSpec
#
LookerDataSourceSpec
#
DataSourceParameter
#
DataSourceSpec
#
DataSource
#
TimeOfDay
#
DataSourceRefreshDailySchedule
#
DataSourceRefreshWeeklySchedule
#
DataSourceRefreshMonthlySchedule
#
Interval
#
DataSourceRefreshScope
#
DataSourceRefreshSchedule
#
Bases: TypedDict
ValueRenderOption
#
DateTimeRenderOption
#
ValueRange
#
ValueInputOption
#
UpdateValuesResponse
#
Bases: TypedDict