Skip to main content

Declarative expect/wait syntax for AWS services (S3, DynamoDB, and more)

Project description

AWS Expect

Declarative, Pythonic waiters for AWS services using boto3. Wait for S3 objects and DynamoDB items or tables to reach an expected state — with optional content matching and parallel execution via expect_all.

Features

  • Declarative syntax: expect_s3(obj).to_exist(timeout=30)
  • Native boto3 waiters: Uses AWS's built-in waiter infrastructure
  • Testing-friendly: Perfect for integration tests and CI/CD
  • Resource-based: Works with boto3 resource objects (not low-level clients)
  • Flexible timeouts: Configure both timeout and poll intervals

Installation

pip install aws-expect

Or with uv:

uv add aws-expect

Quick Start

S3 Object Waiting

import boto3
from aws_expect import expect_s3, S3WaitTimeoutError

s3 = boto3.resource("s3")
obj = s3.Object("my-bucket", "report.csv")

try:
    metadata = expect_s3(obj).to_exist(timeout=30, poll_interval=5)
    print(f"Object exists! Size: {metadata['ContentLength']} bytes")
except S3WaitTimeoutError:
    print("Object did not appear within 30 seconds")

expect_s3(obj).to_not_exist(timeout=10, poll_interval=2)

DynamoDB Item Waiting

import boto3
from aws_expect import expect_dynamodb_item, DynamoDBWaitTimeoutError

dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("orders")

try:
    item = expect_dynamodb_item(table).to_exist(
        key={"pk": "order-123"},
        timeout=30,
        poll_interval=5,
    )
    print(f"Order found: {item}")
except DynamoDBWaitTimeoutError:
    print("Item did not appear within 30 seconds")

item = expect_dynamodb_item(table).to_exist(
    key={"pk": "order-123"},
    entries={"status": "shipped"},
    timeout=60,
    poll_interval=5,
)

expect_dynamodb_item(table).to_not_exist(key={"pk": "order-123"}, timeout=10)

Catching Any Timeout

All service-specific exceptions inherit from WaitTimeoutError, so you can catch timeouts from any service in a single handler:

from aws_expect import expect_s3, WaitTimeoutError

try:
    expect_s3(obj).to_exist(timeout=30)
except WaitTimeoutError:
    print("Timed out waiting for resource")

API Reference

Function Description Returns
expect_s3(s3_object) Creates S3ObjectExpectation wrapper S3ObjectExpectation
expect_dynamodb_item(table) Creates DynamoDBItemExpectation wrapper DynamoDBItemExpectation
Method Description Raises
to_exist(timeout=30, poll_interval=5) Waits for resource to exist S3WaitTimeoutError / DynamoDBWaitTimeoutError
to_not_exist(timeout=30, poll_interval=5) Waits for resource to not exist S3WaitTimeoutError / DynamoDBWaitTimeoutError

S3 Parameters: timeout (float), poll_interval (float, min 1)

DynamoDB Parameters: key (dict), timeout (float), poll_interval (float, min 1), entries (dict, optional)

Exceptions

All timeout exceptions inherit from WaitTimeoutError:

  • S3WaitTimeoutError: attributes include bucket, key, timeout
  • DynamoDBWaitTimeoutError: attributes include table_name, key, timeout

How It Works

S3 — uses boto3's native waiter infrastructure:

  • to_exist()client.get_waiter("object_exists").wait()
  • to_not_exist()client.get_waiter("object_not_exists").wait()

DynamoDB — uses a custom polling loop over get_item (DynamoDB does not provide built-in item-level waiters):

  • to_exist() → polls table.get_item(Key=...) until the item appears and optionally matches expected entries
  • to_not_exist() → polls table.get_item(Key=...) until the item is gone

Development

Setup

git clone https://github.com/PhishStick-hub/aws-expect
cd aws-expect
uv sync --all-groups

Running Tests

Tests use testcontainers and LocalStack for real AWS API simulation:

docker info
uv run pytest tests/ -v

Future Roadmap

  • DynamoDB item waiters
  • Lambda function readiness waiters
  • More S3 matchers (content-type, size, tags)

License

MIT License - see LICENSE file for details.

Author

Ivan Shcherbenko

Credits

Built with:

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

aws_expect-0.2.0.tar.gz (43.7 kB view details)

Uploaded Source

Built Distribution

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

aws_expect-0.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file aws_expect-0.2.0.tar.gz.

File metadata

  • Download URL: aws_expect-0.2.0.tar.gz
  • Upload date:
  • Size: 43.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aws_expect-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a78664b53a614cb89f65c3cc678fd6ef577e3984841bb252b76ae9762cd61f41
MD5 0043002b3270e2c6e6a73fd7208dc303
BLAKE2b-256 eb72073341970ba2787d5b9e1ea735803750432b70d9cd746f62c1f9f79f0853

See more details on using hashes here.

File details

Details for the file aws_expect-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aws_expect-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aws_expect-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 526de7041b4ea2ea95d41769b1f2af630d15f020673f8af1c9fb2270f81e13a8
MD5 3e86540e9adf985585791aefe6b3827c
BLAKE2b-256 7339ce95f05b1b18c5115fc9bcf62b06357bbe0a2bab39acbcf5462740ee2e05

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