Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit c67f275

Browse files
chore(docs): improve async docstrings (#978)
1 parent da27527 commit c67f275

11 files changed

Lines changed: 67 additions & 74 deletions

File tree

google/cloud/bigtable/data/_async/client.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def __init__(
112112
client. If not passed (and if no ``_http`` object is
113113
passed), falls back to the default inferred from the
114114
environment.
115-
client_options (Optional[Union[dict, google.api_core.client_options.ClientOptions]]):
115+
client_options:
116116
Client options used to set user options
117117
on the client. API Endpoint should be set through client_options.
118118
Raises:
119-
RuntimeError: if called outside of an async context (no running event loop)
120-
ValueError: if pool_size is less than 1
119+
RuntimeError: if called outside of an async context (no running event loop)
120+
ValueError: if pool_size is less than 1
121121
"""
122122
# set up transport in registry
123123
transport_str = f"pooled_grpc_asyncio_{pool_size}"
@@ -711,14 +711,13 @@ async def read_rows_sharded(
711711
Runs a sharded query in parallel, then return the results in a single list.
712712
Results will be returned in the order of the input queries.
713713
714-
This function is intended to be run on the results on a query.shard() call:
714+
This function is intended to be run on the results on a query.shard() call.
715+
For example::
715716
716-
```
717-
table_shard_keys = await table.sample_row_keys()
718-
query = ReadRowsQuery(...)
719-
shard_queries = query.shard(table_shard_keys)
720-
results = await table.read_rows_sharded(shard_queries)
721-
```
717+
table_shard_keys = await table.sample_row_keys()
718+
query = ReadRowsQuery(...)
719+
shard_queries = query.shard(table_shard_keys)
720+
results = await table.read_rows_sharded(shard_queries)
722721
723722
Args:
724723
sharded_query: a sharded query to execute

google/cloud/bigtable/data/mutations.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ def _from_dict(cls, input_dict: dict[str, Any]) -> Mutation:
9494
Create a `Mutation` instance from a dictionary representation.
9595
9696
Args:
97-
input_dict (dict[str, Any]): A dictionary representation of the mutation.
98-
97+
input_dict: A dictionary representation of the mutation.
9998
Returns:
10099
Mutation: A Mutation instance created from the dictionary.
101-
102100
Raises:
103101
ValueError: If the input dictionary is invalid or does not represent a valid mutation type.
104102
"""
@@ -139,10 +137,10 @@ class SetCell(Mutation):
139137
Mutation to set the value of a cell.
140138
141139
Args:
142-
family (str): The name of the column family to which the new cell belongs.
143-
qualifier (bytes | str): The column qualifier of the new cell.
144-
new_value (bytes | str | int): The value of the new cell.
145-
timestamp_micros (int | None): The timestamp of the new cell. If `None`,
140+
family: The name of the column family to which the new cell belongs.
141+
qualifier: The column qualifier of the new cell.
142+
new_value: The value of the new cell.
143+
timestamp_micros: The timestamp of the new cell. If `None`,
146144
the current timestamp will be used. Timestamps will be sent with
147145
millisecond precision. Extra precision will be truncated. If -1, the
148146
server will assign a timestamp. Note that `SetCell` mutations with
@@ -207,13 +205,12 @@ class DeleteRangeFromColumn(Mutation):
207205
Mutation to delete a range of cells from a column.
208206
209207
Args:
210-
family (str): The name of the column family.
211-
qualifier (bytes): The column qualifier.
212-
start_timestamp_micros (int | None): The start timestamp of the range to
208+
family: The name of the column family.
209+
qualifier: The column qualifier.
210+
start_timestamp_micros: The start timestamp of the range to
213211
delete. `None` represents 0. Defaults to `None`.
214-
end_timestamp_micros (int | None): The end timestamp of the range to
212+
end_timestamp_micros: The end timestamp of the range to
215213
delete. `None` represents infinity. Defaults to `None`.
216-
217214
Raises:
218215
ValueError: If `start_timestamp_micros` is greater than `end_timestamp_micros`.
219216
"""
@@ -254,7 +251,7 @@ class DeleteAllFromFamily(Mutation):
254251
Mutation to delete all cells from a column family.
255252
256253
Args:
257-
family_to_delete (str): The name of the column family to delete.
254+
family_to_delete: The name of the column family to delete.
258255
"""
259256

260257
family_to_delete: str
@@ -287,8 +284,8 @@ class RowMutationEntry:
287284
Bigtable table.
288285
289286
Args:
290-
row_key (bytes | str): The key of the row to mutate.
291-
mutations (Mutation | list[Mutation]): The mutation or list of mutations to apply
287+
row_key: The key of the row to mutate.
288+
mutations: The mutation or list of mutations to apply
292289
to the row.
293290
294291
Raises:
@@ -358,7 +355,7 @@ def _from_dict(cls, input_dict: dict[str, Any]) -> RowMutationEntry:
358355
Create a `RowMutationEntry` instance from a dictionary representation.
359356
360357
Args:
361-
input_dict (dict[str, Any]): A dictionary representation of the mutation entry.
358+
input_dict: A dictionary representation of the mutation entry.
362359
363360
Returns:
364361
RowMutationEntry: A RowMutationEntry instance created from the dictionary.

google/cloud/bigtable/data/read_modify_write_rules.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ class IncrementRule(ReadModifyWriteRule):
4747
Rule to increment a cell's value.
4848
4949
Args:
50-
family (str):
50+
family:
5151
The family name of the cell to increment.
52-
qualifier (bytes | str):
52+
qualifier:
5353
The qualifier of the cell to increment.
54-
increment_amount (int):
54+
increment_amount:
5555
The amount to increment the cell's value. Must be between -2**63 and 2**63 (64-bit signed int).
5656
Raises:
5757
TypeError:
@@ -83,11 +83,11 @@ class AppendValueRule(ReadModifyWriteRule):
8383
Rule to append a value to a cell's value.
8484
8585
Args:
86-
family (str):
86+
family:
8787
The family name of the cell to append to.
88-
qualifier (bytes | str):
88+
qualifier:
8989
The qualifier of the cell to append to.
90-
append_value (bytes | str):
90+
append_value:
9191
The value to append to the cell's value.
9292
Raises:
9393
TypeError: If append_value is not bytes or str.

google/cloud/bigtable/data/read_rows_query.py

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@
3131
class RowRange:
3232
"""
3333
Represents a range of keys in a ReadRowsQuery
34+
35+
Args:
36+
start_key: The start key of the range. If empty, the range is unbounded on the left.
37+
end_key: The end key of the range. If empty, the range is unbounded on the right.
38+
start_is_inclusive: Whether the start key is inclusive. If None, the start key is
39+
inclusive.
40+
end_is_inclusive: Whether the end key is inclusive. If None, the end key is not inclusive.
41+
Raises:
42+
ValueError: if start_key is greater than end_key, or start_is_inclusive
43+
ValueError: if end_is_inclusive is set when the corresponding key is None
44+
ValueError: if start_key or end_key is not a string or bytes.
3445
"""
3546

3647
__slots__ = ("_pb",)
@@ -42,18 +53,6 @@ def __init__(
4253
start_is_inclusive: bool | None = None,
4354
end_is_inclusive: bool | None = None,
4455
):
45-
"""
46-
Args:
47-
start_key: The start key of the range. If empty, the range is unbounded on the left.
48-
end_key: The end key of the range. If empty, the range is unbounded on the right.
49-
start_is_inclusive: Whether the start key is inclusive. If None, the start key is
50-
inclusive.
51-
end_is_inclusive: Whether the end key is inclusive. If None, the end key is not inclusive.
52-
Raises:
53-
ValueError: if start_key is greater than end_key, or start_is_inclusive
54-
ValueError: if end_is_inclusive is set when the corresponding key is None
55-
ValueError: if start_key or end_key is not a string or bytes.
56-
"""
5756
# convert empty key inputs to None for consistency
5857
start_key = None if not start_key else start_key
5958
end_key = None if not end_key else end_key
@@ -221,6 +220,14 @@ def __repr__(self) -> str:
221220
class ReadRowsQuery:
222221
"""
223222
Class to encapsulate details of a read row request
223+
224+
Args:
225+
row_keys: row keys to include in the query
226+
a query can contain multiple keys, but ranges should be preferred
227+
row_ranges: ranges of rows to include in the query
228+
limit: the maximum number of rows to return. None or 0 means no limit
229+
default: None (no limit)
230+
row_filter: a RowFilter to apply to the query
224231
"""
225232

226233
slots = ("_limit", "_filter", "_row_set")
@@ -232,17 +239,6 @@ def __init__(
232239
limit: int | None = None,
233240
row_filter: RowFilter | None = None,
234241
):
235-
"""
236-
Create a new ReadRowsQuery
237-
238-
Args:
239-
row_keys: row keys to include in the query
240-
a query can contain multiple keys, but ranges should be preferred
241-
row_ranges: ranges of rows to include in the query
242-
limit: the maximum number of rows to return. None or 0 means no limit
243-
default: None (no limit)
244-
row_filter: a RowFilter to apply to the query
245-
"""
246242
if row_keys is None:
247243
row_keys = []
248244
if row_ranges is None:

google/cloud/bigtable/data/row.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ class Row:
3333
query.
3434
Expected to be read-only to users, and written by backend
3535
36-
Can be indexed:
37-
cells = row["family", "qualifier"]
36+
Can be indexed by family and qualifier to get cells in the row::
37+
38+
cells = row["family", "qualifier"]
39+
40+
Args:
41+
key: Row key
42+
cells: List of cells in the row
3843
"""
3944

4045
__slots__ = ("row_key", "cells", "_index_data")
@@ -45,14 +50,8 @@ def __init__(
4550
cells: list[Cell],
4651
):
4752
"""
48-
Initializes a Row object
49-
5053
Row objects are not intended to be created by users.
5154
They are returned by the Bigtable backend.
52-
53-
Args:
54-
key (bytes): Row key
55-
cells (list[Cell]): List of cells in the row
5655
"""
5756
self.row_key = key
5857
self.cells: list[Cell] = cells
@@ -121,9 +120,9 @@ def get_cells(
121120
122121
If family or qualifier not passed, will include all
123122
124-
Can also be accessed through indexing:
125-
cells = row["family", "qualifier"]
126-
cells = row["family"]
123+
Can also be accessed through indexing::
124+
cells = row["family", "qualifier"]
125+
cells = row["family"]
127126
128127
Args:
129128
family: family to filter cells by
@@ -172,9 +171,7 @@ def _get_all_from_family(self, family: str) -> Generator[Cell, None, None]:
172171

173172
def __str__(self) -> str:
174173
"""
175-
Human-readable string representation
176-
177-
.. code-block:: python
174+
Human-readable string representation::
178175
179176
{
180177
(family='fam', qualifier=b'col'): [b'value', (+1 more),],

samples/quickstart/main_async_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
from typing import AsyncGenerator
1717

1818
from google.cloud.bigtable.data import BigtableDataClientAsync, SetCell
19-
import pytest, pytest_asyncio
19+
import pytest
20+
import pytest_asyncio
2021

2122
from main_async import main
2223

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==7.4.4
2+
pytest-asyncio
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
google-cloud-bigtable==2.22.0
1+
google-cloud-bigtable==2.23.0

samples/snippets/deletes/deletes_async_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from typing import AsyncGenerator
1919

2020
from google.cloud._helpers import _microseconds_from_datetime
21-
import pytest, pytest_asyncio
21+
import pytest
22+
import pytest_asyncio
2223

2324
import deletes_snippets_async
2425

@@ -72,7 +73,7 @@ async def _populate_table(table_id):
7273
timestamp = datetime.datetime(2019, 5, 1)
7374
timestamp_minus_hr = timestamp - datetime.timedelta(hours=1)
7475

75-
async with (BigtableDataClientAsync(project=PROJECT) as client):
76+
async with BigtableDataClientAsync(project=PROJECT) as client:
7677
async with client.get_table(BIGTABLE_INSTANCE, table_id) as table:
7778
async with table.mutations_batcher() as batcher:
7879
await batcher.append(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
pytest==7.4.4
2+
pytest-asyncio

0 commit comments

Comments
 (0)