Skip to content
Start here

Delete Object

r2.buckets.objects.delete(strobject_key, ObjectDeleteParams**kwargs) -> ObjectDeleteResponse
DELETE/accounts/{account_id}/r2/buckets/{bucket_name}/objects/{object_key}

Deletes an object from an R2 bucket.

For most workloads, we recommend using R2’s S3-compatible API or a Worker with an R2 binding instead.

Security

API Token

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

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
Accepted Permissions (at least one required)
Workers R2 Storage Write
ParametersExpand Collapse
account_id: str

Account ID.

maxLength32
bucket_name: str

Name of the bucket.

maxLength64
minLength3
object_key: str

The key (name) of the object to delete. May contain slashes for path-like keys. Slashes (/) within the key MUST be sent literally and MUST NOT be percent-encoded (i.e. %2F); other reserved characters should be percent-encoded as usual.

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 ObjectDeleteResponse:

Result of a successful object deletion.

key: Optional[str]

The key (name) of the deleted object.

Delete Object

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
object = client.r2.buckets.objects.delete(
    object_key="path/to/my-object.txt",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    bucket_name="example-bucket",
)
print(object.key)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "key": "path/to/my-object.txt"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "key": "path/to/my-object.txt"
  },
  "success": true
}