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 resources.

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.1.2.tar.gz (41.9 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.1.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aws_expect-0.1.2.tar.gz
  • Upload date:
  • Size: 41.9 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.1.2.tar.gz
Algorithm Hash digest
SHA256 935788e3d51edaf901b01395bcf7c88e28b8bc4ecff4277d95d1d5c8209e6def
MD5 1892d8b21ec967196a8471923629e785
BLAKE2b-256 3bbd9aa859c0f2a726933ee9f343308a2bf1d0b9f62021cfef23f9a114b5e99f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aws_expect-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d7cc0440f26bc12080312fd543a8898222553492a5c6f2e615f18f964c3a16b1
MD5 456a67a3636301c421117496c57c9f2e
BLAKE2b-256 ff2714a67b2531870ea69a0bc4044a2162492201e63375d0c4f3143216ead581

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