Stripe to BigQuery

This page provides you with instructions on how to extract data from Stripe and load it into Google BigQuery. (If this manual process sounds onerous, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

What is Google BigQuery?

Google BigQuery is a data warehouse that delivers super-fast results from SQL queries, which it accomplishes using a powerful engine dubbed Dremel. With BigQuery, there's no spinning up (and down) clusters of machines as you work with your data. With all of that said, it's clear why some claim that BigQuery prioritizes querying over administration. It's super fast, and that's the reason why most folks use it.

Getting data out of Stripe

Getting your Stripe data into your data warehouse starts with pulling that data off of Stripe’s servers. You can do this using the Stripe API, and that documentation can be accessed here. Stripe’s API uses REST to allow customers to retrieve information on transactions and more.

Sample Stripe data

The Stripe API returns JSON-formatted data. Below is an example of the kind of response you might see when querying for a transaction.


Stripe\Charge JSON: {
  "id": "ch_1743p92eZvKYlo2Cw2JNErfI",
  "object": "charge",
  "amount": 10400,
  "amount_refunded": 0,
  "application_fee": null,
  "balance_transaction": "txn_1728rq2eZvKYlo2C91cyTIf5",
  "captured": true,
  "created": 1446791747,
  "currency": "usd",
  "customer": "cus_3nkNHu4SYjMlBC",
  "description": null,
  "destination": null,
  "dispute": null,
  "failure_code": null,
  "failure_message": null,
  "fraud_details": {
  },
  "invoice": "in_1742qw2eZvKYlo2C4zE3pp4a",
  "livemode": false,
  "metadata": {
  },
  "paid": true,
  "receipt_email": null,
  "receipt_number": null,
  "refunded": false,
  "refunds": {
    "object": "list",
    "data": [

    ],
    "has_more": false,
    "total_count": 0,
    "url": "/v1/charges/ch_1743p92eZvKYlo2Cw2JNErfI/refunds"
  },
  "shipping": null,
  "source": {
    "id": "card_103nkN2eZvKYlo2CzNg6Clei",
    "object": "card",
    "address_city": null,
    "address_country": null,
    "address_line1": null,
    "address_line1_check": null,
    "address_line2": null,
    "address_state": null,
    "address_zip": null,
    "address_zip_check": null,
    "brand": "Visa",
    "country": "US",
    "customer": "cus_3nkNHu4SYjMlBC",
    "cvc_check": null,
    "dynamic_last4": null,
    "exp_month": 12,
    "exp_year": 2023,
    "funding": "credit",
    "last4": "4242",
    "metadata": {
    },
    "name": null,
    "tokenization_method": null
  },
  "statement_descriptor": null,
  "status": "succeeded"
}

Preparing Stripe data

This part can get tricky: you need to parse JSON in the API response and map each endpoint to a corresponding table in the destination database. That means you're going to have to know the datatypes for each endpoint. The Stitch Stripe Docs can give you a sense of what datatypes will come through the API.

Loading data into Google BigQuery

Google Cloud Platform offers a helpful guide for loading data into BigQuery. You can use the bq command-line tool to upload the files to your awaiting datasets, adding the correct schema and data type information along the way. The bq load command is your friend here. You can find the syntax in the bq command-line tool quickstart guide. Iterate through this process as many times as it takes to load all of your tables into BigQuery.

Keeping Stripe data up to date

So, now what? You’ve built a script that pulls data from Stripe and loads it to your destination, but what happens tomorrow when you have hundreds of new transactions?

The key is to build your script in such a way that it can also identify incremental updates to your data. Thankfully, Stripe’s API results include fields like “created” that allow you to quickly identify records that are new since your last update (or since the newest record you’ve copied). Last thing: set your script up as a cron job or continuous loop to keep pulling down new data as it appears.

Other data warehouse options

BigQuery is really great, but sometimes you need to optimize for different things when you're choosing a data warehouse. Some folks choose to go with Postgres or Redshift, which are two RDBMSes that use similar SQL syntax. If you're interested in seeing the relevant steps for loading this data into Postgres or Redshift, check out To Redshift and To Postgres.

Easier and faster alternatives

If all this sounds a bit overwhelming, don’t be alarmed. If you have all the skills necessary to go through this process, chances are building and maintaining a script like this isn’t a very high-leverage use of your time.

Thankfully, products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your Stripe data via the API, structuring it in a way that is optimized for analysis, and inserting that data into your Google BigQuery data warehouse.