Skip to main content

A boto3-compatible SDK for CTyun Object Storage (ZOS) with httpx backend

Project description

CTyun ZOS SDK

Python Version License PyPI

A boto3-compatible SDK for CTyun Object Storage (ZOS) with httpx backend. This SDK provides both synchronous and asynchronous interfaces for interacting with CTyun's S3-compatible object storage service.

Features

  • boto3-compatible API: Familiar interface for developers already using AWS S3
  • Dual interfaces: Both synchronous and asynchronous clients
  • httpx backend: Modern HTTP client with better performance and features
  • CTyun-specific optimizations: Handles CTyun ZOS service requirements
  • Proper signing: AWS SigV4 authentication with CTyun-specific header handling
  • Type hints: Full type annotations for better development experience

Installation

From PyPI (recommended)

pip install ctyun-zos-sdk

From source

git clone https://github.com/your-org/ctyun-zos-sdk.git
cd ctyun-zos-sdk
pip install -e .

Quick Start

Basic Usage

import os
from ctyun_zos_sdk import ZOSSession

# Create a session
session = ZOSSession(
    aws_access_key_id=os.environ["S3_ACCESS_KEY"],
    aws_secret_access_key=os.environ["S3_SECRET_KEY"],
    region_name="huabei-2",
    endpoint_url="https://huabei-2.zos.ctyun.cn"
)

# Get S3 client
s3_client = session.client('s3')

# Upload a file
response = s3_client.put_object(
    Bucket="your-bucket",
    Key="example/test.txt",
    Body="Hello, CTyun ZOS!",
    ContentType="text/plain"
)
print(f"Upload successful! ETag: {response['ETag']}")

# Download a file
response = s3_client.get_object(
    Bucket="your-bucket",
    Key="example/test.txt"
)
print(f"Content: {response['Body'].decode('utf-8')}")

Asynchronous Usage

import asyncio
import os
from ctyun_zos_sdk import AsyncZOSClient

async def main():
    async with AsyncZOSClient(
        access_key=os.environ["S3_ACCESS_KEY"],
        secret_key=os.environ["S3_SECRET_KEY"],
        region="huabei-2",
        endpoint="https://huabei-2.zos.ctyun.cn"
    ) as client:
        
        # Upload file asynchronously
        response = await client.put_object(
            Bucket="your-bucket",
            Key="async-test.txt",
            Body="Async upload content"
        )
        print(f"Upload successful! ETag: {response['ETag']}")

# Run the async function
asyncio.run(main())

Direct Client Usage

from ctyun_zos_sdk import ZOSClient

# Create client directly
client = ZOSClient(
    access_key="your_access_key",
    secret_key="your_secret_key",
    region="huabei-2",
    endpoint="https://huabei-2.zos.ctyun.cn"
)

# Use context manager for automatic cleanup
with client:
    response = client.put_object(
        Bucket="your-bucket",
        Key="direct-test.txt",
        Body="Direct client usage"
    )
    print(f"Upload successful! ETag: {response['ETag']}")

Configuration

Environment Variables

You can configure the SDK using environment variables:

export S3_ACCESS_KEY="your_access_key"
export S3_SECRET_KEY="your_secret_key"
export S3_REGION="huabei-2"
export S3_ENDPOINT="https://huabei-2.zos.ctyun.cn"

Supported Regions

  • huabei-2 - 华北2
  • huadong-1 - 华东1
  • huadong-2 - 华东2
  • huanan-1 - 华南1
  • huanan-2 - 华南2

API Reference

ZOSSession

The main session class for managing configuration and creating clients.

session = ZOSSession(
    aws_access_key_id="your_key",
    aws_secret_access_key="your_secret",
    region_name="huabei-2",
    endpoint_url="https://huabei-2.zos.ctyun.cn"
)

# Create S3 client
s3_client = session.client('s3')

ZOSClient

Synchronous client for S3 operations.

Methods

  • get_object(Bucket, Key, **kwargs) - Download an object
  • put_object(Bucket, Key, Body, **kwargs) - Upload an object
  • delete_object(Bucket, Key, **kwargs) - Delete an object
  • list_objects_v2(Bucket, Prefix="", **kwargs) - List objects in a bucket

Parameters

  • Bucket (str): Bucket name
  • Key (str): Object key
  • Body (str/bytes/file): Object content for uploads
  • ContentType (str): MIME type of the object
  • Metadata (dict): Custom metadata for the object

AsyncZOSClient

Asynchronous client with the same interface as ZOSClient.

async with AsyncZOSClient(...) as client:
    response = await client.put_object(...)
    response = await client.get_object(...)

Examples

See the examples/ directory for more detailed examples:

  • examples/basic_usage.py - Basic synchronous operations
  • examples/async_usage.py - Asynchronous operations and concurrency

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/your-org/ctyun-zos-sdk.git
cd ctyun-zos-sdk

# Install development dependencies
make install-dev

# Install package in development mode
make dev-install

Running Tests

# Run all tests
make test

# Run tests with coverage
make test-cov

# Run linting checks
make lint

# Format code
make format

Building and Publishing

# Build package
make build

# Check package metadata
make check

# Upload to test PyPI
make upload-test

# Upload to PyPI
make upload

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Ensure all tests pass
  6. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Based on the verified examples in the verified/ directory
  • Uses boto3's authentication and signing mechanisms
  • Built with httpx for modern HTTP client capabilities

Support

For issues and questions:

  • Create an issue on GitHub
  • Check the examples in the examples/ directory
  • Review the verified examples in the verified/ directory

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ctyun_zos_sdk-0.2.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ctyun_zos_sdk-0.2.1-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file ctyun_zos_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: ctyun_zos_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for ctyun_zos_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b20a24d02f709765217dffa199a0468d1edf4d3adbaf2a1bb49c7fb5b2251c7f
MD5 e62c60444246fb7e79319203add2919e
BLAKE2b-256 d5e4542b005e9247ac98b55089b928c82b7497d1613f5a63fe5eec5388225ab9

See more details on using hashes here.

File details

Details for the file ctyun_zos_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ctyun_zos_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for ctyun_zos_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5f9d8ac52e6c7394ae19b4d9aa591f64c99f6a26bf70b48eefb153cfcd3986f
MD5 1e3c0aa6a9a35d8ca5f2f634033a979c
BLAKE2b-256 a96a202762622b92187a6c99ae87099be51f24ae60dcd1755514ac3b4621ed4f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page