Skip to main content

A PyMongo-like wrapper for DynamoDB

Project description

DynamoWrapper

DynamoWrapper is a Python library that provides a PyMongo-like interface for Amazon DynamoDB. It simplifies DynamoDB operations, making them more intuitive for developers familiar with MongoDB.

Features

  • PyMongo-like API for DynamoDB operations
  • Simplified querying with a familiar syntax
  • Easy table access and management
  • Support for basic CRUD operations
  • Index creation and management
  • Batch operations support

Installation

You can install DynamoWrapper using pip: pip install dynamo-wrapper

Quick Start

Here's a simple example to get you started:

from dynamo_wrapper import DynamoClient

# Initialize the client
client = DynamoClient(aws_access_key_id, aws_secret_access_key, region)

# Access a table
table = client['my-table']

# Insert a document
table.insert_one({'id': '1', 'name': 'John Doe', 'age': 30})

# Find documents
results = table.find({'age': ('GT', 25)})

# Update a document
table.update_one({'id': ('EQ', '1')}, {'name': 'Jane Doe'})

# Delete a document
table.delete_one({'id': ('EQ', '1')})

Usage

Initializing the Client

from dynamo_wrapper import DynamoClient

client = DynamoClient(aws_access_key_id, aws_secret_access_key, region)

Accessing a Table

table = client['table-name']

Insert Operations

# Insert one document
table.insert_one({'id': '1', 'name': 'John Doe', 'age': 30})

# Insert multiple documents
table.insert_many([
    {'id': '2', 'name': 'Jane Doe', 'age': 28},
    {'id': '3', 'name': 'Bob Smith', 'age': 35}
])

Find Operations

# Find one document
result = table.find_one({'id': ('EQ', '1')})

# Find multiple documents
results = table.find({'age': ('GT', 25)})

# Find with projection
results = table.find({'age': ('GT', 25)}, projection=['name', 'age'])

# Find with limit
results = table.find({'age': ('GT', 25)}, limit=10)

Update Operations

# Update one document
table.update_one({'id': ('EQ', '1')}, {'name': 'Jane Doe'})

Delete Operations

# Delete one document
table.delete_one({'id': ('EQ', '1')})

Count Operations

# Count documents
count = table.count({'age': ('GT', 25)})

Index Operations

# Create an index
table.create_index('name')

Query Operators

DynamoWrapper supports the following comparison operators:

  • EQ: Equal to
  • NE: Not equal to
  • LT: Less than
  • LTE: Less than or equal to
  • GT: Greater than
  • GTE: Greater than or equal to
  • IN: In a list of values
  • BETWEEN: Between two values

Example:

table.find({'age': ('GT', 25), 'status': ('EQ', 'active')})

Error Handling

DynamoWrapper provides custom exceptions for various error scenarios. Here are some common exceptions:

  • ItemNotFoundError: Raised when an item is not found in the table
  • QueryError: Raised when there's an error in query formation or execution
  • UpdateError: Raised when an update operation fails
  • DeleteError: Raised when a delete operation fails
  • InsertError: Raised when an insert operation fails

Example:

from dynamo_wrapper import ItemNotFoundError

try:
    result = table.find_one({'id': ('EQ', '999')})
except ItemNotFoundError:
    print("Item not found")

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

dynamo_wrapper-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

dynamo_wrapper-0.1.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamo_wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for dynamo_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d6f2a8953dcf1ad635ec4290155819c9f573b4aaef9a53fb1a271e7cbad11642
MD5 b46e365ef3d3365d22ee48e6675f818c
BLAKE2b-256 5a0f2d1db57703f385f678ad21a6026f9ed5609662f191328739e04bf2a4d12e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dynamo_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3eb816e14efbaf0a6ab607a1eb009e7b35fe18c3bfee63240cab016d4b5bc01
MD5 bc1e855ca84e80d0bf4b697f31b2617c
BLAKE2b-256 f9b19da5746dd68c8e1d04c8516dd2de05e008f452997eccce80644c40d9371e

See more details on using hashes here.

Supported by

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