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
  • Function declaration
  • Restrictions
  • Example
  1. Getting Started

Python

Supports: python3.7

Function declaration

hello.py

def endpoint(req):
    return "Hello World"

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.

hello.py
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))
PreviousNodeNextGo

Last updated 6 years ago