# Python

### REST API

See root documentation of API Reference.

## Helper Library

You can reuse this library for dealing with `memory` and `log`. (import in original code)

{% code title="my\_utils.py" %}

```python
import requests
import os
import json

base_url = "https://memory.backbench.io/"
user = os.environ['benchName'].split(":")

data = {
    "cmd": "",
    "auth": {
        "userId": user[0],
        "benchId":user[1],
        "accessKey": os.environ['ACCESS_KEY'] 
     },
    "args": {}
}

def get(key):
    temp = data
    temp["cmd"] = "bb:mem:get"
    temp["args"] = {"key": key}
    res = requests.post(base_url, json=temp)
    temp = res.json()
    if "errorMessage" in temp:
        return None
    return temp['reply']

def set(key, value):
    temp = data
    temp["cmd"] = "bb:mem:set"
    temp["args"] = {"key": key, "value": value}
    res = requests.post(base_url, json=temp)
    return True

def delete(key):
    temp = data
    temp["cmd"] = "bb:mem:del"
    temp["args"] = {"key": key}
    res = requests.post(base_url, json=temp)
    return True

def log(msg):
    temp = data
    temp["cmd"] = "bb:log"
    temp["args"] = {"message": msg}
    res = requests.post(base_url, json=temp)
    return True
```

{% 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/api-reference/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.
