***

title: Helper Functions
sidebar-title: helpers
slug: /reference/python/agents/data-map/helper-functions
description: Convenience functions for creating common DataMap patterns.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[ref-datamap]: /docs/server-sdks/reference/python/agents/data-map

[ref-functionresult]: /docs/server-sdks/reference/python/agents/function-result

```python
from signalwire import create_simple_api_tool
```

Create a DataMap for a straightforward single-endpoint API call with minimal
configuration.

## **Parameters**

<ParamField path="name" type="str" required={true} toc={true}>
  Function name.
</ParamField>

<ParamField path="url" type="str" required={true} toc={true}>
  API endpoint URL.
</ParamField>

<ParamField path="response_template" type="str" required={true} toc={true}>
  Template string for formatting the response.
</ParamField>

<ParamField path="parameters" type="dict[str, dict]" toc={true}>
  Parameter definitions. Keys are parameter names, values are dicts with
  `"type"`, `"description"`, and optional `"required"` keys.
</ParamField>

<ParamField path="method" type="str" default="GET" toc={true}>
  HTTP method.
</ParamField>

<ParamField path="headers" type="dict[str, str]" toc={true}>
  HTTP headers.
</ParamField>

<ParamField path="body" type="dict[str, Any]" toc={true}>
  Request body for POST/PUT.
</ParamField>

<ParamField path="error_keys" type="list[str]" toc={true}>
  Keys indicating an error response.
</ParamField>

## **Returns**

[`DataMap`][ref-datamap] -- A fully configured DataMap ready for further chaining or conversion.

***

```python
from signalwire import create_expression_tool
```

Create a DataMap for pattern-matching responses without API calls.

## **Parameters**

<ParamField path="name" type="str" required={true} toc={true}>
  Function name.
</ParamField>

<ParamField path="patterns" type="dict[str, tuple[str, FunctionResult]]" required={true} toc={true}>
  Dictionary mapping test values to `(pattern, [FunctionResult][ref-functionresult])` tuples.
</ParamField>

<ParamField path="parameters" type="dict[str, dict]" toc={true}>
  Parameter definitions (same format as `create_simple_api_tool`).
</ParamField>

## **Returns**

`DataMap` -- A fully configured DataMap.

## **Example**

```python
from signalwire import AgentBase
from signalwire import create_simple_api_tool, create_expression_tool
from signalwire import FunctionResult

# Simple API tool -- one line instead of a full DataMap chain
weather = create_simple_api_tool(
    name="get_weather",
    url="https://api.weatherapi.com/v1/current.json?key=KEY&q=${enc:args.city}",
    response_template="Weather in ${args.city}: ${response.current.condition.text}",
    parameters={
        "city": {"type": "string", "description": "City name", "required": True}
    },
    error_keys=["error"]
)

# Expression tool -- pattern matching without API calls
greeting = create_expression_tool(
    name="greet",
    patterns={
        "${args.language}": (r"spanish|espanol", FunctionResult("Hola!")),
    },
    parameters={
        "language": {"type": "string", "description": "Language to greet in"}
    }
)

agent = AgentBase(name="helper-demo")
agent.set_prompt_text("You are a helpful assistant.")
agent.register_swaig_function(weather.to_swaig_function())
agent.register_swaig_function(greeting.to_swaig_function())

if __name__ == "__main__":
    agent.run()
```