@ebowwa/googlesheets
v0.3.2
Published
CLI tool for programmatic Google Sheets access with OAuth authentication
Maintainers
Readme
@ebowwa/googlesheets
A TypeScript CLI tool for programmatic Google Sheets access with OAuth authentication.
Features
- OAuth2 authentication (personal Google account)
- Fallback to service account support
- Google Sheets API access
- Google Drive API for creating spreadsheets
- Doppler integration for credential management
Installation
bun install -g @ebowwa/googlesheetsFrom source
git clone https://github.com/ebowwa/googlesheets.git
cd googlesheets
bun install
bun run buildSetup
1. Create OAuth 2.0 Credentials
Go to Google Cloud Console:
- Create a new OAuth 2.0 Client ID (Web application)
- Add redirect URI:
http://localhost:3000/callback - Add your email as a test user
- Save the Client ID and Secret
2. Run OAuth Setup
oauth-setupOr manually:
export GOOGLE_OAUTH_CLIENT_ID="your-client-id"
export GOOGLE_OAUTH_CLIENT_SECRET="your-client-secret"
oauth-setup3. Set Environment Variables
Using Doppler:
doppler secrets set GOOGLE_OAUTH_CLIENT_ID "your-client-id" -c prd
doppler secrets set GOOGLE_OAUTH_CLIENT_SECRET "your-client-secret" -c prd
doppler secrets set GOOGLE_OAUTH_REFRESH_TOKEN "your-refresh-token" -c prd
doppler secrets set GOOGLE_SHEET_ID "your-sheet-id" -c prdOr with .env:
GOOGLE_OAUTH_CLIENT_ID=your-client-id
GOOGLE_OAUTH_CLIENT_SECRET=your-client-secret
GOOGLE_OAUTH_REFRESH_TOKEN=your-refresh-token
GOOGLE_SHEET_ID=your-sheet-idUsage
Sheets CLI
# Get spreadsheet info
sheets-cli info
# Get data from a range
sheets-cli get "Sheet1!A1:C10"
# Update a cell
sheets-cli update "Sheet1!A1" "New value"
# Update notes column
sheets-cli update-notes 5 "Today's notes"
# Create a new worksheet
sheets-cli create "NewSheet"
# List all worksheets
sheets-cli list-sheetsCreate Spreadsheets
# Create a new spreadsheet (in your Drive)
create-sheet "My New Spreadsheet"OAuth Setup
# Run OAuth flow to get tokens
oauth-setupCLI Commands
sheets-cli
info- Get spreadsheet informationget [range]- Get data from sheet (default: Sheet1!A1:Z1000)update <range> <value>- Update a cellupdate-notes <row> <notes>- Update notes columncreate <sheet_name>- Create new worksheetlist-sheets- List all worksheets
create-sheet
<title>- Spreadsheet title (optional, default: "New Spreadsheet")
oauth-setup
- Opens browser for OAuth authorization
- Generates refresh token for CLI use
Environment Variables
| Variable | Required | Description |
|----------|----------|-------------|
| GOOGLE_OAUTH_CLIENT_ID | Yes | OAuth 2.0 Client ID |
| GOOGLE_OAUTH_CLIENT_SECRET | Yes | OAuth 2.0 Client Secret |
| GOOGLE_OAUTH_REFRESH_TOKEN | Yes | OAuth refresh token |
| GOOGLE_SHEET_ID | Yes | Target spreadsheet ID |
Project Structure
src/
├── cli/
│ ├── index.ts # Main CLI (sheets-cli)
│ ├── oauth-setup.ts # OAuth setup script
│ └── create-via-drive.ts # Spreadsheet creator
├── lib/
│ ├── oauth-auth.ts # OAuth authentication
│ ├── auth.ts # Service account auth (fallback)
│ └── sheets-client.ts # Google Sheets API client
└── types/
└── index.ts # TypeScript typesDependencies
googleapis- Google APIsgoogle-auth-library- Authenticationdotenv- Environment variables
License
MIT © Ebowwa Labs
