I tried to create a sample to access Salesforce using Python and Bottle

I've recently started learning Python personally, so I wondered if I could use Salesforce from Python.

What to use

The following was used to create this sample

To supplement a little

Bottle

A framework for creating web applications in Python. Other frameworks for creating web applications in Python include Django. Bottle is a lightweight framework among them, and it is said that the minimum necessary items are available, so I chose it.

virtualenv

A library that creates a virtual environment for Python. As an image, it may be similar to creating a virtual environment with Virtualbox and Vagrant.

simple-salesforce

A module for operating Salesforce from Python. Looking at the official documentation, it seems like you're hitting the REST API.

Implementation

There is only a minimum of implementation

index.tpl


<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>Bottle Index template</title>
  </head>
  <body>
    <h1>{{msg}}</h1>
    <h2></h2>
    <form action="" method="post">
      <input type="text" name="username" placeholder="Username" />
      <input type="password" name="password" placeholder="Password" />
      <input type="password" name="security_token" placeholder="SecurityToken" />
      <input type="submit" value="Login" />
    </form>
  </body>
</html>

index.py


from bottle import route, run, template, request
from simple_salesforce import Salesforce

@route('/')
def index(msg='This page is home page.'):
    return template('index', msg=msg)

@route('/', method=["POST"])
def login_salesforce():
    uname = request.POST.getunicode("username")
    upw   = request.POST.getunicode("password")
    token = request.POST.getunicode("security_token")
    try:
        sf = Salesforce(username=uname, password=upw, security_token=token)
        return template("login_success")
    except Exception as e:
        return template("login_error")
    finally:
        print("Login process completed")

run(host='localhost', port=8080, debug=True, reloader=True)

It's really just the bare minimum. It will be added as needed in the future.

The source at this stage is on Github's BottleSalesforceEnv.

Recommended Posts

I tried to create a sample to access Salesforce using Python and Bottle
I tried to make a todo application using bottle with python
I tried to access Google Spread Sheets using Python
I tried to make a stopwatch using tkinter in python
I tried to create a linebot (implementation)
I tried to create a linebot (preparation)
I tried to make a regular expression of "amount" using Python
I tried to create a list of prime numbers with python
I tried to make a regular expression of "date" using Python
I tried to make a periodical process with Selenium and Python
I tried to create Bulls and Cows with a shell program
I made a server with Python socket and ssl and tried to access it from a browser
I want to create a karaoke sound source by separating instruments and vocals using Python
I tried web scraping using python and selenium
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
I tried object detection using Python and OpenCV
I want to create a window in Python
Create a web map using Python and GDAL
I tried reading a CSV file using Python
Create a Mac app using py2app and Python3! !!
Start a web server using Bottle and Flask (I also tried using Apache)
I tried to make a ○ ✕ game using TensorFlow
I want to make a web application using React and Python flask
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to create a class that can easily serialize Json in Python
[Python] Deep Learning: I tried to implement deep learning (DBN, SDA) without using a library.
When I tried to create a virtual environment with Python, it didn't work
Python programming: I tried to get (crawling) news articles using Selenium and BeautifulSoup4.
I tried to easily create a fully automatic attendance system with Selenium + Python
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to create a table only with Django
I made a login / logout process using Python Bottle.
I tried to draw a route map with Python
I tried hosting a Pytorch sample model using TorchServe
I want to randomly sample a file in Python
I tried to automatically generate a password with Python3
[Python] I tried running a local server using flask
I tried drawing a pseudo fractal figure using Python
I tried using Python (3) instead of a scientific calculator
Python: I tried a liar and an honest tribe
I tried to draw a configuration diagram using Diagrams
[Python] I tried using OpenPose
[Python + Bottle] I tried to release a web service that visualizes Twitter's positioned tweets.
I tried scraping food recall information with Python to create a pandas data frame
I tried to implement a one-dimensional cellular automaton in Python
I tried to automatically create a report with Markov chain
I tried to get Web information using "Requests" and "lxml"
[Markov chain] I tried to read a quote into Python.
I tried "How to get a method decorated in Python"
I tried to automate [a certain task] using Raspberry Pi
I tried to enumerate the differences between java and python
I tried to create a bot for PES event notification
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to make a simple text editor using PyQt
I made a Chatbot using LINE Messaging API and Python
I tried to output the access log to the server using Node.js
I tried to create Quip API
I made a Line-bot using Python!
I tried to touch Python (installation)
I tried to create a RESTful API by connecting the explosive Python framework FastAPI to MySQL.
Create a python GUI using tkinter