Command line interface for Tencent Cloud Object Storage
Project description
Tencent COS CLI
A powerful command-line interface for Tencent Cloud Object Storage (COS), designed with a similar experience to AWS CLI.
Features
- 🚀 Easy to Use: Intuitive commands similar to AWS CLI
- 🔐 Secure: Support for STS temporary credentials and role assumption
- ⚡ Fast: Multipart uploads and parallel transfers
- 🎨 Beautiful: Rich progress bars and formatted output
- 🔧 Flexible: Multiple profiles, regions, and output formats
- 📦 Complete: Upload, download, sync, and manage buckets
Installation
From PyPI (Recommended)
pip install tencent-cos-cli
That's it! The cos command will be available in your PATH.
From Source (Development)
Quick Install (with new venv)
git clone https://github.com/sszhu/coscli.git
cd coscli
./install.sh
This will:
- Install
uv(if not present) - Create a virtual environment
- Install COS CLI and dependencies
Then activate:
source .venv/bin/activate
Install in Current Environment
If you're already in a conda environment or existing venv:
./install.sh --current
This installs COS CLI in your current Python environment without creating a new venv
Manual Installation
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create venv and install
uv venv
source .venv/bin/activate
uv pip install -e .
Requirements
- Python 3.8+
- uv package manager
- Tencent Cloud Account with COS access
Troubleshooting Installation
If you encounter SSL certificate errors during installation (common in corporate networks):
# The install.sh script handles this automatically, but if needed:
curl -LsSfk https://astral.sh/uv/install.sh | sh
SSL Certificate Issues?
# Run diagnostic tool to identify the issue
python -m cos.tools.diagnose_ssl
📖 More details:
- docs/UV_GUIDE.md
- docs/SSL_TROUBLESHOOTING.md - Comprehensive SSL troubleshooting
Quick Start
1. Configure Credentials
Run the interactive configuration:
cos configure
You'll be prompted for:
- Secret ID: Your Tencent Cloud secret ID
- Secret Key: Your Tencent Cloud secret key
- Assume Role ARN: (Optional) Role to assume
- Default Region: Default region (e.g., ap-shanghai)
- Default Bucket: (Optional) Default bucket name
- Default Prefix: (Optional) Default prefix
- Output Format: json, table, or text
Generate Temporary Credentials
For testing or temporary access:
# Generate 2-hour temporary token
cos token
# Use environment variables
cos token --output env > temp_creds.sh
source temp_creds.sh
📖 More details: docs/TOKEN_MANAGEMENT.md
2. Basic Commands
List Buckets
cos ls
List Objects in Bucket
cos ls cos://my-bucket/
cos ls cos://my-bucket/folder/ --recursive
Upload Files
# Upload single file
cos cp local-file.txt cos://my-bucket/remote-file.txt
# Upload directory
cos cp ./local-dir/ cos://my-bucket/remote-dir/ --recursive
Download Files
# Download single file
cos cp cos://my-bucket/file.txt ./local-file.txt
# Download directory
cos cp cos://my-bucket/folder/ ./local-folder/ --recursive
Copy Between Buckets
cos cp cos://bucket1/file.txt cos://bucket2/file.txt
Delete Objects
# Delete single object
cos rm cos://my-bucket/file.txt
# Delete multiple objects
cos rm cos://my-bucket/folder/ --recursive
Move/Rename Objects
# Rename object
cos mv cos://bucket/old-name.txt cos://bucket/new-name.txt
# Move directory
cos mv cos://bucket/old-folder/ cos://bucket/new-folder/ --recursive
# Move between buckets
cos mv cos://bucket1/file.txt cos://bucket2/file.txt
Synchronize Directories
# Sync local to COS (upload)
cos sync ./local-dir/ cos://bucket/remote-dir/
# Sync COS to local (download)
cos sync cos://bucket/remote-dir/ ./local-dir/
# Sync with delete (exact mirror)
cos sync ./local-dir/ cos://bucket/remote-dir/ --delete
# Preview sync without making changes
cos sync ./local-dir/ cos://bucket/remote-dir/ --dryrun
# Fast sync (compare by size only)
cos sync ./local-dir/ cos://bucket/remote-dir/ --size-only
Generate Presigned URLs
# Generate URL for download (default 1 hour)
cos presign cos://bucket/file.txt
# Custom expiration (2 hours)
cos presign cos://bucket/file.txt --expires-in 7200
# Generate upload URL
cos presign cos://bucket/file.txt --method PUT
# Generate short-lived URL (5 minutes)
cos presign cos://bucket/file.txt -e 300
Create/Delete Buckets
# Create bucket
cos mb cos://my-new-bucket
# Delete bucket
cos rb cos://my-bucket
# Delete bucket with all contents
cos rb cos://my-bucket --force
Advanced Usage
Multiple Profiles
Configure multiple profiles for different accounts or environments:
# Configure production profile
cos configure --profile production
# Use production profile
cos ls --profile production
# Set profile in environment
export COS_PROFILE=production
cos ls
Output Formats
Choose from three output formats:
# Table format (default)
cos ls cos://bucket/ --output table
# JSON format
cos ls cos://bucket/ --output json
# Text format (for scripting)
cos ls cos://bucket/ --output text
Region Override
# Override default region
cos ls cos://bucket/ --region ap-beijing
# Set region in environment
export COS_REGION=ap-beijing
Filtering
# Include specific patterns
cos cp ./dir/ cos://bucket/ --recursive --include "*.txt"
# Exclude specific patterns
cos cp ./dir/ cos://bucket/ --recursive --exclude "*.log"
Progress Control
# Disable progress bars
cos cp large-file.iso cos://bucket/ --no-progress
# Quiet mode
cos cp file.txt cos://bucket/ --quiet
Configuration
Configuration Files
Configuration is stored in ~/.cos/:
~/.cos/
├── config # Configuration settings
└── credentials # Credentials (secret keys)
Configuration File Format
~/.cos/config:
[default]
region = ap-shanghai
output = json
[profile production]
region = ap-beijing
output = table
Credentials File Format
~/.cos/credentials:
[default]
secret_id = AKIDxxxxx
secret_key = xxxxxxxxx
assume_role = qcs::cam::uin/xxx:roleName/xxx
[profile production]
secret_id = AKIDxxxxx
secret_key = xxxxxxxxx
Environment Variables
Override configuration with environment variables:
export COS_SECRET_ID=AKIDxxxxx
export COS_SECRET_KEY=xxxxxxxxx
export COS_REGION=ap-shanghai
export COS_ASSUME_ROLE=qcs::cam::uin/xxx:roleName/xxx
export COS_OUTPUT=json
export COS_PROFILE=production
Command Reference
Global Options
--profile TEXT Use specific profile
--region TEXT Override default region
--output [json|table|text] Output format
--endpoint-url TEXT Custom endpoint URL
--no-verify-ssl Skip SSL verification
--debug Enable debug mode
--quiet Suppress output
Commands
| Command | Description |
|---|---|
configure |
Configure COS CLI settings |
ls |
List buckets or objects |
cp |
Copy files to/from/within COS |
mv |
Move or rename objects |
sync |
Synchronize directories between local and COS |
rm |
Remove objects |
mb |
Make (create) bucket |
rb |
Remove bucket |
presign |
Generate presigned URLs for temporary access |
token |
Generate temporary STS credentials |
lifecycle |
Manage bucket lifecycle policies |
policy |
Manage bucket access policies |
cors |
Configure CORS settings |
versioning |
Manage bucket versioning |
Advanced Commands
Bucket Lifecycle Management
Control automatic transitions and expiration of objects:
# View lifecycle rules
cos lifecycle get cos://my-bucket
# Set lifecycle rules from JSON file
cos lifecycle put cos://my-bucket --config lifecycle.json
# Delete lifecycle configuration
cos lifecycle delete cos://my-bucket
Example lifecycle.json:
{
"Rule": [
{
"ID": "Delete old logs",
"Status": "Enabled",
"Filter": {"Prefix": "logs/"},
"Expiration": {"Days": 30}
},
{
"ID": "Archive to ARCHIVE",
"Status": "Enabled",
"Filter": {"Prefix": "archive/"},
"Transition": {
"Days": 90,
"StorageClass": "ARCHIVE"
}
}
]
}
Bucket Policy Management
Control access permissions at bucket level:
# View current policy
cos policy get cos://my-bucket
# Set policy from JSON file
cos policy put cos://my-bucket --policy policy.json
# Delete policy
cos policy delete cos://my-bucket
Example policy.json:
{
"version": "2.0",
"Statement": [
{
"Effect": "Allow",
"Principal": {"qcs": ["qcs::cam::uin/100000000001:uin/100000000001"]},
"Action": ["name/cos:GetObject"],
"Resource": ["qcs::cos:ap-shanghai:uid/1250000000:my-bucket/*"]
}
]
}
CORS Configuration
Configure Cross-Origin Resource Sharing:
# View CORS rules
cos cors get cos://my-bucket
# Set CORS rules from JSON file
cos cors put cos://my-bucket --config cors.json
# Delete CORS configuration
cos cors delete cos://my-bucket
Example cors.json:
{
"CORSRule": [
{
"ID": "Allow all origins",
"AllowedOrigin": ["*"],
"AllowedMethod": ["GET", "PUT", "POST", "DELETE", "HEAD"],
"AllowedHeader": ["*"],
"ExposeHeader": ["ETag", "Content-Length"],
"MaxAgeSeconds": 3600
}
]
}
Bucket Versioning
Enable object versioning for protection:
# Check versioning status
cos versioning get cos://my-bucket
# Enable versioning
cos versioning enable cos://my-bucket
# Suspend versioning
cos versioning suspend cos://my-bucket
Pattern Matching
Filter files during transfer operations:
# Upload only Python files
cos cp ./project/ cos://bucket/code/ -r --include "*.py"
# Upload all except tests
cos cp ./project/ cos://bucket/code/ -r --exclude "test_*"
# Complex patterns: include source files, exclude tests and cache
cos cp ./project/ cos://bucket/backup/ -r \
--include "*.py" --include "*.js" \
--exclude "test_*" --exclude "__pycache__"
# Download only log files
cos cp cos://bucket/logs/ ./local-logs/ -r --include "*.log"
Checksum Verification
Ensure data integrity with MD5 checksums:
# Sync with checksum verification
cos sync ./local/ cos://bucket/remote/ --checksum
# Even if timestamps differ, skip files with matching checksums
cos sync ./local/ cos://bucket/remote/ --checksum --size-only
Examples
Backup Local Directory to COS
cos cp ./my-data/ cos://my-backup-bucket/$(date +%Y%m%d)/ --recursive
Download Latest Files
cos ls cos://bucket/logs/ --output text | tail -5 | while read file; do
cos cp cos://bucket/$file ./
done
Sync Directory
# Upload only changed files
cos sync ./local-dir/ cos://bucket/backup/ --size-only
# Exact mirror (delete files not in source)
cos sync ./local-dir/ cos://bucket/backup/ --delete
Share Files with Presigned URLs
# Generate a download link valid for 24 hours
cos presign cos://bucket/document.pdf --expires-in 86400
# Share via curl
URL=$(cos presign cos://bucket/file.txt)
echo "Download: $URL"
Bulk Delete Old Files
cos ls cos://bucket/archive/ --output text | while read file; do
cos rm cos://bucket/$file
done
Troubleshooting
Authentication Errors
If you get authentication errors:
- Verify credentials:
cos configure list - Check credential file permissions:
ls -la ~/.cos/ - Try with debug mode:
cos ls --debug
SSL Verification Errors
If you encounter SSL errors:
cos ls --no-verify-ssl
Large File Uploads
For files larger than 5MB, multipart upload is automatic. For very large files:
- Ensure stable network connection
- Use
--no-progressfor background operations - Check available disk space
Development
Running Tests
pytest tests/
Code Style
black cos/
flake8 cos/
mypy cos/
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new features
- Submit a pull request
License
MIT License - see LICENSE file for details
Documentation
- Quick Reference: docs/QUICK_REFERENCE.md
- Development Plan: docs/COS_CLI_DEVELOPMENT_PLAN.md
- Implementation Summary (v1.1.0): docs/IMPLEMENTATION_SUMMARY.md
- Implementation Complete (v2.0.0): docs/IMPLEMENTATION_COMPLETE_V2.md
- Final Verification Report: docs/VERIFICATION_COMPLETE.md
- Release Notes (v2.0.0): docs/RELEASE_NOTES_2.0.0.md
- Full Index: docs/INDEX.md
Changelog
See CHANGELOG.md for version history.
License
This project is licensed under the MIT License - see the LICENSE file for details.
What This Means
✅ You can:
- Use this software for commercial purposes
- Modify and distribute the software
- Use it privately
- Sublicense it
⚠️ You must:
- Include the original copyright notice
- Include the MIT License text
❌ Limitations:
- No warranty provided
- Authors are not liable for any claims
Credits
Built with:
- uv - Ultra-fast package installer
- Click - CLI framework
- Rich - Beautiful terminal output
- Tencent Cloud SDK - Official SDK
Author
Shanshan Zhu
Contributions are welcome! Please feel free to submit a Pull Request.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tencent_cos_cli-2.0.1.tar.gz.
File metadata
- Download URL: tencent_cos_cli-2.0.1.tar.gz
- Upload date:
- Size: 465.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b4f6c422bc4537e684510186f0ccc2aa2803d899200d8d753ff537e65a1a18c7
|
|
| MD5 |
03e58bfb0f75ec470ef46a3cf12f2014
|
|
| BLAKE2b-256 |
f4b87b5ac3e94a95102d4789ac97e516736a1718e2d424339f7ef431e1f7475c
|
File details
Details for the file tencent_cos_cli-2.0.1-py3-none-any.whl.
File metadata
- Download URL: tencent_cos_cli-2.0.1-py3-none-any.whl
- Upload date:
- Size: 44.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35785a7680ee53c02849a1840261222b5c63295503e8ed54be87097c35a5b60d
|
|
| MD5 |
40bd73c204dc20fba0c79fa946c7229e
|
|
| BLAKE2b-256 |
20dc23dd3cbc029e5bf61ff4932141ee6577d34db550d629e7d210533a6d86e0
|