Sling
Slingdata.ioBlogGithubHelp!
  • Introduction
  • Sling CLI
    • Installation
    • Environment
    • Running Sling
    • Global Variables
    • CLI Pro
  • Sling Platform
    • Sling Platform
      • Architecture
      • Agents
      • Connections
      • Editor
      • API
      • Deploy from CLI
  • Concepts
    • Replications
      • Structure
      • Modes
      • Source Options
      • Target Options
      • Columns
      • Transforms
      • Runtime Variables
      • Tags & Wildcards
    • Hooks / Steps
      • Check
      • Command
      • Copy
      • Delete
      • Group
      • Http
      • Inspect
      • List
      • Log
      • Query
      • Replication
      • Store
      • Read
      • Write
    • Pipelines
    • Data Quality
      • Constraints
  • Examples
    • File to Database
      • Custom SQL
      • Incremental
    • Database to Database
      • Custom SQL
      • Incremental
      • Backfill
    • Database to File
      • Incremental
    • Sling + Python 🚀
  • Connections
    • Database Connections
      • Athena
      • BigTable
      • BigQuery
      • Cloudflare D1
      • Clickhouse
      • Databricks
      • DuckDB
      • DuckLake
      • Iceberg
      • MotherDuck
      • MariaDB
      • MongoDB
      • Elasticsearch
      • MySQL
      • Oracle
      • Postgres
      • Prometheus
      • Proton
      • Redshift
      • S3 Tables
      • StarRocks
      • SQLite
      • SQL Server
      • Snowflake
      • Trino
    • Storage Connections
      • AWS S3
      • Azure Storage
      • Backblaze B2
      • Cloudflare R2
      • DigitalOcean Spaces
      • FTP
      • Google Drive
      • Google Storage
      • Local Storage
      • Min.IO
      • SFTP
      • Wasabi
Powered by GitBook
On this page
  • Setup
  • Authentication Options
  • Optional Parameters
  • Using sling conns
  • Environment Variable
  • Sling Env File YAML
  • Usage Examples
  1. Connections
  2. Storage Connections

Google Drive

Connect & Ingest data from / into Google Drive

Setup

The following credentials keys are accepted:

Authentication Options

Option 1: Service Account Key File

  • key_file (optional) -> Path to the service account JSON key file.

Option 2: Service Account Key Body

  • key_body (optional) -> The service account JSON key content as a string. Or as Environment Variable KEY_BODY.

Option 3: OAuth2 Credentials

  • client_id (optional) -> OAuth2 client ID.

  • client_secret (optional) -> OAuth2 client secret.

  • access_token (optional) -> OAuth2 access token.

  • refresh_token (optional) -> OAuth2 refresh token.

  • token_expiry (optional) -> Access token expiry time in RFC3339 format.

Optional Parameters

  • folder_id (recommended) -> Use a specific folder as the root directory instead of the actual Google Drive root.

  • file_id (optional) -> Direct access to a specific file by its Google Drive ID. When set, only read operations are supported.

  • scopes (optional) -> JSON array of Google Drive API scopes. Defaults to ["https://www.googleapis.com/auth/drive"].

Using sling conns

Here are examples of setting a connection named GDRIVE. We must provide the type=gdrive property:

# Using service account key file
$ sling conns set GDRIVE type=gdrive key_file="/path/to/service-account-key.json"

# Using OAuth2 credentials
$ sling conns set GDRIVE type=gdrive client_id="your-client-id" client_secret="your-client-secret" access_token="your-access-token" refresh_token="your-refresh-token"

# Using a specific folder as root
$ sling conns set GDRIVE type=gdrive key_file="/path/to/key.json" folder_id="1abc2def3ghi4jkl5mno6pqr7stu8vwx"

# Direct file access by ID (read-only)
$ sling conns set GDRIVE type=gdrive key_file="/path/to/key.json" file_id="1xyz2abc3def4ghi5jkl6mno7pqr8stu"

Environment Variable

In JSON/YAML format:

# Service account
export GDRIVE='{"type": "gdrive", "key_file": "/path/to/service-account-key.json"}'

# OAuth2
export GDRIVE='{"type": "gdrive", "client_id": "your-client-id", "client_secret": "your-client-secret", "access_token": "your-access-token", "refresh_token": "your-refresh-token"}'∂

Sling Env File YAML

connections:
  GDRIVE:
    type: gdrive
    key_file: /path/to/service-account-key.json
    folder_id: 1abc2def3ghi4jkl5mno6pqr7stu8vwx

  GDRIVE_OAUTH:
    type: gdrive
    client_id: your-client-id
    folder_id: 1abc2def3ghi4jkl5mno6pqr7stu8vwx
    client_secret: your-client-secret
    access_token: your-access-token
    refresh_token: your-refresh-token

  GDRIVE_FOLDER:
    type: gdrive
    key_file: /path/to/service-account-key.json
    folder_id: 1abc2def3ghi4jkl5mno6pqr7stu8vwx  # Use specific folder as root

  GDRIVE_FILE:
    type: gdrive
    key_file: /path/to/service-account-key.json
    file_id: 1xyz2abc3def4ghi5jkl6mno7pqr8stu  # Direct file access (read-only)

Usage Examples

# List files in Google Drive
sling run --src-conn GDRIVE --src-stream "folder/file.csv" --stdout

# Copy from local to Google Drive
sling run --src-stream file:///path/to/local.csv --tgt-conn GDRIVE --tgt-object "folder/remote.csv"

# Copy from Google Drive to database
sling run --src-conn GDRIVE --src-stream "data/file.csv" --tgt-conn MYDB --tgt-object "schema.table"

# Use wildcard patterns
sling run --src-conn GDRIVE --src-stream "reports/*.json" --stdout
PreviousFTPNextGoogle Storage

Last updated 9 days ago

See to learn more about the sling env.yaml file.

If you are facing issues connecting, please reach out to us at , on or open a Github Issue .

here
support@slingdata.io
discord
here