A bucket is a container for storing objects in Object Storage Service (OSS). This topic shows how to create a bucket using the OSS SDK for Python V1.
Usage notes
The examples use the China (Hangzhou) region (
cn-hangzhou) and a public endpoint. To access OSS from other Alibaba Cloud products in the same region, use the internal endpoint instead. For endpoint mappings by region, see Regions and endpoints.Starting October 13, 2025, 10:00 (UTC+8), OSS enables Block Public Access by default for new buckets created through the API, OSS SDKs, or ossutil. The rollout is phased across regions — see [Official Announcement] Adjustment to public access blocking configurations for newly created buckets for the schedule. When Block Public Access is enabled, you cannot set public ACLs (public read or public read/write) or bucket policies that allow public access. Disable this feature after bucket creation if your use case requires public access.
Prerequisites
Before you begin, ensure that you have:
Installed the OSS SDK for Python V1 (
oss2)A Resource Access Management (RAM) user created for API access or routine O&M, and its AccessKey ID and AccessKey Secret
An Alibaba Cloud account AccessKey has full permissions for all API operations, which poses a security risk. Use a RAM user's AccessKey for API access instead. To create a RAM user, log in to the RAM console.
Create a bucket
The following example creates a bucket named examplebucket with default settings.
# -*- coding: utf-8 -*-
import oss2
# An Alibaba Cloud account AccessKey has full permissions for all API operations, which poses a security risk.
# Use a RAM user's AccessKey for API access or routine O&M. To create a RAM user, log in to the RAM console.
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
# Endpoint format: https://oss-{region-id}.aliyuncs.com
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
# Create the bucket.
bucket.create_bucket()Create a bucket with custom settings
To specify the storage class, ACL (Access Control List), or data redundancy type at creation time, pass a BucketCreateConfig object.
The following example creates a bucket with Standard storage, private ACL, and zone-redundant storage (ZRS).
# -*- coding: utf-8 -*-
import oss2
auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret')
bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'examplebucket')
bucket_config = oss2.models.BucketCreateConfig(
oss2.BUCKET_STORAGE_CLASS_STANDARD,
oss2.BUCKET_DATA_REDUNDANCY_TYPE_ZRS
)
bucket.create_bucket(oss2.BUCKET_ACL_PRIVATE, bucket_config)The supported values for each parameter are:
| Parameter | Constant | Value |
|---|---|---|
| Storage class | oss2.BUCKET_STORAGE_CLASS_STANDARD | Standard |
| ACL | oss2.BUCKET_ACL_PRIVATE | private |
| Data redundancy type | oss2.BUCKET_DATA_REDUNDANCY_TYPE_ZRS | Zone-redundant storage (ZRS) |
What's next
For the complete sample code, see the GitHub example.
For the underlying API operation, see PutBucket.