Backbench Docs
  • Introduction
  • Getting Started
    • BBLANG
    • Node
    • Python
    • Go
  • Backbench Features and UI workflow
  • API Reference
    • BBLANG
    • Node
    • Python
    • Go
  • 3rd Party Integrations
    • Login using Facebook
    • Login using Google
    • Login with Twitter
    • Login using LinkedIn
    • Connection with MongoDB
    • Connection with MySQL
    • Geo Location Integration
    • Integration with AWS S3
    • Integration with Google Cloud Storage
    • Integration with Razorpay
    • Integration with Stripe
    • Integration with Mailchimp
    • Integration with Segment
    • Sending Emails with SendGrid
    • Sending Emails with Mailgun
    • Sending SMS with Twilio
    • Sending Push Notification with Pushwoosh
  • Troubleshooting and support
    • CNAME Support
    • FAQS
    • Error Codes
  • Testing
Powered by GitBook
On this page
  • REST API
  • Helper Library
  1. API Reference

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)

my_utils.py

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
PreviousNodeNextGo

Last updated 6 years ago