Skip to main content

finalsa-sqs-client is a Python package for interacting with AWS SQS queues.

Project description

finalsa-sqs-client

Thin, typed wrapper around AWS SQS using boto3 with a simple in-memory test implementation.

  • Python 3.10+
  • Adds W3C trace headers to all messages by default (traceparent, tracestate)
  • Accepts dict or JSON string payloads
  • Returns a convenient SqsReponse model with flattened message attributes

Installation

Using pip or uv:

pip install finalsa-sqs-client
# or
uv add finalsa-sqs-client

Requires valid AWS credentials for the default boto3 client (env vars, config file, or IAM role).

Quick start

from finalsa.sqs.client import SqsServiceImpl, SqsException

svc = SqsServiceImpl()

# Resolve a queue URL by name (helper)
queue_url = svc.get_queue_url("my-queue")

# Send a JSON payload (dict) with optional custom attributes
svc.send_message(queue_url, {"hello": "world"}, {"tenant": "acme"})

# Receive up to 10 messages and delete them
messages = svc.receive_messages(queue_url, max_number_of_messages=10, wait_time_seconds=1)
for msg in messages:
		print("body:", msg.body)  # raw JSON string
		print("attrs:", msg.message_attributes)  # flattened: {"traceparent": "...", ...}
		svc.delete_message(queue_url, msg.receipt_handle)

# Other helpers
arn = svc.get_queue_arn(queue_url)
attrs = svc.get_queue_attributes(queue_url)

Errors are raised as SqsException wrapping the underlying boto3 error when applicable.

Message attributes and tracing

  • Custom attributes can be passed as a simple dict of strings: {"key": "value"}.
  • The client adds two trace headers automatically to every send:
    • traceparent
    • tracestate
  • When receiving messages, attributes are returned flattened into a dict[str, str] on SqsReponse.message_attributes.

Example sending raw string JSON and custom attributes:

svc.send_raw_message(queue_url, '{"a":1}', {"source": "ingestor"})

In-memory test service

For local tests or offline development, use the built-in, in-memory implementation:

from finalsa.sqs.client import SqsServiceTest

svc = SqsServiceTest()
svc.send_message("test-queue", {"x": 1})
msgs = svc.receive_messages("test-queue")
assert len(msgs) == 1
svc.delete_message("test-queue", msgs[0].receipt_handle)

Notes:

  • SqsServiceTest keeps messages in process memory keyed by the queue URL/name you pass.
  • It also injects the same trace attributes as the real client so behavior matches production closely.

API overview

The primary entry points are exported from finalsa.sqs.client:

  • SqsService: abstract interface
  • SqsServiceImpl: boto3-backed implementation
  • SqsServiceTest: in-memory implementation for tests
  • SqsException: error wrapper

Key methods (see docstrings for details):

  • receive_messages(queue_url, max_number_of_messages=1, wait_time_seconds=1) -> list[SqsReponse]
  • send_message(queue_url, payload: dict, message_attributes: dict | None = None) -> None
  • send_raw_message(queue_url, data: dict | str, message_attributes: dict | None = None) -> None
  • delete_message(queue_url, receipt_handle) -> None
  • get_queue_arn(queue_url) -> str
  • get_queue_attributes(queue_url) -> dict
  • get_queue_url(queue_name) -> str

Payload handling:

  • Dict payloads are serialized with orjson (compact) before sending.
  • String payloads are sent as-is.

Credentials and configuration

SqsServiceImpl uses the default boto3.client('sqs'). Configure credentials/region via any standard boto3 method:

  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, ...)
  • AWS config/credentials files
  • IAM role when running in AWS

Development

Run tests with uv (recommended):

uv sync
uv run pytest -q

Or with plain pip:

python -m venv .venv && source .venv/bin/activate
pip install -e .[test]
pytest -q

License

MIT – see LICENSE.md.

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

finalsa_sqs_client-2.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

finalsa_sqs_client-2.1.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file finalsa_sqs_client-2.1.1.tar.gz.

File metadata

  • Download URL: finalsa_sqs_client-2.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.12

File hashes

Hashes for finalsa_sqs_client-2.1.1.tar.gz
Algorithm Hash digest
SHA256 01c67e577d639d16dfa97209961d302ec0a4fc06e5def11ae95281c8da6cc1c1
MD5 5840b84355c84fa2b274012ff8ab4e2e
BLAKE2b-256 684cb4e1d82e2a6c283a45ace1d34b28a537084277b4b3fa9e0715bf07339a58

See more details on using hashes here.

File details

Details for the file finalsa_sqs_client-2.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for finalsa_sqs_client-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bce94a20c6b17726e88b4be2f61632f23eb20722aaec2ed8dc85a21bd8f3be81
MD5 4fc16042336165f02224adfd1228656c
BLAKE2b-256 fd66d68be70b38534248c5380a0bf2f87bc641ee2403e06c079fd1b6120144a0

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