Management Commands
Django commands for setting up plans in Stripe and syncing Stripe data.
One command pushes your plans to Stripe; the others pull Stripe's data into the local database, for initial setup, disaster recovery or reconciliation.
sync_stripe_plans
Makes Stripe's products and prices match subscriptions/plans.py, then pulls them into the database:
python manage.py sync_stripe_plans --dry-run # show what would change
python manage.py sync_stripe_plans
python manage.py sync_stripe_plans --skip-db # change Stripe only| Option | Description |
|---|---|
--dry-run | Only show what would change |
--skip-db | Don't pull the result into this database |
What it does:
- Creates or updates one product per paid plan, tagged with
metadata.plan - Creates monthly and yearly prices with lookup keys (
pro_month,pro_year). A changed price becomes a new price that takes over the lookup key; the old one is archived, and existing subscribers keep paying it until they change plan - Archives products that aren't a plan
- Sets the billing portal's default configuration to offer exactly these plans and prices
Running it again changes nothing. Run it in test mode while developing, and once with the live key before launch. See Plans.
pull_stripe
Orchestrates a full sync of all Stripe data:
python manage.py pull_stripeRuns these commands in sequence:
update_stripe_products— Syncs products and pricesupdate_stripe_customers— Syncs customer recordsupdate_stripe_subscriptions— Syncs subscription data
update_stripe_products
Fetches all products and prices from Stripe and updates local records:
python manage.py update_stripe_productsWhat it does:
- Creates/updates
Productrecords (id, name, description, active) - Creates/updates
Pricerecords (id, product, amount, frequency, currency) - Copies each product's
metadata.planintoProduct.plan - Syncs feature mappings from product metadata
update_stripe_customers
Links Stripe customers to the accounts their metadata.user_id names:
python manage.py update_stripe_customers
python manage.py update_stripe_customers --limit 50
python manage.py update_stripe_customers --starting_after cus_abc123| Option | Default | Description |
|---|---|---|
-l, --limit | 100 | Max customers to fetch (max 100) |
-s, --starting_after | — | Pagination cursor (Stripe customer ID) |
What it does:
- Fetches customers from Stripe
- Creates or updates
StripeUserrecords for customers whosemetadata.user_idis an account here, which checkout sets - Skips every other customer. It never matches a customer to an account by email, and never creates accounts
update_stripe_subscriptions
Fetches subscriptions and updates local records:
python manage.py update_stripe_subscriptions
python manage.py update_stripe_subscriptions --limit 50
python manage.py update_stripe_subscriptions --starting_after sub_abc123| Option | Default | Description |
|---|---|---|
-l, --limit | 100 | Max subscriptions to fetch (max 100) |
-s, --starting_after | — | Pagination cursor (Stripe subscription ID) |
What it does:
- Fetches subscriptions from Stripe
- Creates/updates
Subscriptionrecords with all fields - Recreates
SubscriptionItemrecords from subscription line items - Links subscriptions to
StripeUserrecords
When to Use
| Scenario | Command |
|---|---|
| Initial deployment | sync_stripe_plans |
After changing plans.py | sync_stripe_plans |
| After restoring database | pull_stripe |
| Verify webhook data integrity | pull_stripe |
| Paginate through large customer lists | update_stripe_customers --limit 100 --starting_after cus_... |
| Debug subscription issues | update_stripe_subscriptions |
Docker Usage
# Local
docker compose -f docker-compose.local.yml run --rm django python manage.py pull_stripe
# Production
docker compose -f docker-compose.production.yml run --rm django python manage.py pull_stripe