# Locks ## Get Bucket Lock Rules `r2.buckets.locks.get(strbucket_name, LockGetParams**kwargs) -> LockGetResponse` **get** `/accounts/{account_id}/r2/buckets/{bucket_name}/lock` Get lock rules for a bucket. ### Parameters - `account_id: str` Account ID. - `bucket_name: str` Name of the bucket. - `jurisdiction: Optional[Literal["default", "eu", "fedramp"]]` Jurisdiction where objects in this bucket are guaranteed to be stored. - `"default"` - `"eu"` - `"fedramp"` ### Returns - `class LockGetResponse: …` - `rules: Optional[List[Rule]]` - `id: str` Unique identifier for this rule. - `condition: RuleCondition` Condition to apply a lock rule to an object for how long in seconds. - `class RuleConditionR2LockRuleAgeCondition: …` Condition to apply a lock rule to an object for how long in seconds. - `max_age_seconds: int` - `type: Literal["Age"]` - `"Age"` - `class RuleConditionR2LockRuleDateCondition: …` Condition to apply a lock rule to an object until a specific date. - `date: datetime` - `type: Literal["Date"]` - `"Date"` - `class RuleConditionR2LockRuleIndefiniteCondition: …` Condition to apply a lock rule indefinitely. - `type: Literal["Indefinite"]` - `"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. ### Example ```python 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.get( bucket_name="example-bucket", account_id="023e105f4ecef8ad9ca31a8372d0c353", ) print(lock.rules) ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": { "rules": [ { "id": "Lock all objects for 24 hours", "condition": { "maxAgeSeconds": 100, "type": "Age" }, "enabled": true, "prefix": "prefix" } ] }, "success": true } ``` ## 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. ### Parameters - `account_id: str` Account ID. - `bucket_name: str` Name of the bucket. - `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. - `class RuleConditionR2LockRuleAgeCondition: …` Condition to apply a lock rule to an object for how long in seconds. - `max_age_seconds: int` - `type: Literal["Age"]` - `"Age"` - `class RuleConditionR2LockRuleDateCondition: …` Condition to apply a lock rule to an object until a specific date. - `date: Union[str, datetime]` - `type: Literal["Date"]` - `"Date"` - `class RuleConditionR2LockRuleIndefiniteCondition: …` Condition to apply a lock rule indefinitely. - `type: Literal["Indefinite"]` - `"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. - `"default"` - `"eu"` - `"fedramp"` ### Returns - `object` ### Example ```python 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) ``` #### Response ```json { "errors": [ { "code": 1000, "message": "message", "documentation_url": "documentation_url", "source": { "pointer": "pointer" } } ], "messages": [ "string" ], "result": {}, "success": true } ``` ## Domain Types ### Lock Get Response - `class LockGetResponse: …` - `rules: Optional[List[Rule]]` - `id: str` Unique identifier for this rule. - `condition: RuleCondition` Condition to apply a lock rule to an object for how long in seconds. - `class RuleConditionR2LockRuleAgeCondition: …` Condition to apply a lock rule to an object for how long in seconds. - `max_age_seconds: int` - `type: Literal["Age"]` - `"Age"` - `class RuleConditionR2LockRuleDateCondition: …` Condition to apply a lock rule to an object until a specific date. - `date: datetime` - `type: Literal["Date"]` - `"Date"` - `class RuleConditionR2LockRuleIndefiniteCondition: …` Condition to apply a lock rule indefinitely. - `type: Literal["Indefinite"]` - `"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.