Skip to content

To get posts you have two options:

  • get_posts to get the posts in their amended state.
  • get_message to only get the unique POST messages at the time of the call.

get_posts

Since version 0.8.0, get_posts uses a PostFilter object to specify the filters:

Usage

async def get_posts(
        self,
        page_size: int = DEFAULT_PAGE_SIZE, # Default is 200
        page: int = 1, # Default is 1
        post_filter: Optional[PostFilter] = None,
        ignore_invalid_messages: Optional[bool] = True,
        invalid_messages_log_level: Optional[int] = logging.NOTSET,
    ) -> PostsResponse:

Arguments

Required arguments

Parameter Description
page_size The number of posts to return per page.
page The page number to return.

Optional arguments

Parameter Description
post_filter A PostFilter object to specify the filters.
ignore_invalid_messages If True, invalid messages will be ignored.
invalid_messages_log_level The log level to use for invalid messages.

Example

from aleph.sdk.client import AlephHttpClient
from aleph.sdk.query.filters import PostFilter

async def main():
    async with AlephHttpClient() as client:
        posts = await client.get_posts(
            post_filter=PostFilter(channels=["MY_CHANNEL"])
        )
        return posts

import asyncio
posts = asyncio.run(main())
print(posts)

outputs something akin to:

"pagination_page": 1,
"pagination_total": 26,
"pagination_per_page": 200,
"pagination_item": "posts",
"posts": [...] -- The list of every posts

get_message

Usage

async def get_message(
        self,
        item_hash: str,
        message_type: Optional[Type[GenericMessage]] = None,
    ) -> GenericMessage:

Arguments

Required arguments

Parameter Description
item_hash The hash of the message to retrieve.

Optional arguments

Parameter Description
message_type The type of message to retrieve.

Example

from aleph.sdk.client import AlephHttpClient
from pprint import pprint

async def main():
    async with AlephHttpClient() as client:
        message = await client.get_message(
            "142f99fbbe63befc868d16a4e389395cd1abc812b0eecaba72e08b8709caafd6",
        )
        return message

import asyncio
message = asyncio.run(main())
pprint(message.content.dict())

outputs:

{'address': '0xd7e1f3De8Cf89F0a032614994b0baAab88B747b6',
 'content': {'body': [{'appId': '0',
                       'chain': 'mumbai',
                       'payment': [{'payment': {'fee': 0,
                                                'limitPeriod': 6,
                                                'loadingTime': 5,
                                                'name': 'Standard',
                                                'owner': '0x6432BF02a54975500EE3924Dfe504351E27b968B',
                                                'paymentTokens': [{'firstAmount': '0',
                                                                   'price': '10000000',
                                                                   'token': '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23'},
                                                                  {'firstAmount': '0',
                                                                   'price': '10000000000000000000',
                                                                   'token': '0xe583769738b6dd4E7CAF8451050d1948BE717679'}],
                                                'paymentType': 0,
                                                'periodType': 'MONTH',
                                                'trialPeriod': 0},
                                    'paymentId': '0xd5b2779d1fba52a8490d3f84b09d002ab5c2983127dc9bd372e2047c925ceb9c'},
                                    [...] More information 
 'ref': '8336aa904697b4358d1c84f495c5e90114b4906182715a56afd2dc5c10837be5',
 'time': 1709026357.038,
 'type': 'amend'}