A Client for managing batch interactions with AWS services
Project description
Boto3 Batch Utils
This library offers some functionality to assist in writing records to AWS services in batches, where your data is not naturally batched. This helps to achieve significant efficiencies when interacting with those AWS services as batch writes are often times orders of magnitude faster than individual writes.
General Usage
The library is very simple to use and works on the concept that you wish to submit payloads to a dispatcher, and not care too much about how to batch up the payloads and send them into their target service. This allows you to utilise the significant efficiencies of patch send/put/write methods, without the problem of error handling and batch sizes.
Each of the supported services has it's own dispatcher class. Each has the same 2 meths with which to interact:
- submit_payload: pass in a payload (e.g. a single message, metric etc)
- flush_payloads: send all payloads in the backlog. Don't worry if there are a lot of payloads, the dispatcher will automatically break them down into chunks.
It is recommended you flush_payloads
every invocation or when payload lists become long (100-200 items +) to avoid issues.
Supported Services
Kinesis Put
Batch Put items to a Kinesis stream
from boto3_batch_utils import KinesisBatchDispatcher
kn = KinesisBatchDispatcher('MyExampleStreamName')
kn.submit_payload({"something": "in", "my": "message"})
kn.submit_payload({"tells": "me", "this": "is", "easy": True})
kn.flush_payloads()
Dynamo Write
Batch write records to a DynamoDB table
from boto3_batch_utils import DynamoBatchDispatcher
dy = DynamoBatchDispatcher('MyExampleDynamoTable', partition_key='Id')
dy.submit_payload({"something": "in", "my": "message"})
dy.submit_payload({"tells": "me", "this": "is", "easy": True})
dy.flush_payloads()
Cloudwatch Put Metrics
Batch put metric data to Cloudwatch. CLoudwatch comes with a handy dimension builder function cloudwatch_dimension
to help you construct dimensions
from boto3_batch_utils import CloudwatchBatchDispatcher, cloudwatch_dimension
cw = CloudwatchBatchDispatcher('TEST_JUNK')
cw.submit_payload('RANDOM_METRIC', dimensions=cloudwatch_dimension('dimA', '12345'), value=555, unit='Count')
cw.submit_payload('RANDOM_METRIC', dimensions=cloudwatch_dimension('dimA', '12345'), value=1234, unit='Count')
cw.flush_payloads()
SQS Send Messages
Batch send messages to an SQS queue
from boto3_batch_utils import SQSBatchDispatcher
sqs = SQSBatchDispatcher("aQueueWithAName")
sqs.submit_payload("some message of some sort")
sqs.submit_payload("a different message, probably a similar sort")
sqs.flush_payloads()
Project details
Release history Release notifications | RSS feed
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
Hashes for boto3_batch_utils-1.9.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cab903baaf606bffe93731509901476d7387f231b9bd5f32517fccb973f9658f |
|
MD5 | 0cd837c65b4003a42ce6a1433f51da4e |
|
BLAKE2b-256 | 1cee5b16d6a6666a410815959f643668720a125a2e088b0079157133783d6445 |