Tentaclio S3
Tentaclio-s3 is a Python package that provides all the necessary dependencies to enable S3 protocol support within the `tentaclio` library. The `tentaclio` library itself simplifies handling streams from various protocols (like file, ftp, sftp, s3) and manages credentials. Tentaclio-s3, currently at version 0.0.3, acts as an 'extra' dependency for tentaclio, not a standalone library for direct S3 interaction.
Warnings
- gotcha Tentaclio-s3 is an 'extra' package for the main `tentaclio` library. You should always import and interact with S3 via `tentaclio.open` (or `tentaclio.copy`, `tentaclio.remove`, etc.) rather than attempting to import directly from `tentaclio_s3`.
- gotcha Authentication for S3 resources relies on `boto3`'s credential resolution chain. This means AWS credentials must be configured in your environment (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION`), via an IAM role for EC2 instances, or in `~/.aws/credentials`.
- gotcha The `tentaclio` library, which `tentaclio-s3` extends, requires Python 3.9 or higher. Ensure your environment meets this minimum Python version.
Install
-
pip install tentaclio-s3
Imports
- open
from tentaclio import open
Quickstart
import os
from tentaclio import open
# Ensure AWS credentials are set via environment variables (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
# or other boto3-supported methods (IAM role, ~/.aws/credentials).
# For demonstration, we'll use a dummy bucket and key.
S3_BUCKET = os.environ.get('TEST_S3_BUCKET', 'your-test-s3-bucket')
S3_KEY = os.environ.get('TEST_S3_KEY', 'path/to/my_file.txt')
S3_PATH = f"s3://{S3_BUCKET}/{S3_KEY}
# Example: Write to an S3 file
content_to_write = "Hello from tentaclio-s3!"
try:
with open(S3_PATH, mode="w") as writer:
writer.write(content_to_write)
print(f"Content successfully written to {S3_PATH}")
# Example: Read from an S3 file
with open(S3_PATH, mode="r") as reader:
read_content = reader.read()
print(f"Content read from {S3_PATH}: {read_content}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure your AWS credentials are configured and the S3 bucket/key are accessible.")