belvo.resources.base

  1from typing import Dict, Generator, List, Union
  2
  3from belvo.http import APISession
  4
  5
  6class Resource:
  7    endpoint: str
  8
  9    def __init__(self, session: APISession) -> None:
 10        self._session = session
 11
 12    @property
 13    def session(self) -> APISession:
 14        return self._session
 15
 16    def list(self, **kwargs) -> Generator:
 17        """# **List all items for the given resource.**
 18
 19        With the `.list()` method, you can list all items for a given resource. You can additionally add filters to your method in order to only retrieve results matching your query. If you don't provide any filters, we return all items for that resource.
 20
 21        Example:
 22
 23        ```
 24        # Retrieve all accounts (no filter given)
 25        accounts = client.Accounts.list()
 26
 27        # Retrieve accounts for a specific bank
 28        accounts = client.Accounts.list(institution="erebor_mx_retail")
 29
 30
 31        # Retrieve all checking accounts with an available balance >= 100
 32        accounts = client.Accounts.list(type__in="checking", balance_available__gte=100)
 33
 34        ```
 35
 36        You can find the filters, along with examples, that you can apply per resource by checking our API reference documentation. For example, if you want to see the filters you can apply to the Links resource, then see our [List all links documentation](https://developers.belvo.com/reference/listlinks).
 37
 38        Returns:
 39            _type_: _description_
 40
 41        Yields:
 42            Generator: _description_
 43        """
 44        endpoint = self.endpoint
 45        return self.session.list(endpoint, params=kwargs)
 46
 47    def get(self, id: str, **kwargs) -> Dict:
 48        """#Get the details for a specific object
 49
 50        Args:
 51            id (str): The ID of the item you want to get details for (UUID).
 52
 53        Returns:
 54            Dict: The details of the object.
 55        """
 56        return self.session.get(self.endpoint, id, params=kwargs)
 57
 58    def delete(self, id: str) -> bool:
 59        """# Delete an item from the Belvo API.
 60
 61        Note: If you delete an account object, all associated transactions and owners are also deleted from your Belvo account.
 62
 63        Example:
 64
 65        ```
 66        # Deleting an account
 67        client.Accounts.delete("161a5e4d-67f5-4760-ae4f-c1fe85cb20ca")
 68
 69        ```
 70
 71        Args:
 72            id (str): The id of the object to delete.
 73
 74        Returns:
 75            bool: Returns `True` if the object was deleted.
 76        """
 77        return self.session.delete(self.endpoint, id)
 78
 79    def resume(
 80        self, session: str, token: str, *, link: str = None, raise_exception: bool = False, **kwargs
 81    ) -> Union[List[Dict], Dict]:
 82        """# Resume a resource sessions
 83
 84        Example:
 85
 86        ```
 87        # Login to Belvo API
 88        client = Client("Secret Key ID", "Secret Key PASSWORD", "sandbox")
 89
 90        # Resume a link
 91        link = client.Links.resume(
 92          session="session_id",
 93          token="token",
 94          link="link_id"
 95        )
 96
 97        ```
 98
 99        Args:
100            session (str): The session you want to resume (UUID).
101            token (str): The MFA token required to continue the session.
102            link (str, optional): The Link ID . Defaults to None.
103            raise_exception (bool, optional): Boolean indicating whether to return an API error or to raise an exception. Defaults to False.
104
105        Returns:
106            Union[List[Dict], Dict]: On success, returns the resource data requests.
107        """
108
109        data = {"session": session, "token": token}
110
111        if link is not None:
112            data.update(link=link)
113
114        return self.session.patch(
115            self.endpoint, data=data, raise_exception=raise_exception, **kwargs
116        )
class Resource:
  7class Resource:
  8    endpoint: str
  9
 10    def __init__(self, session: APISession) -> None:
 11        self._session = session
 12
 13    @property
 14    def session(self) -> APISession:
 15        return self._session
 16
 17    def list(self, **kwargs) -> Generator:
 18        """# **List all items for the given resource.**
 19
 20        With the `.list()` method, you can list all items for a given resource. You can additionally add filters to your method in order to only retrieve results matching your query. If you don't provide any filters, we return all items for that resource.
 21
 22        Example:
 23
 24        ```
 25        # Retrieve all accounts (no filter given)
 26        accounts = client.Accounts.list()
 27
 28        # Retrieve accounts for a specific bank
 29        accounts = client.Accounts.list(institution="erebor_mx_retail")
 30
 31
 32        # Retrieve all checking accounts with an available balance >= 100
 33        accounts = client.Accounts.list(type__in="checking", balance_available__gte=100)
 34
 35        ```
 36
 37        You can find the filters, along with examples, that you can apply per resource by checking our API reference documentation. For example, if you want to see the filters you can apply to the Links resource, then see our [List all links documentation](https://developers.belvo.com/reference/listlinks).
 38
 39        Returns:
 40            _type_: _description_
 41
 42        Yields:
 43            Generator: _description_
 44        """
 45        endpoint = self.endpoint
 46        return self.session.list(endpoint, params=kwargs)
 47
 48    def get(self, id: str, **kwargs) -> Dict:
 49        """#Get the details for a specific object
 50
 51        Args:
 52            id (str): The ID of the item you want to get details for (UUID).
 53
 54        Returns:
 55            Dict: The details of the object.
 56        """
 57        return self.session.get(self.endpoint, id, params=kwargs)
 58
 59    def delete(self, id: str) -> bool:
 60        """# Delete an item from the Belvo API.
 61
 62        Note: If you delete an account object, all associated transactions and owners are also deleted from your Belvo account.
 63
 64        Example:
 65
 66        ```
 67        # Deleting an account
 68        client.Accounts.delete("161a5e4d-67f5-4760-ae4f-c1fe85cb20ca")
 69
 70        ```
 71
 72        Args:
 73            id (str): The id of the object to delete.
 74
 75        Returns:
 76            bool: Returns `True` if the object was deleted.
 77        """
 78        return self.session.delete(self.endpoint, id)
 79
 80    def resume(
 81        self, session: str, token: str, *, link: str = None, raise_exception: bool = False, **kwargs
 82    ) -> Union[List[Dict], Dict]:
 83        """# Resume a resource sessions
 84
 85        Example:
 86
 87        ```
 88        # Login to Belvo API
 89        client = Client("Secret Key ID", "Secret Key PASSWORD", "sandbox")
 90
 91        # Resume a link
 92        link = client.Links.resume(
 93          session="session_id",
 94          token="token",
 95          link="link_id"
 96        )
 97
 98        ```
 99
100        Args:
101            session (str): The session you want to resume (UUID).
102            token (str): The MFA token required to continue the session.
103            link (str, optional): The Link ID . Defaults to None.
104            raise_exception (bool, optional): Boolean indicating whether to return an API error or to raise an exception. Defaults to False.
105
106        Returns:
107            Union[List[Dict], Dict]: On success, returns the resource data requests.
108        """
109
110        data = {"session": session, "token": token}
111
112        if link is not None:
113            data.update(link=link)
114
115        return self.session.patch(
116            self.endpoint, data=data, raise_exception=raise_exception, **kwargs
117        )
Resource(session: belvo.http.APISession)
10    def __init__(self, session: APISession) -> None:
11        self._session = session
endpoint: str
def list(self, **kwargs) -> Generator:
17    def list(self, **kwargs) -> Generator:
18        """# **List all items for the given resource.**
19
20        With the `.list()` method, you can list all items for a given resource. You can additionally add filters to your method in order to only retrieve results matching your query. If you don't provide any filters, we return all items for that resource.
21
22        Example:
23
24        ```
25        # Retrieve all accounts (no filter given)
26        accounts = client.Accounts.list()
27
28        # Retrieve accounts for a specific bank
29        accounts = client.Accounts.list(institution="erebor_mx_retail")
30
31
32        # Retrieve all checking accounts with an available balance >= 100
33        accounts = client.Accounts.list(type__in="checking", balance_available__gte=100)
34
35        ```
36
37        You can find the filters, along with examples, that you can apply per resource by checking our API reference documentation. For example, if you want to see the filters you can apply to the Links resource, then see our [List all links documentation](https://developers.belvo.com/reference/listlinks).
38
39        Returns:
40            _type_: _description_
41
42        Yields:
43            Generator: _description_
44        """
45        endpoint = self.endpoint
46        return self.session.list(endpoint, params=kwargs)

List all items for the given resource.

With the .list() method, you can list all items for a given resource. You can additionally add filters to your method in order to only retrieve results matching your query. If you don't provide any filters, we return all items for that resource.

Example:

# Retrieve all accounts (no filter given)
accounts = client.Accounts.list()

# Retrieve accounts for a specific bank
accounts = client.Accounts.list(institution="erebor_mx_retail")


# Retrieve all checking accounts with an available balance >= 100
accounts = client.Accounts.list(type__in="checking", balance_available__gte=100)

You can find the filters, along with examples, that you can apply per resource by checking our API reference documentation. For example, if you want to see the filters you can apply to the Links resource, then see our List all links documentation.

Returns:

_type_: _description_

Yields:

Generator: _description_

def get(self, id: str, **kwargs) -> Dict:
48    def get(self, id: str, **kwargs) -> Dict:
49        """#Get the details for a specific object
50
51        Args:
52            id (str): The ID of the item you want to get details for (UUID).
53
54        Returns:
55            Dict: The details of the object.
56        """
57        return self.session.get(self.endpoint, id, params=kwargs)

Get the details for a specific object

Arguments:
  • id (str): The ID of the item you want to get details for (UUID).
Returns:

Dict: The details of the object.

def delete(self, id: str) -> bool:
59    def delete(self, id: str) -> bool:
60        """# Delete an item from the Belvo API.
61
62        Note: If you delete an account object, all associated transactions and owners are also deleted from your Belvo account.
63
64        Example:
65
66        ```
67        # Deleting an account
68        client.Accounts.delete("161a5e4d-67f5-4760-ae4f-c1fe85cb20ca")
69
70        ```
71
72        Args:
73            id (str): The id of the object to delete.
74
75        Returns:
76            bool: Returns `True` if the object was deleted.
77        """
78        return self.session.delete(self.endpoint, id)

Delete an item from the Belvo API.

Note: If you delete an account object, all associated transactions and owners are also deleted from your Belvo account.

Example:

# Deleting an account
client.Accounts.delete("161a5e4d-67f5-4760-ae4f-c1fe85cb20ca")

Arguments:
  • id (str): The id of the object to delete.
Returns:

bool: Returns True if the object was deleted.

def resume( self, session: str, token: str, *, link: str = None, raise_exception: bool = False, **kwargs) -> Union[List[Dict], Dict]:
 80    def resume(
 81        self, session: str, token: str, *, link: str = None, raise_exception: bool = False, **kwargs
 82    ) -> Union[List[Dict], Dict]:
 83        """# Resume a resource sessions
 84
 85        Example:
 86
 87        ```
 88        # Login to Belvo API
 89        client = Client("Secret Key ID", "Secret Key PASSWORD", "sandbox")
 90
 91        # Resume a link
 92        link = client.Links.resume(
 93          session="session_id",
 94          token="token",
 95          link="link_id"
 96        )
 97
 98        ```
 99
100        Args:
101            session (str): The session you want to resume (UUID).
102            token (str): The MFA token required to continue the session.
103            link (str, optional): The Link ID . Defaults to None.
104            raise_exception (bool, optional): Boolean indicating whether to return an API error or to raise an exception. Defaults to False.
105
106        Returns:
107            Union[List[Dict], Dict]: On success, returns the resource data requests.
108        """
109
110        data = {"session": session, "token": token}
111
112        if link is not None:
113            data.update(link=link)
114
115        return self.session.patch(
116            self.endpoint, data=data, raise_exception=raise_exception, **kwargs
117        )

Resume a resource sessions

Example:

# Login to Belvo API
client = Client("Secret Key ID", "Secret Key PASSWORD", "sandbox")

# Resume a link
link = client.Links.resume(
  session="session_id",
  token="token",
  link="link_id"
)

Arguments:
  • session (str): The session you want to resume (UUID).
  • token (str): The MFA token required to continue the session.
  • link (str, optional): The Link ID . Defaults to None.
  • raise_exception (bool, optional): Boolean indicating whether to return an API error or to raise an exception. Defaults to False.
Returns:

Union[List[Dict], Dict]: On success, returns the resource data requests.