In part 1 of the simple-salesforce tutorial series, we are going to learn how to use simple-salesforce Python library to work with Salesforce.

Simple-Salesforce is a lightweight Python library designed to provide an easy solution to work with Salesforce REST API. This tutorial is divided into three parts. In part 1 of the tutorial, we are going to learn how to:

  1. create a #Python virutal environment dedicated to development project
  2. install simple-salesforce library
  3. how to connect to #Salesforce using simple-salesforce
  4. how to create a Salesforce instance to access Salesforce REST API features, and
  5. retrieve your #Salesforce org information.

Buy Me a Coffee? Your support is much appreciated!
PayPal Me:
Venmo: @Jie-Jenn

Source Code:

import json
import pandas as pd
from simple_salesforce import Salesforce, SalesforceLogin, SFType

loginInfo = json.load(open('login.json'))
username = loginInfo['username']
password = loginInfo['password']
security_token = loginInfo['security_token']
domain = 'login'

# sf = Salesforce(username=username, password=password, security_token=security_token, domain=domain)

session_id, instance = SalesforceLogin(username=username, password=password, security_token=security_token, domain=domain)
sf = Salesforce(instance=instance, session_id=session_id)

for element in dir(sf):
    if not element.startswith('_'):
        if isinstance(getattr(sf, element), str):
            print('Property Name:{0} ;Value: {1}'.format(element, getattr(sf, element)))

metadata_org = sf.describe()
df_sobjects = pd.DataFrame(metadata_org['sobjects'])
df_sobjects.to_csv('org metadata info.csv', index=False)

# method 1
project__c = sf.Project__c
metadata_project = project__c.metadata()
df_project_metadata = pd.DataFrame(metadata_project.get('objectDescribe'))
df_project_metadata.to_csv('project metadata.csv', index=False)

# method 2
account = SFType('account', session_id, instance)
account_metadata = account.metadata()
df_account_metadata = pd.DataFrame(account_metadata.get('objectDescribe'))
df_account_metadata.to_csv('account metadata.csv', index=False)