functional components
Functional components are the programatic components that are available to the fury system. These are mostly for demo examples, we expect the user to register their unique components into programatic_action_registry.
- chainfury.components.functional.call_api_requests(method: str, url: str, params: Dict[str, str] = {}, data: Dict[str, str] = {}, json: Dict[str, str] = {}, headers: Dict[str, str] = {}, cookies: Dict[str, str] = {}, auth: Dict[str, str] = {}, timeout: float = 0, *, max_retries: int = 3, retry_delay: int = 1) Tuple[Tuple[str, int], Exception | None] [source]
Call an API using the python requests library. You can use this for any API that you want to call.
- Parameters:
method (str) – The HTTP method to use.
url (str) – The URL to call.
params (Dict[str, str], optional) – The query parameters. Defaults to {}.
data (Dict[str, str], optional) – The data to send. Defaults to {}.
json (Dict[str, str], optional) – The JSON to send. Defaults to {}.
headers (Dict[str, str], optional) – The headers to send. Defaults to {}.
cookies (Dict[str, str], optional) – The cookies to send. Defaults to {}.
auth (Dict[str, str], optional) – The auth to send. Defaults to {}.
timeout (float, optional) – The timeout in seconds. Defaults to 0.
max_retries (int, optional) – The number of times to retry the request. Defaults to 3.
retry_delay (int, optional) – The number of seconds to wait between retries. Defaults to 1.
- Returns:
The response text and status code, and the exception if there was one.
- Return type:
Tuple[Tuple[str, int], Optional[Exception]]
- chainfury.components.functional.json_translator(data: str | Dict[str, str], resolver: Dict[str, str], default: str = '', return_only_value: bool = False) Tuple[str, Exception | None] [source]
This simple function takes a json string or a python dictionary and translates it to the required output defined by the resolver. It is a dictionary that tells the location of the output that you want and the target locations. Here is a simple example on how you can use this:
>>> x = { ... "a": { ... "b": [1, 2, 3], ... "c": { ... "d": "hello", ... "e": "world", ... } ... }, ... "f": "foo", ... } >>> resolver = { ... "x": ["a", "b", 0], ... "y": ["a", "c", "d"], ... "z": ["f"], ... } >>> json_translator(x, resolver) >>> { ... "x": 1, ... "y": "hello", ... "z": "foo", ... }
Note
If you pass return_only_value=True, then the output will be the value of the first key in the resolver. See below for an example:
>>> json_translator(x, resolver, return_only_value=True) >>> 1
- Parameters:
data (Union[str, Dict[str, Any]]) – The data to be processed
resolver (Dict[str, str], optional) – The resolver dictionary. Defaults to {}.
default (str, optional) – The default value to be returned if the resolver fails. Defaults to “”.
return_only_value (bool, optional) – If True, only the value is returned. Defaults to False.
- Returns:
The output and the exception if any
- Return type:
Tuple[str, Optional[Exception]]
- chainfury.components.functional.regex_search(pattern: str, text: str) Tuple[List[str], Exception | None] [source]
Perform a regex search on the text and get items in an array
- Parameters:
pattern (str) – The regex pattern to search for
text (str) – The text to search in
- Returns:
The list of items found
- Return type:
Tuple[List[str], Optional[Exception]]
- chainfury.components.functional.regex_substitute(pattern: str, repl: str, text: str) Tuple[str, Exception | None] [source]
Perform a regex substitution on the text and get the result
- Parameters:
pattern (str) – The regex pattern to search for
repl (str) – The replacement string
text (str) – The text to search in
- Returns:
The substituted text and the exception if there was one
- Return type:
Tuple[str, Optional[Exception]]