s3cmd Command Line Tool

2.4.0 · active · verified Fri Apr 10

s3cmd is a free, feature-rich, command-line tool for managing Amazon S3 and other S3-compatible cloud storage services. Written in Python, it allows users to upload, retrieve, and manage data with simple shell commands. The current version is 2.4.0, and it follows an active maintenance release cadence.

Warnings

Install

Imports

Quickstart

Demonstrates how to interact with the s3cmd command-line tool from a Python script using the `subprocess` module to list S3 buckets. Users must ensure s3cmd is installed and configured with appropriate AWS credentials (e.g., via `s3cmd --configure` or environment variables).

import subprocess

# s3cmd requires prior configuration (e.g., via `s3cmd --configure` or AWS environment variables/IAM roles).
# This example assumes s3cmd is configured to access an S3 bucket.

# Example: List S3 buckets
try:
    # Using check=True will raise CalledProcessError if s3cmd exits with a non-zero status
    result = subprocess.run(['s3cmd', 'ls'], check=True, capture_output=True, text=True)
    print("S3 Buckets:\n", result.stdout)
except subprocess.CalledProcessError as e:
    print(f"Error listing buckets: {e.stderr}")
    print("Ensure s3cmd is correctly configured (e.g., with valid credentials in ~/.s3cfg).")
except FileNotFoundError:
    print("s3cmd command not found. Ensure it's installed and in your system's PATH.")

view raw JSON →