feat: add get_object method for async grpc client (#1735) · googleapis/python-storage@0e5ec29 · GitHub
Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 0e5ec29

Browse files
authored
feat: add get_object method for async grpc client (#1735)
This method can be used to fetch the metadata of an object using the async grpc API.
1 parent 7a00dfb commit 0e5ec29

3 files changed

Lines changed: 191 additions & 0 deletions

File tree

google/cloud/storage/asyncio/async_grpc_client.py

Lines changed: 63 additions & 0 deletions

tests/system/test_zonal.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,3 +601,56 @@ async def _run():
601601
gc.collect()
602602

603603
event_loop.run_until_complete(_run())
604+
605+
def test_get_object_after_appendable_write(
606+
grpc_clients,
607+
grpc_client_direct,
608+
event_loop,
609+
storage_client,
610+
blobs_to_delete,
611+
):
612+
"""Test getting object metadata after writing with AsyncAppendableObjectWriter.
613+
614+
This test:
615+
1. Creates a test object using AsyncAppendableObjectWriter
616+
2. Appends content to the object (without finalizing)
617+
3. Closes the write stream
618+
4. Fetches the object metadata using AsyncGrpcClient.get_object()
619+
5. Verifies the object size matches the written data
620+
"""
621+
622+
async def _run():
623+
grpc_client = grpc_client_direct
624+
object_name = f"test-get-object-{uuid.uuid4().hex}"
625+
test_data = b"Some test data bytes."
626+
expected_size = len(test_data)
627+
628+
writer = AsyncAppendableObjectWriter(
629+
grpc_client,
630+
_ZONAL_BUCKET,
631+
object_name,
632+
)
633+
634+
await writer.open()
635+
await writer.append(test_data)
636+
await writer.close(finalize_on_close=False)
637+
638+
obj = await grpc_client.get_object(
639+
bucket_name=_ZONAL_BUCKET,
640+
object_name=object_name,
641+
)
642+
643+
# Assert
644+
assert obj is not None
645+
assert obj.name == object_name
646+
assert obj.bucket == f"projects/_/buckets/{_ZONAL_BUCKET}"
647+
assert obj.size == expected_size, (
648+
f"Expected object size {expected_size}, got {obj.size}"
649+
)
650+
651+
# Cleanup
652+
blobs_to_delete.append(storage_client.bucket(_ZONAL_BUCKET).blob(object_name))
653+
del writer
654+
gc.collect()
655+
656+
event_loop.run_until_complete(_run())

tests/unit/asyncio/test_async_grpc_client.py

Lines changed: 75 additions & 0 deletions

0 commit comments

Comments
 (0)