A

stripe-client-migration

How to Use
Run this codemod on your codebase using one of the following commands

The easiest way to run this codemod without installing anything globally:

Documentation

stripe-client-migration

Stripe Legacy to StripeClient Migration Codemod

This codemod migrates Python codebases from the legacy Stripe SDK usage patterns to the modern StripeClient pattern. It performs the following transformations:

Key Features:
Legacy Pattern Migration: Converts direct stripe.* calls (e.g., stripe.Customer.create()) to client-based calls (e.g., client.customers.create())

Resource Class Migration: Transforms standalone resource class calls (e.g., Customer.create()) to use the client pattern

Import Optimization: Updates import statements to remove the legacy stripe module and ensure StripeClient is imported

Smart Client Management:

Detects existing StripeClient instances and reuses them
Creates a default client when none exists
Handles getter-based client patterns by hoisting them to variables
Getter Pattern Optimization: Transforms repeated getter calls like get_stripe_client().customers.create() into hoisted variables to avoid redundant function calls

Example Transformation:

Before

from stripe import stripe, StripeClient, Customer
customer = stripe.Customer.create(name="John Doe")

After

from stripe import StripeClient, Customer
client = StripeClient('sk_test')
customer = client.customers.create(name="John Doe")

This codemod ensures a clean migration to the recommended StripeClient pattern while maintaining code functionality and improving performance by reducing redundant client instantiations.

Ready to contribute?

Build your own codemod and share it with the community.