code: import stripe
  stripe.api_key = "sk_test_your_key"
  
  stripe.Subscription.modify(
    "sub_1JbiLB2eZvKYlo2CNHnqfMzf",
    metadata={"order_id": "6735"},
  )
  '''Response {
    "id": "sub_1JbiLB2eZvKYlo2CNHnqfMzf",
    "object": "subscription",
    "application": null,
    "application_fee_percent": null,
    "automatic_tax": {
      "enabled": false
    },
    "billing_cycle_anchor": 1633337949,
    "billing_thresholds": null,
    "cancel_at": null,
    "cancel_at_period_end": false,
    "canceled_at": null,
    "collection_method": "charge_automatically",
    "created": 1632128349,
    "currency": "usd",
    "current_period_end": 1660553949,
    "current_period_start": 1658739549,
    "customer": "cus_KGEouBKGmh7mXW",
    "days_until_due": null,
    "default_payment_method": "pm_1JbiL92eZvKYlo2CuiUB2nL1",
    "default_source": null,
    "default_tax_rates": [],
    "description": null,
    "discount": null,
    "ended_at": null,
    "items": {
      "object": "list",
      "data": [
        {
          "id": "si_KGEo6oKuLzcuYw",
          "object": "subscription_item",
          "billing_thresholds": null,
          "created": 1632128350,
          "metadata": {},
          "price": {
            "id": "15",
            "object": "price",
            "active": true,
            "billing_scheme": "per_unit",
            "created": 1386685951,
            "currency": "usd",
            "custom_unit_amount": null,
            "livemode": false,
            "lookup_key": null,
            "metadata": {
              "charset": "utf-8",
              "content": "15"
            },
            "nickname": null,
            "product": "prod_BTdpcRLIUTfsFR",
            "recurring": {
              "aggregate_usage": null,
              "interval": "week",
              "interval_count": 3,
              "usage_type": "licensed"
            },
            "tax_behavior": "unspecified",
            "tiers_mode": null,
            "transform_quantity": null,
            "type": "recurring",
            "unit_amount": 444,
            "unit_amount_decimal": "444"
          },
          "quantity": 1,
          "subscription": "sub_1JbiLB2eZvKYlo2CNHnqfMzf",
          "tax_rates": []
        }
      ],
      "has_more": false,
      "url": "/v1/subscription_items?subscription=sub_1JbiLB2eZvKYlo2CNHnqfMzf"
    },
    "latest_invoice": "in_1LPN8U2eZvKYlo2C2h002pSa",
    "livemode": false,
    "metadata": {
      "order_id": "6735"
    },
    "next_pending_invoice_item_invoice": null,
    "pause_collection": null,
    "payment_settings": {
      "payment_method_options": null,
      "payment_method_types": null,
      "save_default_payment_method": null
    },
    "pending_invoice_item_interval": null,
    "pending_setup_intent": null,
    "pending_update": null,
    "schedule": null,
    "start_date": 1632128349,
    "status": "active",
    "test_clock": null,
    "transfer_data": null,
    "trial_end": 1633337949,
    "trial_start": 1632128349
  }'''
nl: Update a subscriptionUpdates an existing subscription to match the specified parameters.
  When changing prices or quantities, we will optionally prorate the price we charge next month to make up for any price changes.
  To preview how the proration will be calculated, use the upcoming invoice endpoint.
  
    By default, we prorate subscription changes. For example, if a customer signs up on May 1 for a $100 price, she'll be billed $100 immediately. If on May 15 she switches to a $200 price, then on June 1 she'll be billed $250 ($200 for a renewal of her subscription, plus a $50 prorating adjustment for half of the previous month's $100 difference). Similarly, a downgrade will generate a credit to be applied to the next invoice. We also prorate when you make quantity changes.
  
  
    Switching prices does not normally change the billing date or generate an immediate charge unless:
  
  
  
  The billing interval is changed (e.g., monthly to yearly).
  The subscription moves from free to paid, or paid to free.
  A trial starts or ends.
  
  
  
    In these cases, we apply a credit for the time unused on the previous price and the customer is immediately charged using the new price. This also resets the billing date.
  
  
    If you'd like to charge for an upgrade immediately, just pass proration_behavior as create_prorations (the default), and then invoice the customer as soon as you make the subscription change. That will collect the proration adjustments into a new invoice, and Stripe will automatically attempt to collect payment on the invoice.
  
  
    If you don't want to prorate at all, set the proration_behavior option to none and the customer would be billed $100 on May 1 and $200 on June 1. Similarly, if you set proration_behavior to none when switching between different billing intervals (monthly to yearly, for example), we won't generate any credits for the old subscription's unused time—although we will still reset the billing date and will bill immediately for the new subscription.
  
  
    Updating the quantity on a subscription many times in an hour may result in rate limiting.  If you need to bill for a frequently changing quantity, consider integrating metered billing instead.
  
  Parameters cancel_at_period_end optional Boolean indicating whether this subscription should cancel at the end of the current period. default_payment_method optional ID of the default payment method for the subscription. It must belong to the customer associated with the subscription. This takes precedence over default_source. If neither are set, invoices will use the customer’s invoice_settings.default_payment_method or default_source. description optional The subscription’s description, meant to be displayable to the customer. Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces. items optional array of hashes A list of up to 20 subscription items, each with an attached price.Show child parameters metadata optional dictionary Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format. Individual keys can be unset by posting an empty value to them. All keys can be unset by posting an empty value to metadata. payment_behavior optional enum Use allow_incomplete to transition the subscription to status=past_due if a payment is required but cannot be paid. This allows you to manage scenarios where additional user actions are needed to pay a subscription’s invoice. For example, SCA regulation may require 3DS authentication to complete payment. See the SCA Migration Guide for Billing to learn more. This is the default behavior.
  Use default_incomplete to transition the subscription to status=past_due when payment is required and await explicit confirmation of the invoice’s payment intent. This allows simpler management of scenarios where additional user actions are needed to pay a subscription’s invoice. Such as failed payments, SCA regulation, or collecting a mandate for a bank debit payment method.
  Use pending_if_incomplete to update the subscription using pending updates. When you use pending_if_incomplete you can only pass the parameters supported by pending updates.
  Use error_if_incomplete if you want Stripe to return an HTTP 402 status code if a subscription’s invoice cannot be paid. For example, if a payment method requires 3DS authentication due to SCA regulation and further user action is needed, this parameter does not update the subscription and returns an error instead. This was the default behavior for API versions prior to 2019-03-14. See the changelog to learn more.Possible enum valuesallow_incomplete error_if_incomplete pending_if_incomplete default_incomplete  proration_behavior optional enum Determines how to handle prorations when the billing cycle changes (e.g., when switching plans, resetting billing_cycle_anchor=now, or starting a trial), or if an item’s quantity changes.Possible enum valuescreate_prorations Will cause proration invoice items to be created when applicable. These proration items will only be invoiced immediately under certain conditions.none Disable creating prorations in this request.always_invoice Always invoice immediately for prorations.More parametersExpand all  add_invoice_items optional array of hashes   application_fee_percent optional Connect only   automatic_tax optional dictionary   billing_cycle_anchor optional   billing_thresholds optional dictionary   cancel_at optional   collection_method optional   coupon optional   days_until_due optional   default_source optional   default_tax_rates optional   off_session optional   pause_collection optional dictionary   payment_settings optional dictionary   pending_invoice_item_interval optional dictionary   promotion_code optional   proration_date optional   transfer_data optional dictionary Connect only   trial_end optional   trial_from_plan optional Returns  The newly updated Subscription object, if the call succeeded.
  
  
    If payment_behavior is error_if_incomplete and a charge is required for the update and it fails, this call raises an error, and the subscription update does not go into effect.