# Python

Supports: **python3.7**

## Function declaration

{% code title="hello.py" %}

```python
def endpoint(req):
    return "Hello World"
```

{% endcode %}

**Public function** should be named as **endpoint** within a module.

**Argument `req`** is a map, and has following properties:

```
{  
    "method": "",  
    "path": "",  
    "body": {},  
    "headers": {},
    "query": {} 
}
```

**NOTE:** Always return *string*. For RUNTIME ERRORS check dashboard.

## Restrictions

* Module name cannot be `func.py`.

## Example

This is an example for couting no of times API has been accessed. For `utils.py`, see API Reference of python.

{% code title="hello.py" %}

```python
from utils.py import get, set, log 
#for utils.py look at API reference- Python

def endpoint(req):
    count = get("count")
    if count==None:
        count = 0
    else: 
        count = str(count)
        count = count + 1
    set("count", str(count))
    log("visit count of the API is "+str(count))
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://backbench.gitbook.io/backbench-docs/getting-started/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
