Skip to content
Start here

Create Bucket

r2.buckets.create(BucketCreateParams**kwargs) -> Bucket
POST/accounts/{account_id}/r2/buckets

Creates an R2 bucket in the account and selected jurisdiction, with an optional location hint and default storage class.

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

Cloudflare account ID that owns the R2 resource.

maxLength32
name: str

Name of the bucket.

maxLength64
minLength3
location_hint: Optional[Literal["apac", "eeur", "enam", 3 more]]

Location of the bucket.

One of the following:
"apac"
"eeur"
"enam"
"weur"
"wnam"
"oc"
storage_class: Optional[Literal["Standard", "InfrequentAccess"]]

Storage class for newly uploaded objects, unless specified otherwise.

One of the following:
"Standard"
"InfrequentAccess"
cf_r2_jurisdiction: Optional[Literal["default", "eu", "us", 2 more]]
One of the following:
"default"
"eu"
"us"
"fedramp"
"fedramp-high"
ReturnsExpand Collapse
class Bucket: …

A single R2 bucket.

creation_date: Optional[str]

Creation timestamp.

jurisdiction: Optional[Literal["default", "eu", "us", 2 more]]

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

One of the following:
"default"
"eu"
"us"
"fedramp"
"fedramp-high"
location: Optional[Literal["apac", "eeur", "enam", 3 more]]

Location of the bucket.

One of the following:
"apac"
"eeur"
"enam"
"weur"
"wnam"
"oc"
name: Optional[str]

Name of the bucket.

maxLength64
minLength3
storage_class: Optional[Literal["Standard", "InfrequentAccess"]]

Storage class for newly uploaded objects, unless specified otherwise.

One of the following:
"Standard"
"InfrequentAccess"

Create Bucket

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_token=os.environ.get("CLOUDFLARE_API_TOKEN"),  # This is the default and can be omitted
)
bucket = client.r2.buckets.create(
    account_id="023e105f4ecef8ad9ca31a8372d0c353",
    name="example-bucket",
)
print(bucket.creation_date)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "creation_date": "creation_date",
    "jurisdiction": "default",
    "location": "apac",
    "name": "example-bucket",
    "storage_class": "Standard"
  },
  "success": true
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    "string"
  ],
  "result": {
    "creation_date": "creation_date",
    "jurisdiction": "default",
    "location": "apac",
    "name": "example-bucket",
    "storage_class": "Standard"
  },
  "success": true
}