Skip to content
Start here

Put Bucket Lock Rules

r2.buckets.locks.update(strbucket_name, LockUpdateParams**kwargs) -> object
PUT/accounts/{account_id}/r2/buckets/{bucket_name}/lock

Set lock 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
rules: Optional[Iterable[Rule]]
id: str

Unique identifier for this rule.

condition: RuleCondition

Condition to apply a lock rule to an object for how long in seconds.

One of the following:
class RuleConditionR2LockRuleAgeCondition:

Condition to apply a lock rule to an object for how long in seconds.

max_age_seconds: int
type: Literal["Age"]
class RuleConditionR2LockRuleDateCondition:

Condition to apply a lock rule to an object until a specific date.

date: Union[str, datetime]
formatdate-time
type: Literal["Date"]
class RuleConditionR2LockRuleIndefiniteCondition:

Condition to apply a lock rule indefinitely.

type: Literal["Indefinite"]
enabled: bool

Whether or not this rule is in effect.

prefix: Optional[str]

Rule 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.

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
object

Put Bucket Lock 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
)
lock = client.r2.buckets.locks.update(
    bucket_name="example-bucket",
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(lock)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {},
  "success": true
}