Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.pyc
.settings
.coverage
.pydevproject
.vscode/
.idea
.DS_Store
dist
build
*egg-info
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ChangeLog - Alibaba Cloud OSS SDK for Python v2
Empty file added DEVGUIDE.md
Empty file.
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include LICENSE
include README.md
include CHANGELOG.md
144 changes: 144 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# Alibaba Cloud OSS SDK for Python v2

[![GitHub version](https://badge.fury.io/gh/aliyun%2Falibabacloud-oss-python-sdk-v2.svg)](https://badge.fury.io/gh/aliyun%2Falibabacloud-oss-python-sdk-v2)

alibabacloud-oss-python-sdk-v2 is the Developer Preview for the v2 of the OSS SDK for the Python programming language

## [README in Chinese](README-CN.md)

## About
> - This Python SDK is based on the official APIs of [Alibaba Cloud OSS](http://www.aliyun.com/product/oss/).
> - Alibaba Cloud Object Storage Service (OSS) is a cloud storage service provided by Alibaba Cloud, featuring massive capacity, security, a low cost, and high reliability.
> - The OSS can store any type of files and therefore applies to various websites, development enterprises and developers.
> - With this SDK, you can upload, download and manage data on any app anytime and anywhere conveniently.

## Running Environment
> - Python 3.8 or above.

## Installing
### Install the official release version through pip
```bash
$ pip install alibabacloud-oss-v2
```

### Install from the unzipped installer package directly
```bash
$ sudo python setup.py install
```

## Getting Started
#### List Bucket
```python
import alibabacloud_oss_v2 as oss

def main():

region = "cn-hangzhou"

# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region

client = oss.Client(cfg)

# Create the Paginator for the ListBuckets operation
paginator = client.list_buckets_paginator()

# Iterate through the bucket pages
for page in paginator.iter_page(oss.ListBucketsRequest(
)
):
for o in page.buckets:
print(f'Bucket: {o.name}, {o.location}, {o.creation_date} {o.resource_group_id}')

if __name__ == "__main__":
main()

```

#### List Objects
```python
import alibabacloud_oss_v2 as oss

def main():

region = "cn-hangzhou"
bucket_name = "your bucket name"

# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region

client = oss.Client(cfg)

# Create the Paginator for the ListObjectsV2 operation
paginator = client.list_objects_v2_paginator()

# Iterate through the object pages
for page in paginator.iter_page(oss.ListObjectsV2Request(
bucket=bucket_name
)
):
for o in page.contents:
print(f'Object: {o.key}, {o.size}, {o.last_modified}')

if __name__ == "__main__":
main()

```

#### Put Object
```python
import alibabacloud_oss_v2 as oss

def main():

region = "cn-hangzhou"
bucket_name = "your bucket name"
object_name = "your object name"
local_file = "your local file path"

# Loading credentials values from the environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

# Using the SDK's default configuration
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = region


client = oss.Client(cfg)

with open(local_file, 'rb') as f:
result = client.put_object(oss.PutObjectRequest(
bucket=bucket_name,
key=object_name,
body=f,
))

print(f'put object sucessfully, ETag {result.etag}')


if __name__ == "__main__":
main()

```

## Complete Example
More example projects can be found in the `sample` folder

### Running Example
> - Go to the sample code folder `sample`。
> - Configure credentials values from the environment variables, like `export OSS_ACCESS_KEY_ID="your access key id"`, `export OSS_ACCESS_KEY_SECRET="your access key secrect"`
> - Take list_buckets.python as an example,run `python list_buckets.python -region cn-hangzhou` command。

## License
> - Apache-2.0, see [license file](LICENSE)
56 changes: 56 additions & 0 deletions alibabacloud_oss_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from .types import *

# sub mod
from . import credentials
from . import retry
from . import signer
from . import transport
from . import models
from . import exceptions
from . import crypto
from . import checkpoint

# all types in models
from .models.enums import *
from .models.service import *
from .models.region import *
from .models.bucket_basic import *
from .models.object_basic import *

from .config import Config
from .client import Client
from .encryption_client import EncryptionClient, EncryptionMultiPartContext

from .downloader import (
Downloader,
DownloadResult,
DownloadError,
)

from .uploader import (
Uploader,
UploadResult,
UploadError
)

from .paginator import (
ListObjectsPaginator,
ListObjectsV2Paginator,
ListObjectVersionsPaginator,
ListBucketsPaginator,
ListPartsPaginator,
ListMultipartUploadsPaginator
)

from .filelike import (
AppendOnlyFile,
ReadOnlyFile,
PathError
)

from .io_utils import (
StreamBodyDiscarder
)

from ._version import VERSION
__version__ = VERSION
Loading