AARS
The AARS class is the main entry point for the Aleph Active Record SDK. It provides versatile methods to create, update, delete and query records.
Initializes the SDK with an account and a channel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
account |
Optional[Account]
|
Account with which to sign the messages. Defaults to the fallback account. |
None
|
channel |
Optional[str]
|
Channel to which to send the messages. Defaults to ‘AARS_TEST’. |
None
|
api_url |
Optional[str]
|
The API URL to use. Defaults to an official Aleph API host. |
None
|
session |
Optional[AuthenticatedAlephClient]
|
An aiohttp session to use. Defaults to a new session with the given account. |
None
|
cache |
Optional[VmCache]
|
An optional Aleph VM cache to cache messages. |
None
|
retry_count |
Optional[int]
|
The number of times to retry a failed request. Defaults to 3. |
None
|
Source code in aars/core.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
|
fetch_exact(record_type: Type[R], item_hash: str) -> R
classmethod
async
Retrieves the revision of an object by its item_hash of the message. The content will be exactly the same as in the referenced message, so no amendments will be applied.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record_type |
Type[R]
|
The type of the object to retrieve. |
required |
item_hash |
str
|
item_hash of the message, whose content to fetch. |
required |
Returns:
Type | Description |
---|---|
R
|
The record in the state it was when the message was created. |
Source code in aars/core.py
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
|
fetch_records(record_type: Type[R], item_hashes: Optional[List[Union[str, ItemHash]]] = None, channel: Optional[str] = None, owner: Optional[str] = None, page_size: int = 50, page: int = 1) -> AsyncIterator[R]
classmethod
async
Retrieves posts as objects by its aleph item_hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record_type |
Type[R]
|
The type of the objects to retrieve. |
required |
item_hashes |
Optional[List[Union[str, ItemHash]]]
|
Aleph item_hashes of the objects to fetch. |
None
|
channel |
Optional[str]
|
Channel in which to look for it. |
None
|
owner |
Optional[str]
|
Account that owns the object. |
None
|
page_size |
int
|
Number of items to fetch per page. |
50
|
page |
int
|
Page number to fetch, based on page_size. |
1
|
Returns:
Type | Description |
---|---|
AsyncIterator[R]
|
An iterator over the found records. |
Source code in aars/core.py
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 |
|
fetch_revisions(record_type: Type[R], ref: str, channel: Optional[str] = None, owner: Optional[str] = None, page = 1) -> AsyncIterator[ItemHash]
classmethod
async
Retrieves posts of revisions of an object by its item_hash.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record_type |
Type[R]
|
The type of the objects to retrieve. |
required |
ref |
str
|
item_hash of the object, whose revisions to fetch. |
required |
channel |
Optional[str]
|
Channel in which to look for it. |
None
|
owner |
Optional[str]
|
Account that owns the object. |
None
|
page |
Page number to fetch. |
1
|
Returns:
Type | Description |
---|---|
AsyncIterator[ItemHash]
|
An iterator over the found records. |
Source code in aars/core.py
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
|
forget_objects(objs: List[R], channel: Optional[str] = None)
classmethod
async
Forgets multiple objects from Aleph and local cache. All related revisions will be forgotten too.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
objs |
List[R]
|
The objects to forget. |
required |
channel |
Optional[str]
|
The channel to delete the object from. If None, will use the configured default channel. |
None
|
Source code in aars/core.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 |
|
post_or_amend_object(obj: R, channel: Optional[str] = None) -> R
classmethod
async
Posts or amends an object to Aleph. If the object is already posted, it’s list of revision hashes is updated and the object receives the latest revision number.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
R
|
The object to post or amend. |
required |
channel |
Optional[str]
|
The channel to post the object to. If None, will use the configured default channel. |
None
|
Returns:
Type | Description |
---|---|
R
|
The object with the updated revision hashes and revision number. |
Source code in aars/core.py
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
|
sync_indices()
classmethod
async
Synchronizes all the indices created so far, by iteratively fetching all the messages from the channel, having post_types of the Record subclasses that have been declared so far.
This can take quite some time on large databases.
Source code in aars/core.py
631 632 633 634 635 636 637 638 639 640 641 |
|