Count
count.co
  • Getting Started
    • What is Count?
    • Count FAQ
    • Intro to your workspace
    • Example canvases
    • Getting started guides
      • Set up your workspace and projects
        • 1. Review workspace settings
        • 2. Create and organise your projects
      • Canvas orientation
      • Your first ad hoc analysis
        • 1. Examples and templates
        • 2. Build your first queries
        • 3. Create visuals
        • 4. Caching, local cells and scheduling
        • 5. Collaborating with a stakeholder
      • Your first report
        • 1. Examples and templates
        • 2. Filters and control cells
        • 3. Sharing your report
        • 4. Alerts
  • Connect your data
    • Database connection overview
      • Athena
      • Azure Synapse
      • BigQuery
      • Databricks
      • Microsoft SQL Server
      • MySQL
      • PostgreSQL
      • Redshift
      • Snowflake
    • Refresh database schema
    • Upload CSV files
    • dbt integration
      • ☁️dbt Cloud integration
      • 👩‍💻dbt Core integration
  • Import & Export
    • Import from other tools
      • Import Miro files
      • Import SQL files
      • Import Google Sheets
      • Import Jupyter notebooks
    • Export code and results
      • Export compiled SQL and Jinja-SQL
      • Export CSV files
      • Export images and PDF files
  • THE CANVAS
    • Navigating the canvas
      • Canvas tool bar
      • Data sidebar
      • Customizing the canvas
    • Canvas objects
      • Cells
      • Text and markdown
      • Shapes and tools
      • Sticky notes
      • Frames
      • Images
      • Embeds
      • Stamps
      • Grouping objects
      • Object order and alignment
      • Locking objects
      • Scaling objects
      • Shared styles
    • Overviews
    • Templates
    • Count AI
    • Alerts and subscriptions
      • Slack integration
    • Keyboard shortcuts
  • Querying data
    • Cells overview
      • Dynamic query compilation engine
    • SQL cells
      • Referencing other cells
      • Jinja templating
      • SQL formatting
    • Python cells
    • Visual and low-code cells
      • Calculations in visuals and low-code cells
      • Joins in visuals and low-code cells
    • Control cells
      • Single and multiple selects
      • Date controls
      • Text, number, and boolean controls
      • Custom control cells
    • Local DuckDB cells
      • DuckDB on the server
    • Query caching and scheduling
    • Manage queries and results
    • Troubleshooting
  • Visualizing data
    • Visualization overview
    • Templated visuals
    • Custom visuals
      • Marks
      • Facet
      • Subplots
      • Style
      • Filters
    • Formatting a visual
      • Axes
        • Secondary Axis
      • Colors and labels
      • Legends
      • Tooltips
    • Column summaries
    • Dynamic text
    • Every Visual Under the Sun
  • Presenting and Reporting
    • Reports and Slides
  • Count Metrics
    • Intro to Count Metrics
    • Build and edit a catalog
    • Views
      • Creating views
      • Customizing views
    • Datasets
      • Creating datasets
    • Save changes to the catalog
      • Catalog validation
      • Version control
    • Exposing catalogs to the workspace
    • Caching in Count Metrics
    • Using the catalog
      • Explore from cell
  • Sharing and Permissions
    • Real-time collaboration
    • Comments
    • Sharing permissions
    • Shared links
    • Embedding canvases
  • History and Versions
    • Version control
    • Duplicating and merging
    • Data snapshots
  • Settings and administration
    • Workspace settings
      • Workspace members
      • Groups
      • Tags
      • Billing
      • Single sign-on (SSO)
        • Okta
        • Entra ID
        • JumpCloud
        • Google
        • Generic OIDC
      • Brand
    • Connection settings
    • Project settings
    • User settings
    • Roles and permissions
  • Quick guides
    • Interactive control guides
      • Date ranges
      • Date groupings
      • Search
      • Select All
  • Resources
    • Join the Slack community
  • Blog
  • Security overview
  • Terms of use
  • Pricing FAQ
Powered by GitBook
On this page
  • Option 1 - pandas.read_csv()
  • Option 2 - the gspread package
  • Option 3 - BigQuery
  1. Import & Export
  2. Import from other tools

Import Google Sheets

How to bring data from a Google Sheet into Count using Python or BigQuery

PreviousImport SQL filesNextImport Jupyter notebooks

Last updated 7 months ago

There are several methods available to import Google Sheets into Count, in order of increasing security (and complexity):

  • If the sheet is public - use the

  • If the sheet is private but will only be accessed in Count by people with permission to access it anyway - use the

  • If the sheet is private and security is important - import the sheet into

Option 1 - pandas.read_csv()

This is the simplest option, but only works if the sheet is public.

Step 1 - Make the sheet public

Head to your Sheet and click the Share menu in the upper-right. Under General access, enable the option for Anyone with the link:

Step 2 - Get the sheet key

Go to your Google Sheet and check the URL - it should look like:

https://docs.google.com/spreadsheets/d/SOME_LONG_KEY/edit#gid=0

Make a note of the long string of text after /d/ - this is the key for your sheet.

Step 3 - Read the sheet from Count

Head to Count and create a new Python cell, and insert:

import pandas as pd

key = 'SOME_LONG_KEY'
sheet_name = 'SHEET_NAME'
csv_url = f'https://docs.google.com/spreadsheets/d/{key}/gviz/tq?tqx=out:csv&sheet={sheet_name}'

pd.read_csv(csv_url)

where you should replace SOME_LONG_KEY and SHEET_NAME with the appropriate values for your Sheet.

Option 2 - the gspread package

Step 1 - Create a service account

Once enabled, head back to the APIs dashboard and select Credentials > Create credentials > Service account. Create a new service account and download a key in JSON format.

Step 2 - Invite the service account to your Sheet

Head to your Sheet and click the Share menu in the upper-right. Under People with access, ensure that you have invited the email address for your service account.

Step 3 - Access the sheet data in Count

In Count, create a new Python cell and enter your service account details:

import gspread
import pandas as pd

credentials = {
  'type': 'service_account',
  'project_id': '...',
  'private_key_id': '...',
  'private_key': '...',
  'client_email': '...',
  'client_id': '...',
  'auth_uri': '...',
  'token_uri': '...',
  'auth_provider_x509_cert_url': '...',
  'client_x509_cert_url': '...',
  'universe_domain': '...'
}

gs = gspread.service_account_from_dict(credentials)

sheet = # gs.open('SHEET_NAME') TODO - use the correct sheet name
worksheet = # sheet.sheet1 TODO - use the correct worksheet name

pd.DataFrame.from_records(worksheet.get_all_records())

Option 3 - BigQuery

This option is the most complex to implement, but it has the benefits of being completely secure compared to the alternative methods.

Step 1 - Import your Google Sheet to BigQuery as a table

In your BigQuery editor, select the ellipsis next to a dataset and select Create table:

Fill in the details required to create a table from Google Sheets

If your Google Sheet has a header row, remember under to select to skip 1 header row under Advanced options.

Step 2 - Create a new view

For example, by executing the following SQL query in your editor:

create table [new table] as (select * from [gsheet connected table])

Step 3 - Set up a scheduled query

If you'd like the data you use in Count to be up to date, set up a scheduled query at your desired interval (hourly is the most frequent).

This determines how frequently data from your Google Sheet is refreshed in Count. Be sure that the refresh frequency aligns with how often you expect edits to occur.

Step 4 - Refresh your BigQuery schema in Count

is a Python package for interacting with Google Sheets, and you can use it in Count to access the the contents of your sheets. This means that access to the Sheet is controlled by credentials that you create, but those credentials will be visible to anyone that can view the canvas, so care must be taken when using this method. If security is important, use the below.

If you haven't enabled the Google Drive and Google Sheets API, head to the , select Library and search for the Google Drive and Google Sheets APIs.

For more information on scheduled queries in BigQuery, check out .

If you haven't yet connected BigQuery to Count, first and your Google Sheet should appear.

Otherwise, to see your Google Sheet in your list of tables.

GCP APIs dashboard
this page
add your BigQuery connection
refresh your schema
gspread
third option
pandas read_csv() method
gspread Python library
BigQuery
Enable link sharing in Google Sheets
Paste in the email address for your service account