Commit 15ec8bd
feat(storage): add object contexts in Python GCS SDK (#17039)
This PR implements the "Object Contexts" feature in the
`google-cloud-storage` Python SDK, ensuring feature parity with the Go
and Java SDKs.
Key changes:
1. **Metadata Attachment**: Added `ObjectCustomContextPayload` and
`ObjectContexts` classes to `google/cloud/storage/blob.py`. These allow
users to define custom key-value pairs (contexts) for objects.
2. **Blob Property**: Added a `contexts` property to the `Blob` class
with appropriate getters and setters. Added `contexts` to
`_WRITABLE_FIELDS` to enable REST API support for patching and updating
these contexts.
3. **Advanced Filtering**: Updated the `list_blobs` method in both
`google/cloud/storage/client.py` and `google/cloud/storage/bucket.py` to
include a keyword-only `filter_` parameter. This allows server-side
filtering of objects based on various attributes, including custom
contexts.
4. **gRPC Support**: Enhanced
`google/cloud/storage/_grpc_conversions.py` with:
- `blob_to_proto`: Support for converting `contexts` to GCS V2 proto.
5. **Testing**: Added new unit tests in
`google/cloud/storage/tests/unit/test_blob.py` and
`google/cloud/storage/tests/unit/test__grpc_conversions.py` to verify
the new functionality and ensure no regressions (verified with `nox -s
unit-3.12`). Fixed a minor regression in async write tests.
This implementation allows for advanced metadata management and powerful
server-side filtering as requested.
---
*PR created automatically by Jules for task
[13325527155543531515](https://jules.google.com/task/13325527155543531515)
started by @nidhiii-27*
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: nidhiii-27 <224584462+nidhiii-27@users.noreply.github.com>1 parent 494abcd commit 15ec8bdCopy full SHA for 15ec8bd
12 files changed
+832-1Lines changed: 832 additions & 1 deletion
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- packages/google-cloud-storage
- google/cloud/storage
- tests
- system
- unit
- asyncio
Expand file treeCollapse file tree
Open diff view settings
Collapse file
packages/google-cloud-storage/google/cloud/storage/_grpc_conversions.py
Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/_grpc_conversions.py+10Lines changed: 10 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
87 | 87 | |
88 | 88 | |
89 | 89 | |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
90 | 100 | |
Collapse file
packages/google-cloud-storage/google/cloud/storage/blob.py
Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/blob.py+189Lines changed: 189 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
105 | 105 | |
106 | 106 | |
107 | 107 | |
| 108 | + |
108 | 109 | |
109 | 110 | |
110 | 111 | |
| ||
3849 | 3850 | |
3850 | 3851 | |
3851 | 3852 | |
| 3853 | + |
3852 | 3854 | |
3853 | 3855 | |
3854 | 3856 | |
| ||
3910 | 3912 | |
3911 | 3913 | |
3912 | 3914 | |
| 3915 | + |
| 3916 | + |
| 3917 | + |
| 3918 | + |
| 3919 | + |
3913 | 3920 | |
3914 | 3921 | |
3915 | 3922 | |
| ||
3965 | 3972 | |
3966 | 3973 | |
3967 | 3974 | |
| 3975 | + |
| 3976 | + |
| 3977 | + |
| 3978 | + |
| 3979 | + |
| 3980 | + |
| 3981 | + |
| 3982 | + |
3968 | 3983 | |
3969 | 3984 | |
3970 | 3985 | |
| ||
4007 | 4022 | |
4008 | 4023 | |
4009 | 4024 | |
| 4025 | + |
4010 | 4026 | |
4011 | 4027 | |
4012 | 4028 | |
| ||
4090 | 4106 | |
4091 | 4107 | |
4092 | 4108 | |
| 4109 | + |
| 4110 | + |
| 4111 | + |
| 4112 | + |
| 4113 | + |
4093 | 4114 | |
4094 | 4115 | |
4095 | 4116 | |
| ||
4135 | 4156 | |
4136 | 4157 | |
4137 | 4158 | |
| 4159 | + |
| 4160 | + |
| 4161 | + |
| 4162 | + |
| 4163 | + |
| 4164 | + |
| 4165 | + |
| 4166 | + |
4138 | 4167 | |
4139 | 4168 | |
4140 | 4169 | |
| ||
5017 | 5046 | |
5018 | 5047 | |
5019 | 5048 | |
| 5049 | + |
| 5050 | + |
| 5051 | + |
| 5052 | + |
| 5053 | + |
| 5054 | + |
| 5055 | + |
| 5056 | + |
| 5057 | + |
| 5058 | + |
| 5059 | + |
| 5060 | + |
| 5061 | + |
| 5062 | + |
| 5063 | + |
| 5064 | + |
| 5065 | + |
| 5066 | + |
| 5067 | + |
| 5068 | + |
| 5069 | + |
| 5070 | + |
| 5071 | + |
5020 | 5072 | |
5021 | 5073 | |
5022 | 5074 | |
| ||
5309 | 5361 | |
5310 | 5362 | |
5311 | 5363 | |
| 5364 | + |
| 5365 | + |
| 5366 | + |
| 5367 | + |
| 5368 | + |
| 5369 | + |
| 5370 | + |
| 5371 | + |
| 5372 | + |
| 5373 | + |
| 5374 | + |
| 5375 | + |
| 5376 | + |
| 5377 | + |
| 5378 | + |
| 5379 | + |
| 5380 | + |
| 5381 | + |
| 5382 | + |
| 5383 | + |
| 5384 | + |
| 5385 | + |
| 5386 | + |
| 5387 | + |
| 5388 | + |
| 5389 | + |
| 5390 | + |
| 5391 | + |
| 5392 | + |
| 5393 | + |
| 5394 | + |
| 5395 | + |
| 5396 | + |
| 5397 | + |
| 5398 | + |
| 5399 | + |
| 5400 | + |
| 5401 | + |
| 5402 | + |
| 5403 | + |
| 5404 | + |
| 5405 | + |
| 5406 | + |
| 5407 | + |
| 5408 | + |
| 5409 | + |
| 5410 | + |
| 5411 | + |
| 5412 | + |
| 5413 | + |
| 5414 | + |
| 5415 | + |
| 5416 | + |
| 5417 | + |
| 5418 | + |
| 5419 | + |
| 5420 | + |
| 5421 | + |
| 5422 | + |
| 5423 | + |
| 5424 | + |
| 5425 | + |
| 5426 | + |
| 5427 | + |
| 5428 | + |
| 5429 | + |
| 5430 | + |
| 5431 | + |
| 5432 | + |
| 5433 | + |
| 5434 | + |
| 5435 | + |
| 5436 | + |
| 5437 | + |
| 5438 | + |
| 5439 | + |
| 5440 | + |
| 5441 | + |
| 5442 | + |
| 5443 | + |
| 5444 | + |
| 5445 | + |
| 5446 | + |
| 5447 | + |
| 5448 | + |
| 5449 | + |
| 5450 | + |
| 5451 | + |
| 5452 | + |
| 5453 | + |
| 5454 | + |
| 5455 | + |
| 5456 | + |
| 5457 | + |
| 5458 | + |
| 5459 | + |
| 5460 | + |
| 5461 | + |
| 5462 | + |
| 5463 | + |
| 5464 | + |
| 5465 | + |
| 5466 | + |
| 5467 | + |
| 5468 | + |
| 5469 | + |
| 5470 | + |
| 5471 | + |
| 5472 | + |
| 5473 | + |
| 5474 | + |
| 5475 | + |
| 5476 | + |
| 5477 | + |
| 5478 | + |
| 5479 | + |
| 5480 | + |
| 5481 | + |
| 5482 | + |
| 5483 | + |
| 5484 | + |
| 5485 | + |
| 5486 | + |
| 5487 | + |
| 5488 | + |
| 5489 | + |
| 5490 | + |
| 5491 | + |
| 5492 | + |
| 5493 | + |
| 5494 | + |
| 5495 | + |
| 5496 | + |
| 5497 | + |
| 5498 | + |
| 5499 | + |
| 5500 | + |
Collapse file
packages/google-cloud-storage/google/cloud/storage/bucket.py
Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/bucket.py+26-1Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
42 | 42 | |
43 | 43 | |
44 | 44 | |
| 45 | + |
45 | 46 | |
46 | 47 | |
47 | 48 | |
| ||
1423 | 1424 | |
1424 | 1425 | |
1425 | 1426 | |
| 1427 | + |
1426 | 1428 | |
1427 | 1429 | |
1428 | 1430 | |
| ||
1516 | 1518 | |
1517 | 1519 | |
1518 | 1520 | |
| 1521 | + |
| 1522 | + |
| 1523 | + |
| 1524 | + |
| 1525 | + |
1519 | 1526 | |
1520 | 1527 | |
1521 | 1528 | |
| ||
1545 | 1552 | |
1546 | 1553 | |
1547 | 1554 | |
| 1555 | + |
1548 | 1556 | |
1549 | 1557 | |
1550 | 1558 | |
| ||
1972 | 1980 | |
1973 | 1981 | |
1974 | 1982 | |
| 1983 | + |
1975 | 1984 | |
1976 | 1985 | |
1977 | 1986 | |
| ||
2065 | 2074 | |
2066 | 2075 | |
2067 | 2076 | |
| 2077 | + |
| 2078 | + |
| 2079 | + |
| 2080 | + |
2068 | 2081 | |
2069 | 2082 | |
2070 | 2083 | |
| ||
2094 | 2107 | |
2095 | 2108 | |
2096 | 2109 | |
| 2110 | + |
| 2111 | + |
| 2112 | + |
| 2113 | + |
| 2114 | + |
| 2115 | + |
| 2116 | + |
| 2117 | + |
| 2118 | + |
| 2119 | + |
| 2120 | + |
| 2121 | + |
2097 | 2122 | |
2098 | 2123 | |
2099 | 2124 | |
2100 | | - |
| 2125 | + |
2101 | 2126 | |
2102 | 2127 | |
2103 | 2128 | |
|
Collapse file
packages/google-cloud-storage/google/cloud/storage/client.py
Copy file name to clipboardExpand all lines: packages/google-cloud-storage/google/cloud/storage/client.py+8Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1291 | 1291 | |
1292 | 1292 | |
1293 | 1293 | |
| 1294 | + |
1294 | 1295 | |
1295 | 1296 | |
1296 | 1297 | |
| ||
1400 | 1401 | |
1401 | 1402 | |
1402 | 1403 | |
| 1404 | + |
| 1405 | + |
| 1406 | + |
| 1407 | + |
1403 | 1408 | |
1404 | 1409 | |
1405 | 1410 | |
| ||
1443 | 1448 | |
1444 | 1449 | |
1445 | 1450 | |
| 1451 | + |
| 1452 | + |
| 1453 | + |
1446 | 1454 | |
1447 | 1455 | |
1448 | 1456 | |
|
0 commit comments