---
title: "💭 Cancel subscriptions | Stripe Documentation"
description: "!https://stripe.com/docs/billing/subscriptions/cancel#canceling"
date: 2023-12-10
published: true
tags:
  - webdev
  - stripe
  - thought
template: link
---


<div class="embed-card embed-card-external">
  <a href="https://stripe.com/docs/billing/subscriptions/cancel#canceling" class="embed-card-link" target="_blank" rel="noopener noreferrer">
    <div class="embed-card-image">
      <img src="https://d37ugbyn3rpeym.cloudfront.net/docs/og-image/billing.subscriptions.cancel.ogimage.png" alt="Cancel subscriptions — Cancel subscriptions immediately or at the end of the subscription period with proration options, invoice handling, and automatic cancellation after failed payment attempts." loading="lazy">
    </div>
    <div class="embed-card-content">
      <div class="embed-card-title">Cancel subscriptions</div>
      <div class="embed-card-description">Cancel subscriptions immediately or at the end of the subscription period with proration options, invoice handling, and automatic cancellation after failed payment attempts.</div>
      <div class="embed-card-meta">stripe.com</div>
    </div>
  </a>
</div>


This is a handy guide to cancelling stripe subscriptions.

``` python
# Set your secret key. Remember to switch to your live secret key in production.
# See your keys here: https://dashboard.stripe.com/apikeys
import stripe
stripe.api_key = "sk_test_51ODvHtB26msLKqCAPBAo1qkBBuIfT5tQBX6YFWCLMsPixIExxITCRVa9tNCIqkdQS8olhR79NYXsFWBPKsM3LbGO00zEcNQfNI"

stripe.Subscription.modify(
  "sub_49ty4767H20z6a",
  cancel_at_period_end=True,
)
```

You can even inverse it by flipping `True` to `False` and re activate the subscription.

!!! note

    This post is a <a href="/thoughts/" class="wikilink" data-title="Thoughts" data-description="These are generally my thoughts on a web page or some sort of url, except a rare few don&#39;t have a link. These are dual published off of my..." data-date="2024-04-01">thought</a>. It's a short note that I make
    about someone else's content online <a href="/tags/thoughts/" class="hashtag-tag" data-tag="thoughts" data-count=2 data-reading-time=3 data-reading-time-text="3 minutes">#thoughts</a>
