Skip to main content

A modular framework for extending boto3 clients with automatic enhancements, wrappers, and developer-friendly features

Project description

botowrap

Python Package PyPI version License: MIT Python 3.7+

A modular framework for building and distributing "opinionated" wrappers around boto3 clients. Enhance your AWS SDK experience with powerful extensions that add developer-friendly features while maintaining the standard boto3 interface.

Out of the box it provides:

  • DynamoDBDocumentExtension
    • Python↔DynamoDB (de)serialization
    • Auto‐CreatedAt/UpdatedAt timestamps
    • Jittered exponential backoff on throttling
    • query_all/scan_all pagination helpers
    • ConsumedCapacity logging

Installation

pip install botowrap

Usage

import logging
import boto3
from botowrap.core import ExtensionManager
from botowrap.extensions.dynamodb import (
    DynamoDBExtension, DynamoDBConfig
)

logging.basicConfig(level=logging.INFO)

# 1) Create the manager (uses the default boto3 session)
mgr = ExtensionManager()

# 2) Register whichever extensions you want:
ddb_config = DynamoDBConfig(
    max_retries=8,
    log_consumed=True,
    add_pagination=True,
    add_timestamps=True
)
mgr.register(DynamoDBExtension(ddb_config))

# 3) Bootstrap: from now on, boto3.client('dynamodb') is enhanced
mgr.bootstrap()

# Use the enhanced client
ddb = boto3.client('dynamodb')

# Insert item with native Python types (automatic serialization)
ddb.put_item(
    TableName='Users',
    Item={
        'UserId': 'alice',
        'Age': 30,
        'Active': True,
        'Data': {'joined': '2023-01-01'}
    }
)

# Use pagination helper
all_users = ddb.scan_all(TableName='Users')
print(all_users)  # All users with Python types

Features

Automatic Type Conversion

No more manual serialization between Python and DynamoDB types:

# Without botowrap
from boto3.dynamodb.types import TypeSerializer
serializer = TypeSerializer()
ddb.put_item(
    TableName='Users',
    Item={
        'UserId': serializer.serialize('alice'),
        'Age': serializer.serialize(30),
        'Active': serializer.serialize(True)
    }
)

# With botowrap
ddb.put_item(
    TableName='Users',
    Item={
        'UserId': 'alice',
        'Age': 30,
        'Active': True
    }
)

Automatic Timestamps

Keep track of when items were created and last modified:

# Creates an item with CreatedAt and UpdatedAt timestamps
ddb.put_item(TableName='Users', Item={'UserId': 'bob'})

# UpdatedAt is automatically updated, CreatedAt preserved
ddb.update_item(
    TableName='Users',
    Key={'UserId': 'bob'},
    UpdateExpression='SET Age = :a',
    ExpressionAttributeValues={':a': 25}
)

Simplified Pagination

No more dealing with LastEvaluatedKey tokens manually:

# With botowrap
all_items = ddb.scan_all(TableName='MyTable')

# Equivalent to:
items = []
resp = ddb.scan(TableName='MyTable')
items.extend(resp.get('Items', []))
while 'LastEvaluatedKey' in resp:
    resp = ddb.scan(
        TableName='MyTable',
        ExclusiveStartKey=resp['LastEvaluatedKey']
    )
    items.extend(resp.get('Items', []))

Configuration Options

The DynamoDB extension can be configured:

ddb_config = DynamoDBConfig(
    # Number of retries for throttling (default: 5)
    max_retries=8,
    
    # Whether to log consumed capacity (default: True)
    log_consumed=True,
    
    # Whether to add pagination helpers (default: True)
    add_pagination=True,
    
    # Whether to add CreatedAt/UpdatedAt timestamps (default: True)
    add_timestamps=True
)

Developing

  • New service wrappers live under botowrap/extensions/
  • Base classes and manager logic are in core.py
  • Extensions must implement:
    • attach(session) - Adds functionality to the boto3 session
    • detach(session) - Removes functionality from the boto3 session

Creating an Extension

from botowrap.core import BaseExtension

class MyServiceExtension(BaseExtension):
    SERVICE = 'my-service'
    
    def __init__(self, config):
        self.config = config
        
    def attach(self, session):
        # Add functionality to the session
        pass
        
    def detach(self, session):
        # Remove functionality from the session
        pass

Documentation

For full documentation, visit the documentation site.

Contributing

Contributions are welcome! See the CONTRIBUTING guide for details.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

botowrap-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

botowrap-0.1.0-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file botowrap-0.1.0.tar.gz.

File metadata

  • Download URL: botowrap-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for botowrap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e53e6b668eca470b4e0cb661ee6ecd5de6f13791e0b2b2a1b5c36dfc51e9d96d
MD5 b2c4c3ea08a784ed851684d1c8d35941
BLAKE2b-256 523d491f0cf75b7f14e75ca8c4ff02f3b5c20ddceedae58af1031985deb1f5c3

See more details on using hashes here.

File details

Details for the file botowrap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: botowrap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for botowrap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94ec98bcd0280f18d13a77fbf29f49a85c200373fcb1144b19a99a4c419b619d
MD5 c2a733be8b1b479e244a2966ade987e2
BLAKE2b-256 368f9321cae06e72d228a79d2b1caf861b40174b0a14a7c8e53bd3696e7b5e19

See more details on using hashes here.

Supported by

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