Skip to content

Instantly share code, notes, and snippets.

@skoudoro
Last active January 11, 2023 21:59
Show Gist options
  • Save skoudoro/f4bed874661d1746479d78e2eeab90ea to your computer and use it in GitHub Desktop.
Save skoudoro/f4bed874661d1746479d78e2eeab90ea to your computer and use it in GitHub Desktop.
saas metrics in python
"""This need some work but this is a starter."""
# Import Stripe Python Library
import stripe
# Connect to stripe
stripe.api_key = {your_api_key}
# Get saas monthly revenue
monthly_revenue = stripe.Charge.list(
limit=100
).auto_paging_iter().aggregate(
fn=sum, field="amount"
)
print("Monthly revenue: $" + str(monthly_revenue))
# Get saas monthly customers
monthly_customers = stripe.Customer.list(
limit=100
).auto_paging_iter().aggregate(
fn=len
)
print("Monthly customers: " + str(monthly_customers))
# Get saas monthly sign ups
monthly_sign_ups = stripe.Invoice.list(
limit=100
).auto_paging_iter().filter(
fn=lambda x: x.status=='paid'
).aggregate(
fn=len
)
print("Monthly sign ups: " + str(monthly_sign_ups))
# Get saas monthly churn rate
monthly_churn_rate = 1 - (monthly_customers/monthly_sign_ups)
print("Monthly churn rate: " + str(monthly_churn_rate))
# Basic Stripe Payment Information
arr = stripe.Balance.retrieve()['total']
mrr = stripe.Payments.list()['amount_received']
cltv = stripe.Invoices.list()['amount_paid']
# ARPU - Average Revenue Per User
user_list = stripe.Customers.list()
user_num = 0
for user in user_list:
user_num += 1
arpu = arr/user_num
# Churn Rate
churn_rate = stripe.Refunds.list()['amount_refunded'] / mrr
# Usage and Engagement
dau = stripe.Payments.list()['succeeded']
mau = stripe.Payments.list()['closed']
# User Retention Rate
retention_rate = stripe.Customers.list()['active']/user_num
# User Acquisition Cost
uac = stripe.Payouts.list()['amount_sent']/user_num
# Product Performance
feature_adopt = stripe.Subscriptions.list()['quantity']/user_num
session_length = stripe.UsageRecords.list()['duration']
unique_pageviews = stripe.ConnectedAccounts.list()['account_types']
# Time To Live
ttl = stripe.Transfers.list()['currency']/mrr
# User Traffic Sources
user_traffic = stripe.Sources.list()['service_provider']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment