Stripe Dataset

Export your Stripe data into Pandas Dataframes. Analyzing your revenue metrics has never been easier.

Authentication

Downloading more than 10,000 rows?

A PetalData API key is required. Email support@petaldata.app to obtain an API key.

Your Stripe API key must be passed to PetalData. You can view your API keys in the Developers area of the Stripe dashboard. Read permissions are required for core and billing resources.

import petaldata

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"
curl http://localhost:3001/stripe/invoices.csv?limit=5 \
-H "STRIPE_API_KEY: [YOUR STRIPE API KEY]" \

Examples

Try out PetalData using Google Colab. The examples below link to remote notebooks that allow you to immediately analyze your data. Make a copy of the Notebook, then enter your Stripe API key to run each example.

Stripe revenue by month

Exports 90 days of Stripe invoices and generates a table + plot of revenue by month.


Invoices

Invoices are statements of amounts owed by a customer, and are either generated one-off, or generated periodically from a subscription.

grid_on Preview

Initialize Invoices

Initializes a Stripe Invoices dataset, loading the dataset if it was previously saved to storage.

Arguments

Name Description
base_pickle_filename
optional string
Specifies the name of the Pickle file the Dataset should be loaded from and saved to. If the file doesn't exit, it will be created when the Dataset is saved.

The default is stripe_invoices.pkl.

import petaldata

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"

invoices = petaldata.datasets.stripe.Invoices()
# Access previously saved invoices via a Pandas Dataframe
df = invoices.df

Download Invoices

Downloads Invoices from Stripe. Invoices are accessible as a Pandas Dataframe via the Invoices.df attribute after the download completes.

Invoices.df is overwritten with the new downloaded data. The dataframe is not saved automatically following the download - call Invoices.save() to save the dataset.

In-progress downloads are saved as csv files to local storage.

Arguments

Name Description
created_gt
optional datetime
Return invoices created after this value.
created_gte
optional datetime
Return invoices created on or after this value.
updated_gte
optional datetime
Return invoices updated on or after this avlue.
limit
optional integer
Limits the number of invoices returned.
import petaldata

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"

invoices = petaldata.datasets.stripe.Invoices()
invoices.download(limit=5)
# Access downloaded invoices via a Pandas Dataframe
df = invoices.df
curl http://localhost:3001/Stripe/invoices.csv?limit=5 \
-H "STRIPE_API_KEY: [YOUR STRIPE API KEY]" \

Save Invoices

Saves a downloaded or upsert-ed invoices dataset to storage as a Pickle file. Invoices.save() overwrites the existing Pickle file if it exists.

Arguments

No arguments.
import petaldata

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"

invoices = petaldata.datasets.stripe.Invoices()
invoices.download(limit=5)
# Saves invoices to a pickle file.
invoices.save()

Upsert Invoices

Updates existing invoices in Invoices.df and inserts new invoices into the dataframe.

Invoices.df is overwritten with the updated data. The dataframe is not saved automatically following the upsert - call Invoices.save() to save the dataset.

Arguments

Name Description
created_gt
optional datetime
Return invoices created after this value. If not provided, only new rows created after Invoices.updated are inserted and existing rows are not updated.
import petaldata
from datetime import datetime, timedelta

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"

invoices = petaldata.datasets.stripe.Invoices()
invoices.upsert(created_gt=datetime.now() - timedelta(days=30))
# Access invoices via a Pandas Dataframe
df = invoices.df

Delete Invoices

Deletes the associated saved Pickle file and the dataframe accessible at Invoices.df. This does not delete data within your Stripe account.

Arguments

No arguments.
import petaldata

petaldata.datasets.stripe.api_key = "[YOUR STRIPE API KEY]"

invoices = petaldata.datasets.stripe.Invoices()
invoices.delete()