localstack-python-client icon indicating copy to clipboard operation
localstack-python-client copied to clipboard

[Request] asyncio support

Open hyunilmmt opened this issue 3 years ago • 4 comments

Would love to see:

  • asyncio version of localstack_client
  • monkeypatch aioboto3 client and resource

Thanks :)

hyunilmmt avatar Sep 14 '22 07:09 hyunilmmt

Hi @hyunilmmt , thanks for reporting! Can you please share some details about your use case - can you share a small snippet or test case of an asyncio function that would make use of the client? I think we have a rough understanding - but it would be helpful for us to understand the requirements a bit better.. Thanks!

whummer avatar Jan 24 '23 22:01 whummer

Hi @hyunilmmt! Is there a chance you could give us some more details on this one?

alexrashed avatar Sep 28 '23 07:09 alexrashed

aioboto3 is the asyncio version of boto3. It'll need patching the same way boto3 is being patched. The use case is that any project using aioboto3 in async code can be tested the same way you test boto3 code.

e.g. using the sample function from the aioboto3 project:

async def main():
    session = aioboto3.Session()
    async with session.resource("s3") as s3:
        bucket = await s3.Bucket('mybucket')
        async for s3_object in bucket.objects.all():
            print(s3_object)

The Session() object there won't be patched even if you used localstack_client.patch.enable_local_endpoints ().

mjpieters avatar May 23 '24 12:05 mjpieters

After a brief look at how enable_local_endpoints works, and at how aioboto3 defines the Session class you probably can apply the same patch to aioboto3 and have it work transparently.

Note that the Session.client object is now a client defined by aiobotocore, but it uses botocore.client.BaseClient as the base exactly the same way boto3 / botocore use it.

mjpieters avatar May 23 '24 12:05 mjpieters