Skip to content

Commit ca3fb37

Browse files
MHHukiewitzhoh
authored andcommitted
add MessageFilter & PostFilter; remove limit parameter; rename Aleph to aleph.im
1 parent d5602de commit ca3fb37

14 files changed

+412
-432
lines changed

src/aleph/sdk/base.py

+20-144
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import logging
44
from abc import ABC, abstractmethod
5-
from datetime import datetime
65
from pathlib import Path
76
from typing import (
87
Any,
@@ -26,42 +25,33 @@
2625
from aleph_message.models.execution.program import Encoding
2726
from aleph_message.status import MessageStatus
2827

29-
from aleph.sdk.models import PostsResponse
30-
from aleph.sdk.types import GenericMessage, StorageEnum
28+
from .models.message import MessageFilter
29+
from .models.post import PostFilter, PostsResponse
30+
from .types import GenericMessage, StorageEnum
3131

3232
DEFAULT_PAGE_SIZE = 200
3333

3434

3535
class BaseAlephClient(ABC):
3636
@abstractmethod
37-
async def fetch_aggregate(
38-
self,
39-
address: str,
40-
key: str,
41-
limit: int = 100,
42-
) -> Dict[str, Dict]:
37+
async def fetch_aggregate(self, address: str, key: str) -> Dict[str, Dict]:
4338
"""
4439
Fetch a value from the aggregate store by owner address and item key.
4540
4641
:param address: Address of the owner of the aggregate
4742
:param key: Key of the aggregate
48-
:param limit: Maximum number of items to fetch (Default: 100)
4943
"""
5044
pass
5145

5246
@abstractmethod
5347
async def fetch_aggregates(
54-
self,
55-
address: str,
56-
keys: Optional[Iterable[str]] = None,
57-
limit: int = 100,
48+
self, address: str, keys: Optional[Iterable[str]] = None
5849
) -> Dict[str, Dict]:
5950
"""
6051
Fetch key-value pairs from the aggregate store by owner address.
6152
6253
:param address: Address of the owner of the aggregate
6354
:param keys: Keys of the aggregates to fetch (Default: all items)
64-
:param limit: Maximum number of items to fetch (Default: 100)
6555
"""
6656
pass
6757

@@ -70,15 +60,7 @@ async def get_posts(
7060
self,
7161
pagination: int = DEFAULT_PAGE_SIZE,
7262
page: int = 1,
73-
types: Optional[Iterable[str]] = None,
74-
refs: Optional[Iterable[str]] = None,
75-
addresses: Optional[Iterable[str]] = None,
76-
tags: Optional[Iterable[str]] = None,
77-
hashes: Optional[Iterable[str]] = None,
78-
channels: Optional[Iterable[str]] = None,
79-
chains: Optional[Iterable[str]] = None,
80-
start_date: Optional[Union[datetime, float]] = None,
81-
end_date: Optional[Union[datetime, float]] = None,
63+
post_filter: Optional[PostFilter] = None,
8264
ignore_invalid_messages: Optional[bool] = True,
8365
invalid_messages_log_level: Optional[int] = logging.NOTSET,
8466
) -> PostsResponse:
@@ -87,60 +69,28 @@ async def get_posts(
8769
8870
:param pagination: Number of items to fetch (Default: 200)
8971
:param page: Page to fetch, begins at 1 (Default: 1)
90-
:param types: Types of posts to fetch (Default: all types)
91-
:param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
92-
:param addresses: Addresses of the posts to fetch (Default: all addresses)
93-
:param tags: Tags of the posts to fetch (Default: all tags)
94-
:param hashes: Specific item_hashes to fetch
95-
:param channels: Channels of the posts to fetch (Default: all channels)
96-
:param chains: Chains of the posts to fetch (Default: all chains)
97-
:param start_date: Earliest date to fetch messages from
98-
:param end_date: Latest date to fetch messages from
72+
:param post_filter: Filter to apply to the posts (Default: None)
9973
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
10074
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
10175
"""
10276
pass
10377

10478
async def get_posts_iterator(
10579
self,
106-
types: Optional[Iterable[str]] = None,
107-
refs: Optional[Iterable[str]] = None,
108-
addresses: Optional[Iterable[str]] = None,
109-
tags: Optional[Iterable[str]] = None,
110-
hashes: Optional[Iterable[str]] = None,
111-
channels: Optional[Iterable[str]] = None,
112-
chains: Optional[Iterable[str]] = None,
113-
start_date: Optional[Union[datetime, float]] = None,
114-
end_date: Optional[Union[datetime, float]] = None,
80+
post_filter: Optional[PostFilter] = None,
11581
) -> AsyncIterable[PostMessage]:
11682
"""
11783
Fetch all filtered posts, returning an async iterator and fetching them page by page. Might return duplicates
11884
but will always return all posts.
11985
120-
:param types: Types of posts to fetch (Default: all types)
121-
:param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
122-
:param addresses: Addresses of the posts to fetch (Default: all addresses)
123-
:param tags: Tags of the posts to fetch (Default: all tags)
124-
:param hashes: Specific item_hashes to fetch
125-
:param channels: Channels of the posts to fetch (Default: all channels)
126-
:param chains: Chains of the posts to fetch (Default: all chains)
127-
:param start_date: Earliest date to fetch messages from
128-
:param end_date: Latest date to fetch messages from
86+
:param post_filter: Filter to apply to the posts (Default: None)
12987
"""
13088
page = 1
13189
resp = None
13290
while resp is None or len(resp.posts) > 0:
13391
resp = await self.get_posts(
13492
page=page,
135-
types=types,
136-
refs=refs,
137-
addresses=addresses,
138-
tags=tags,
139-
hashes=hashes,
140-
channels=channels,
141-
chains=chains,
142-
start_date=start_date,
143-
end_date=end_date,
93+
post_filter=post_filter,
14494
)
14595
page += 1
14696
for post in resp.posts:
@@ -165,18 +115,7 @@ async def get_messages(
165115
self,
166116
pagination: int = DEFAULT_PAGE_SIZE,
167117
page: int = 1,
168-
message_type: Optional[MessageType] = None,
169-
message_types: Optional[Iterable[MessageType]] = None,
170-
content_types: Optional[Iterable[str]] = None,
171-
content_keys: Optional[Iterable[str]] = None,
172-
refs: Optional[Iterable[str]] = None,
173-
addresses: Optional[Iterable[str]] = None,
174-
tags: Optional[Iterable[str]] = None,
175-
hashes: Optional[Iterable[str]] = None,
176-
channels: Optional[Iterable[str]] = None,
177-
chains: Optional[Iterable[str]] = None,
178-
start_date: Optional[Union[datetime, float]] = None,
179-
end_date: Optional[Union[datetime, float]] = None,
118+
message_filter: Optional[MessageFilter] = None,
180119
ignore_invalid_messages: Optional[bool] = True,
181120
invalid_messages_log_level: Optional[int] = logging.NOTSET,
182121
) -> MessagesResponse:
@@ -185,69 +124,28 @@ async def get_messages(
185124
186125
:param pagination: Number of items to fetch (Default: 200)
187126
:param page: Page to fetch, begins at 1 (Default: 1)
188-
:param message_type: [DEPRECATED] Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
189-
:param message_types: Filter by message types, can be any combination of "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
190-
:param content_types: Filter by content type
191-
:param content_keys: Filter by aggregate key
192-
:param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
193-
:param addresses: Addresses of the posts to fetch (Default: all addresses)
194-
:param tags: Tags of the posts to fetch (Default: all tags)
195-
:param hashes: Specific item_hashes to fetch
196-
:param channels: Channels of the posts to fetch (Default: all channels)
197-
:param chains: Filter by sender address chain
198-
:param start_date: Earliest date to fetch messages from
199-
:param end_date: Latest date to fetch messages from
127+
:param message_filter: Filter to apply to the messages
200128
:param ignore_invalid_messages: Ignore invalid messages (Default: True)
201129
:param invalid_messages_log_level: Log level to use for invalid messages (Default: logging.NOTSET)
202130
"""
203131
pass
204132

205133
async def get_messages_iterator(
206134
self,
207-
message_type: Optional[MessageType] = None,
208-
content_types: Optional[Iterable[str]] = None,
209-
content_keys: Optional[Iterable[str]] = None,
210-
refs: Optional[Iterable[str]] = None,
211-
addresses: Optional[Iterable[str]] = None,
212-
tags: Optional[Iterable[str]] = None,
213-
hashes: Optional[Iterable[str]] = None,
214-
channels: Optional[Iterable[str]] = None,
215-
chains: Optional[Iterable[str]] = None,
216-
start_date: Optional[Union[datetime, float]] = None,
217-
end_date: Optional[Union[datetime, float]] = None,
135+
message_filter: Optional[MessageFilter] = None,
218136
) -> AsyncIterable[AlephMessage]:
219137
"""
220138
Fetch all filtered messages, returning an async iterator and fetching them page by page. Might return duplicates
221139
but will always return all messages.
222140
223-
:param message_type: Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
224-
:param content_types: Filter by content type
225-
:param content_keys: Filter by content key
226-
:param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
227-
:param addresses: Addresses of the posts to fetch (Default: all addresses)
228-
:param tags: Tags of the posts to fetch (Default: all tags)
229-
:param hashes: Specific item_hashes to fetch
230-
:param channels: Channels of the posts to fetch (Default: all channels)
231-
:param chains: Filter by sender address chain
232-
:param start_date: Earliest date to fetch messages from
233-
:param end_date: Latest date to fetch messages from
141+
:param message_filter: Filter to apply to the messages
234142
"""
235143
page = 1
236144
resp = None
237145
while resp is None or len(resp.messages) > 0:
238146
resp = await self.get_messages(
239147
page=page,
240-
message_type=message_type,
241-
content_types=content_types,
242-
content_keys=content_keys,
243-
refs=refs,
244-
addresses=addresses,
245-
tags=tags,
246-
hashes=hashes,
247-
channels=channels,
248-
chains=chains,
249-
start_date=start_date,
250-
end_date=end_date,
148+
message_filter=message_filter,
251149
)
252150
page += 1
253151
for message in resp.messages:
@@ -272,34 +170,12 @@ async def get_message(
272170
@abstractmethod
273171
def watch_messages(
274172
self,
275-
message_type: Optional[MessageType] = None,
276-
message_types: Optional[Iterable[MessageType]] = None,
277-
content_types: Optional[Iterable[str]] = None,
278-
content_keys: Optional[Iterable[str]] = None,
279-
refs: Optional[Iterable[str]] = None,
280-
addresses: Optional[Iterable[str]] = None,
281-
tags: Optional[Iterable[str]] = None,
282-
hashes: Optional[Iterable[str]] = None,
283-
channels: Optional[Iterable[str]] = None,
284-
chains: Optional[Iterable[str]] = None,
285-
start_date: Optional[Union[datetime, float]] = None,
286-
end_date: Optional[Union[datetime, float]] = None,
173+
message_filter: Optional[MessageFilter] = None,
287174
) -> AsyncIterable[AlephMessage]:
288175
"""
289176
Iterate over current and future matching messages asynchronously.
290177
291-
:param message_type: [DEPRECATED] Type of message to watch
292-
:param message_types: Types of messages to watch
293-
:param content_types: Content types to watch
294-
:param content_keys: Filter by aggregate key
295-
:param refs: References to watch
296-
:param addresses: Addresses to watch
297-
:param tags: Tags to watch
298-
:param hashes: Hashes to watch
299-
:param channels: Channels to watch
300-
:param chains: Chains to watch
301-
:param start_date: Start date from when to watch
302-
:param end_date: End date until when to watch
178+
:param message_filter: Filter to apply to the messages
303179
"""
304180
pass
305181

@@ -318,7 +194,7 @@ async def create_post(
318194
sync: bool = False,
319195
) -> Tuple[AlephMessage, MessageStatus]:
320196
"""
321-
Create a POST message on the Aleph network. It is associated with a channel and owned by an account.
197+
Create a POST message on the aleph.im network. It is associated with a channel and owned by an account.
322198
323199
:param post_content: The content of the message
324200
:param post_type: An arbitrary content type that helps to describe the post_content
@@ -368,7 +244,7 @@ async def create_store(
368244
sync: bool = False,
369245
) -> Tuple[AlephMessage, MessageStatus]:
370246
"""
371-
Create a STORE message to store a file on the Aleph network.
247+
Create a STORE message to store a file on the aleph.im network.
372248
373249
Can be passed either a file path, an IPFS hash or the file's content as raw bytes.
374250
@@ -422,7 +298,7 @@ async def create_program(
422298
:param persistent: Whether the program should be persistent or not (Default: False)
423299
:param encoding: Encoding to use (Default: Encoding.zip)
424300
:param volumes: Volumes to mount
425-
:param subscriptions: Patterns of Aleph messages to forward to the program's event receiver
301+
:param subscriptions: Patterns of aleph.im messages to forward to the program's event receiver
426302
:param metadata: Metadata to attach to the message
427303
"""
428304
pass

0 commit comments

Comments
 (0)