Skip to content

Commit 4fba443

Browse files
authored
Merge pull request #186 public method renames for topic client
2 parents 0385ad9 + fc7ea86 commit 4fba443

File tree

10 files changed

+46
-45
lines changed

10 files changed

+46
-45
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* BROKEN CHANGES: change names of public method in topic client
2+
13
## 3.0.1b5 ##
24
* Remove six package from code and dependencies (remove support python2)
35
* Use anonymous credentials by default instead of iam metadata (use ydb.driver.credentials_from_env_variables for creds by env var)

examples/topic/reader_async_example.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,12 @@ async def connect():
1010
connection_string="grpc://localhost:2135?database=/local",
1111
credentials=ydb.credentials.AnonymousCredentials(),
1212
)
13-
reader = ydb.TopicClientAsyncIO(db).topic_reader(
14-
"/local/topic", consumer="consumer"
15-
)
13+
reader = ydb.TopicClientAsyncIO(db).reader("/local/topic", consumer="consumer")
1614
return reader
1715

1816

1917
async def create_reader_and_close_with_context_manager(db: ydb.aio.Driver):
20-
with ydb.TopicClientAsyncIO(db).topic_reader(
18+
with ydb.TopicClientAsyncIO(db).reader(
2119
"/database/topic/path", consumer="consumer"
2220
) as reader:
2321
async for message in reader.messages():
@@ -91,7 +89,7 @@ async def get_one_batch_from_external_loop_async(reader: ydb.TopicReaderAsyncIO)
9189
async def auto_deserialize_message(db: ydb.aio.Driver):
9290
# async, batch work similar to this
9391

94-
async with ydb.TopicClientAsyncIO(db).topic_reader(
92+
async with ydb.TopicClientAsyncIO(db).reader(
9593
"/database/topic/path", consumer="asd", deserializer=json.loads
9694
) as reader:
9795
async for message in reader.messages():
@@ -133,7 +131,7 @@ def process_batch(batch):
133131

134132

135133
async def connect_and_read_few_topics(db: ydb.aio.Driver):
136-
with ydb.TopicClientAsyncIO(db).topic_reader(
134+
with ydb.TopicClientAsyncIO(db).reader(
137135
[
138136
"/database/topic/path",
139137
ydb.TopicSelector("/database/second-topic", partitions=3),
@@ -156,7 +154,7 @@ def on_commit(event: ydb.TopicReaderEvents.OnCommit) -> None:
156154
print(event.topic)
157155
print(event.offset)
158156

159-
async with ydb.TopicClientAsyncIO(db).topic_reader(
157+
async with ydb.TopicClientAsyncIO(db).reader(
160158
"/local", consumer="consumer", commit_batch_time=4, on_commit=on_commit
161159
) as reader:
162160
async for message in reader.messages():
@@ -173,7 +171,7 @@ async def on_get_partition_start_offset(
173171
resp.start_offset = 123
174172
return resp
175173

176-
async with ydb.TopicClient(db).topic_reader(
174+
async with ydb.TopicClient(db).reader(
177175
"/local/test",
178176
consumer="consumer",
179177
on_get_partition_start_offset=on_get_partition_start_offset,

examples/topic/reader_example.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ def connect():
99
connection_string="grpc://localhost:2135?database=/local",
1010
credentials=ydb.credentials.AnonymousCredentials(),
1111
)
12-
reader = ydb.TopicClient(db).topic_reader("/local/topic", consumer="consumer")
12+
reader = ydb.TopicClient(db).reader("/local/topic", consumer="consumer")
1313
return reader
1414

1515

1616
def create_reader_and_close_with_context_manager(db: ydb.Driver):
17-
with ydb.TopicClient(db).topic_reader(
17+
with ydb.TopicClient(db).reader(
1818
"/database/topic/path", consumer="consumer", buffer_size_bytes=123
1919
) as reader:
2020
for message in reader:
@@ -81,7 +81,7 @@ def get_one_batch_from_external_loop(reader: ydb.TopicReader):
8181
def auto_deserialize_message(db: ydb.Driver):
8282
# async, batch work similar to this
8383

84-
reader = ydb.TopicClient(db).topic_reader(
84+
reader = ydb.TopicClient(db).reader(
8585
"/database/topic/path", consumer="asd", deserializer=json.loads
8686
)
8787
for message in reader.messages():
@@ -123,7 +123,7 @@ def process_batch(batch):
123123

124124

125125
def connect_and_read_few_topics(db: ydb.Driver):
126-
with ydb.TopicClient(db).topic_reader(
126+
with ydb.TopicClient(db).reader(
127127
[
128128
"/database/topic/path",
129129
ydb.TopicSelector("/database/second-topic", partitions=3),
@@ -146,7 +146,7 @@ def on_commit(event: ydb.TopicReaderEvents.OnCommit) -> None:
146146
print(event.topic)
147147
print(event.offset)
148148

149-
with ydb.TopicClient(db).topic_reader(
149+
with ydb.TopicClient(db).reader(
150150
"/local", consumer="consumer", commit_batch_time=4, on_commit=on_commit
151151
) as reader:
152152
for message in reader:
@@ -164,7 +164,7 @@ def on_get_partition_start_offset(
164164
resp.start_offset = 123
165165
return resp
166166

167-
with ydb.TopicClient(db).topic_reader(
167+
with ydb.TopicClient(db).reader(
168168
"/local/test",
169169
consumer="consumer",
170170
on_get_partition_start_offset=on_get_partition_start_offset,

examples/topic/writer_async_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@
88

99

1010
async def create_writer(db: ydb.aio.Driver):
11-
async with ydb.TopicClientAsyncIO(db).topic_writer(
11+
async with ydb.TopicClientAsyncIO(db).writer(
1212
"/database/topic/path",
1313
producer_and_message_group_id="producer-id",
1414
) as writer:
1515
await writer.write(TopicWriterMessage("asd"))
1616

1717

1818
async def connect_and_wait(db: ydb.aio.Driver):
19-
async with ydb.TopicClientAsyncIO(db).topic_writer(
19+
async with ydb.TopicClientAsyncIO(db).writer(
2020
"/database/topic/path",
2121
producer_and_message_group_id="producer-id",
2222
) as writer:
2323
writer.wait_init()
2424

2525

2626
async def connect_without_context_manager(db: ydb.aio.Driver):
27-
writer = ydb.TopicClientAsyncIO(db).topic_writer(
27+
writer = ydb.TopicClientAsyncIO(db).writer(
2828
"/database/topic/path",
2929
producer_and_message_group_id="producer-id",
3030
)
@@ -81,7 +81,7 @@ async def send_messages_with_wait_ack(writer: ydb.TopicWriterAsyncIO):
8181

8282

8383
async def send_json_message(db: ydb.aio.Driver):
84-
async with ydb.TopicClientAsyncIO(db).topic_writer(
84+
async with ydb.TopicClientAsyncIO(db).writer(
8585
"/database/path/topic", serializer=json.dumps
8686
) as writer:
8787
writer.write({"a": 123})

examples/topic/writer_example.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ async def connect():
1313
connection_string="grpc://localhost:2135?database=/local",
1414
credentials=ydb.credentials.AnonymousCredentials(),
1515
)
16-
writer = ydb.TopicClientAsyncIO(db).topic_writer(
16+
writer = ydb.TopicClientAsyncIO(db).writer(
1717
"/local/topic",
1818
producer_and_message_group_id="producer-id",
1919
)
2020
await writer.write(TopicWriterMessage("asd"))
2121

2222

2323
def create_writer(db: ydb.Driver):
24-
with ydb.TopicClient(db).topic_writer(
24+
with ydb.TopicClient(db).writer(
2525
"/database/topic/path",
2626
producer_and_message_group_id="producer-id",
2727
) as writer:
2828
writer.write(TopicWriterMessage("asd"))
2929

3030

3131
def connect_and_wait(db: ydb.Driver):
32-
with ydb.TopicClient(db).topic_writer(
32+
with ydb.TopicClient(db).writer(
3333
"/database/topic/path",
3434
producer_and_message_group_id="producer-id",
3535
) as writer:
3636
writer.wait()
3737

3838

3939
def connect_without_context_manager(db: ydb.Driver):
40-
writer = ydb.TopicClient(db).topic_writer(
40+
writer = ydb.TopicClient(db).writer(
4141
"/database/topic/path",
4242
producer_and_message_group_id="producer-id",
4343
)
@@ -98,7 +98,7 @@ def send_messages_with_wait_ack(writer: ydb.TopicWriter):
9898

9999

100100
def send_json_message(db: ydb.Driver):
101-
with ydb.TopicClient(db).topic_writer(
101+
with ydb.TopicClient(db).writer(
102102
"/database/path/topic", serializer=json.dumps
103103
) as writer:
104104
writer.write({"a": 123})

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ async def topic_path(driver, topic_consumer, database) -> str:
131131
@pytest.fixture()
132132
@pytest.mark.asyncio()
133133
async def topic_with_messages(driver, topic_path):
134-
writer = driver.topic_client.topic_writer(
134+
writer = driver.topic_client.writer(
135135
topic_path, producer_and_message_group_id="fixture-producer-id"
136136
)
137137
await writer.write_with_ack(

tests/topics/test_control_plane.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def test_drop_topic(self, driver, topic_path):
2727
await client.drop_topic(topic_path)
2828

2929
async def test_describe_topic(self, driver, topic_path: str, topic_consumer):
30-
res = await driver.topic_client.describe(topic_path)
30+
res = await driver.topic_client.describe_topic(topic_path)
3131

3232
assert res.self.name == os.path.basename(topic_path)
3333

@@ -61,8 +61,7 @@ def test_drop_topic(self, driver_sync, topic_path):
6161
client.drop_topic(topic_path)
6262

6363
def test_describe_topic(self, driver_sync, topic_path: str, topic_consumer):
64-
res = driver_sync.topic_client.describe(topic_path)
65-
res.partition_count_limit
64+
res = driver_sync.topic_client.describe_topic(topic_path)
6665

6766
assert res.self.name == os.path.basename(topic_path)
6867

tests/topics/test_topic_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class TestTopicReaderAsyncIO:
66
async def test_read_message(
77
self, driver, topic_path, topic_with_messages, topic_consumer
88
):
9-
reader = driver.topic_client.topic_reader(topic_consumer, topic_path)
9+
reader = driver.topic_client.reader(topic_consumer, topic_path)
1010

1111
assert await reader.receive_batch() is not None
1212
await reader.close()
@@ -16,7 +16,7 @@ class TestTopicReaderSync:
1616
def test_read_message(
1717
self, driver_sync, topic_path, topic_with_messages, topic_consumer
1818
):
19-
reader = driver_sync.topic_client.topic_reader(topic_consumer, topic_path)
19+
reader = driver_sync.topic_client.reader(topic_consumer, topic_path)
2020

2121
assert reader.receive_batch() is not None
2222
reader.close()

tests/topics/test_topic_writer.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
@pytest.mark.asyncio
77
class TestTopicWriterAsyncIO:
88
async def test_send_message(self, driver: ydb.aio.Driver, topic_path):
9-
writer = driver.topic_client.topic_writer(
9+
writer = driver.topic_client.writer(
1010
topic_path, producer_and_message_group_id="test"
1111
)
1212
await writer.write(ydb.TopicWriterMessage(data="123".encode()))
1313
await writer.close()
1414

1515
async def test_wait_last_seqno(self, driver: ydb.aio.Driver, topic_path):
16-
async with driver.topic_client.topic_writer(
16+
async with driver.topic_client.writer(
1717
topic_path,
1818
producer_and_message_group_id="test",
1919
auto_seqno=False,
@@ -22,7 +22,7 @@ async def test_wait_last_seqno(self, driver: ydb.aio.Driver, topic_path):
2222
ydb.TopicWriterMessage(data="123".encode(), seqno=5)
2323
)
2424

25-
async with driver.topic_client.topic_writer(
25+
async with driver.topic_client.writer(
2626
topic_path,
2727
producer_and_message_group_id="test",
2828
get_last_seqno=True,
@@ -31,7 +31,7 @@ async def test_wait_last_seqno(self, driver: ydb.aio.Driver, topic_path):
3131
assert init_info.last_seqno == 5
3232

3333
async def test_auto_flush_on_close(self, driver: ydb.aio.Driver, topic_path):
34-
async with driver.topic_client.topic_writer(
34+
async with driver.topic_client.writer(
3535
topic_path,
3636
producer_and_message_group_id="test",
3737
auto_seqno=False,
@@ -43,7 +43,7 @@ async def test_auto_flush_on_close(self, driver: ydb.aio.Driver, topic_path):
4343
ydb.TopicWriterMessage(data=f"msg-{i}", seqno=last_seqno)
4444
)
4545

46-
async with driver.topic_client.topic_writer(
46+
async with driver.topic_client.writer(
4747
topic_path,
4848
producer_and_message_group_id="test",
4949
get_last_seqno=True,
@@ -54,21 +54,21 @@ async def test_auto_flush_on_close(self, driver: ydb.aio.Driver, topic_path):
5454

5555
class TestTopicWriterSync:
5656
def test_send_message(self, driver_sync: ydb.Driver, topic_path):
57-
writer = driver_sync.topic_client.topic_writer(
57+
writer = driver_sync.topic_client.writer(
5858
topic_path, producer_and_message_group_id="test"
5959
)
6060
writer.write(ydb.TopicWriterMessage(data="123".encode()))
6161
writer.close()
6262

6363
def test_wait_last_seqno(self, driver_sync: ydb.Driver, topic_path):
64-
with driver_sync.topic_client.topic_writer(
64+
with driver_sync.topic_client.writer(
6565
topic_path,
6666
producer_and_message_group_id="test",
6767
auto_seqno=False,
6868
) as writer:
6969
writer.write_with_ack(ydb.TopicWriterMessage(data="123".encode(), seqno=5))
7070

71-
with driver_sync.topic_client.topic_writer(
71+
with driver_sync.topic_client.writer(
7272
topic_path,
7373
producer_and_message_group_id="test",
7474
get_last_seqno=True,
@@ -77,7 +77,7 @@ def test_wait_last_seqno(self, driver_sync: ydb.Driver, topic_path):
7777
assert init_info.last_seqno == 5
7878

7979
def test_auto_flush_on_close(self, driver_sync: ydb.Driver, topic_path):
80-
with driver_sync.topic_client.topic_writer(
80+
with driver_sync.topic_client.writer(
8181
topic_path,
8282
producer_and_message_group_id="test",
8383
auto_seqno=False,
@@ -87,7 +87,7 @@ def test_auto_flush_on_close(self, driver_sync: ydb.Driver, topic_path):
8787
last_seqno = i + 1
8888
writer.write(ydb.TopicWriterMessage(data=f"msg-{i}", seqno=last_seqno))
8989

90-
with driver_sync.topic_client.topic_writer(
90+
with driver_sync.topic_client.writer(
9191
topic_path,
9292
producer_and_message_group_id="test",
9393
get_last_seqno=True,

ydb/topic.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def create_topic(
9292
_wrap_operation,
9393
)
9494

95-
async def describe(
95+
async def describe_topic(
9696
self, path: str, include_stats: bool = False
9797
) -> TopicDescription:
9898
args = locals().copy()
@@ -115,7 +115,7 @@ async def drop_topic(self, path: str):
115115
_wrap_operation,
116116
)
117117

118-
def topic_reader(
118+
def reader(
119119
self,
120120
consumer: str,
121121
topic: str,
@@ -139,7 +139,7 @@ def topic_reader(
139139
settings = TopicReaderSettings(**args)
140140
return TopicReaderAsyncIO(self._driver, settings)
141141

142-
def topic_writer(
142+
def writer(
143143
self,
144144
topic,
145145
*,
@@ -215,7 +215,9 @@ def create_topic(
215215
_wrap_operation,
216216
)
217217

218-
def describe(self, path: str, include_stats: bool = False) -> TopicDescription:
218+
def describe_topic(
219+
self, path: str, include_stats: bool = False
220+
) -> TopicDescription:
219221
args = locals().copy()
220222
del args["self"]
221223
req = _ydb_topic_public_types.DescribeTopicRequestParams(**args)
@@ -236,7 +238,7 @@ def drop_topic(self, path: str):
236238
_wrap_operation,
237239
)
238240

239-
def topic_reader(
241+
def reader(
240242
self,
241243
consumer: str,
242244
topic: str,
@@ -260,7 +262,7 @@ def topic_reader(
260262
settings = TopicReaderSettings(**args)
261263
return TopicReader(self._driver, settings)
262264

263-
def topic_writer(
265+
def writer(
264266
self,
265267
topic,
266268
producer_and_message_group_id: str,

0 commit comments

Comments
 (0)