Skip to content
Start here

Get Object Lifecycle Rules

r2.buckets.lifecycle.get(strbucket_name, LifecycleGetParams**kwargs) -> LifecycleGetResponse
GET/accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle

Get object lifecycle rules for a bucket.

Security

API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
ParametersExpand Collapse
account_id: str

Account ID.

maxLength32
bucket_name: str

Name of the bucket.

maxLength64
minLength3
jurisdiction: Optional[Literal["default", "eu", "fedramp"]]

Jurisdiction where objects in this bucket are guaranteed to be stored.

One of the following:
"default"
"eu"
"fedramp"
ReturnsExpand Collapse
class LifecycleGetResponse:
rules: Optional[List[Rule]]
id: str

Unique identifier for this rule.

conditions: RuleConditions

Conditions that apply to all transitions of this rule.

prefix: str

Transitions will only apply to objects/uploads in the bucket that start with the given prefix, an empty prefix can be provided to scope rule to all objects/uploads.

enabled: bool

Whether or not this rule is in effect.

abort_multipart_uploads_transition: Optional[RuleAbortMultipartUploadsTransition]

Transition to abort ongoing multipart uploads.

condition: Optional[RuleAbortMultipartUploadsTransitionCondition]

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

max_age: int
type: Literal["Age"]
delete_objects_transition: Optional[RuleDeleteObjectsTransition]

Transition to delete objects.

condition: Optional[RuleDeleteObjectsTransitionCondition]

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
class RuleDeleteObjectsTransitionConditionR2LifecycleAgeCondition:

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

max_age: int
type: Literal["Age"]
class RuleDeleteObjectsTransitionConditionR2LifecycleDateCondition:

Condition for lifecycle transitions to apply on a specific date.

date: datetime
formatdate-time
type: Literal["Date"]
storage_class_transitions: Optional[List[RuleStorageClassTransition]]

Transitions to change the storage class of objects.

condition: RuleStorageClassTransitionCondition

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

One of the following:
class RuleStorageClassTransitionConditionR2LifecycleAgeCondition:

Condition for lifecycle transitions to apply after an object reaches an age in seconds.

max_age: int
type: Literal["Age"]
class RuleStorageClassTransitionConditionR2LifecycleDateCondition:

Condition for lifecycle transitions to apply on a specific date.

date: datetime
formatdate-time
type: Literal["Date"]
storage_class: Literal["InfrequentAccess"]

Get Object Lifecycle Rules

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
lifecycle = client.r2.buckets.lifecycle.get(
    bucket_name="example-bucket",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(lifecycle.rules)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "rules": [
      {
        "id": "Expire all objects older than 24 hours",
        "conditions": {
          "prefix": "prefix"
        },
        "enabled": true,
        "abortMultipartUploadsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "deleteObjectsTransition": {
          "condition": {
            "maxAge": 0,
            "type": "Age"
          }
        },
        "storageClassTransitions": [
          {
            "condition": {
              "maxAge": 0,
              "type": "Age"
            },
            "storageClass": "InfrequentAccess"
          }
        ]
      }
    ]
  },
  "success": true
}