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.4.0.tar.gz (58.0 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.4.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aws_expect-0.4.0.tar.gz
  • Upload date:
  • Size: 58.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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.4.0.tar.gz
Algorithm Hash digest
SHA256 e1422b51dd79e543296fab65e67da4738552a119f02ab4c9db37da81c5d3ea96
MD5 96a504fa719f9b6c3cb149cf67ebd91f
BLAKE2b-256 e33799a8d0e115f7abdcb1ee00a9735ee0c18f2f4fafd147d0730f1d76b08da3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aws_expect-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05742fd59af7236b17fe9834564bcd1e97860cdc802ddc92e5ae2308214b46d6
MD5 b5f471ef396f0ffdef476d7b81611885
BLAKE2b-256 50a638b53023c328ea3a541e4a01654946e59df9a78282875705d481e59d7733

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