Skip to main content

codecov

A wrapper for the following boto3 s3 client operations with connection retry and checksum verification:

  • get_object

  • head_object

  • upload_fileobj

  • copy_object

  • delete_object

  • list_objects_v2

Features

  • Retry connection failures

  • Confirm checksum of uploaded and retrieved objects

  • Move object

  • Constrained interface to support simple CRUD operations for objects in existing buckets

Configuration

The following environment variables configure the object clerk.

Variable

Description

Type

Default

MULTIPART_THRESHOLD

Threshold in bytes at which uploads are broken into multiple parts for upload. Impacts the checksum stored in the eTag

STR

524288000

S3_CLIENT_CONFIG

Boto Core Client Configuration https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html Defaults reflect capturing the retry of failed operations at a higher level. May be overridden at initialization time with the client_config parameter.

JSON

`json {"connect_timeout": 60, "read_timeout": 60, "retries": {"max_attempts": 0}} `

S3_UPLOAD_CONFIG

Transfer Configuration applied to uploads https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/s3.html#boto3.s3.transfer.TransferConfig multipart_threshold and multipart_chunksize are set by the MULTIPART_THRESHOLD environment variable. Values for these keys in the S3_UPLOAD_CONFIG will be discarded. May be overridden at initialization time with the transfer_config parameter.

JSON

`json {} `

S3_DOWNLOAD_CONFIG

Reserved for download transfer configuration (currently not applied by object_clerk) https://boto3.amazonaws.com/v1/documentation/api/latest/reference/customizations/s3.html#boto3.s3.transfer.TransferConfig

JSON

`json {} `

CHECKSUM_RETRY_CONFIG

Configuration for retrying failed connections

JSON

`json {"retry_delay": 1, "retry_backoff": 1, "retry_jitter": [1, 3], "retry_max_delay": 5, "retry_tries": 3} `

Installation

pip install object-clerk

Examples

Initialize

clerk = ObjectClerk(host=127.0.0.1, port=8080, access_key=12342, secret_key=12342, retry_delay=1, retry_backoff=1, retry_jitter=(1, 3), retry_max_delay=5, retry_tries=3, use_ssl=False)'

Get Object

# with checksum verified

bytes_response = clerk.get_object("bucket", "object_key")

# without checksum verified

bytes_response = clerk.get_object("bucket", "object_key", verify_checksum=False)

Delete Object

clerk.delete_object("bucket", "object_key")

Get Object Info

dict_response = clerk.get_object_info("bucket", "object_key")

Copy Object

# with checksum verified

clerk.copy_object(
    "source_bucket",
    "source_object_key",
    "destination_bucket",
    "destination_object_key",
)

# without checksum verified

clerk.copy_object(
    "source_bucket",
    "source_object_key",
    "destination_bucket",
    "destination_object_key",
    verify_checksum=False
)

Upload Object

# with checksum verified

with open("file", mode='rb') as f:

    clerk.upload_object(f, "bucket", "object_key")

# without checksum verified

with open("file", mode='rb') as f:

    clerk.upload_object(f, "bucket", "object_key", verify_checksum=False)

Move Object

# with checksum verified

clerk.move_object(
    "source_bucket",
    "source_object_key",
    "destination_bucket",
    "destination_object_key",
)

# without checksum verified

clerk.move_object(
    "source_bucket",
    "source_object_key",
    "destination_bucket",
    "destination_object_key",
    verify_checksum=False
)

List Object

clerk.list_objects(
    "bucket_name",
    1000
)

Test

git clone git@bitbucket.org:swiant/object_store_wrapper.git

pip install -e .

export HOST=<host>

export PORT=<port>

export ACCESS_KEY=<access_key>

export SECRET_KEY=<secret_key>

pytest -v object_clerk

To run the development tests locally, you need a running S3-compatible endpoint. The recommended approach is to use LocalStack via Docker:

# Start LocalStack S3 service
docker run --rm -d -p 4566:4566 -e SERVICES=s3 -e DEFAULT_REGION=us-east-1 localstack/localstack:latest

# Set environment variables for the test session
export OBJECT_STORE_HOST=localhost
export OBJECT_STORE_PORT=4566
export OBJECT_STORE_ACCESS_KEY=test
export OBJECT_STORE_SECRET_KEY=test
export AWS_REGION=us-east-1

# Run tests with tox (all environments)
tox
# Or run a specific environment
tox -e py313

# Stop LocalStack when done
docker stop $(docker ps -q --filter ancestor=localstack/localstack:latest)

Download files

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

Source Distribution

object_clerk-1.1.0.tar.gz (21.0 kB view details)

Uploaded Source

Built Distribution

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

object_clerk-1.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file object_clerk-1.1.0.tar.gz.

File metadata

  • Download URL: object_clerk-1.1.0.tar.gz
  • Upload date:
  • Size: 21.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for object_clerk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 530832c5bbbe14a05ab9270be4fb2b0928e6c216e27d17936f591b7279a8b56b
MD5 5dc696971690df30dc1bd6e63db1bd79
BLAKE2b-256 b6a187c92c24d94b5f48e193a73e8c34b52fc41be5fefb8f1ecc707bb1def967

See more details on using hashes here.

File details

Details for the file object_clerk-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: object_clerk-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for object_clerk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15cda2e553d9eefbeb2e7e40b4cdf5379627d8ed93931fc3d9405488dd4deee6
MD5 8e28e99fbad3886bf3f6bad20a3c7d3b
BLAKE2b-256 dcd781cec48fd0e44eb97a6313eccf851728e1226df26c8c7afdc3c2715e3b9e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.1.2

2 files

0.1.1

1 file

0.1.0

1 file

0.0.18

1 file

0.0.17

1 file

0.0.16

1 file

0.0.15

1 file

0.0.14

1 file

0.0.13

1 file

0.0.12

1 file

0.0.11

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Supported by

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