Skip to main content

salesforce-python

salesforce-python is an API wrapper for Salesforce written in Python

Installing

pip install salesforce-python

Usage

from salesforce.client import Client

client = Client('CLIENT_KEY', 'CLIENT_SECRET', 'https://na50.salesforce.com/', 'v41.0') # Host must have trailing slash

Get authorization url

url = client.authorization_url('REDIRECT_URI')

Exchange the code for a token

token = client.exchange_code('REDIRECT_URI', 'CODE')

Set the token

client.set_access_token('TOKEN')

Refresh the token

new_token = client.refresh_token()

Get user information

user = client.get_user_info()

Get API versions

user = client.get_versions()

Get all resources by the version specified in the client instantiation.

versions = client.get_versions()

Get all objects described

metadata = client.get_describe_global()

Get an object

object = client.get_sobject('Lead)

Create an object

data = {'LastName': 'Doe', 'IsConverted': 'False', 'Status': 'Open - Not Contacted', 'IsUnreadByOwner': 'False', 'Company': 'NA', 'FirstName': 'John'}
response = client.create_sobject('Lead', data)

Get an object described

metadata = client.get_sobject_describe('Lead')

Webhooks

In order to create a webhook in Salesforce we need to create an APEX Class, Remote Site and Apex Trigger.

Create the APEX Class

In this example we are going to read the apex_class.txt file in the files folder included in this repository:

with open(os.path.join('/path/to/apex_class.txt'), 'r') as file:
    body = file.read()

response = client.create_apex_class('WebhookClass', body)

Create the Remote Site

URL is a string with the domain of your site:

url = 'https://mywebsite.com/'
response = client.create_remote_site('RemoteSiteSetting', url)

Create the APEX Trigger

To create the Trigger, we are going to read the apex_trigger.txt file and replace some values.

with open(os.path.join('/path/to/apex_trigger.txt'), 'r') as file:
    body = file.read()

sobject = 'User'
event = 'after insert'
url = 'https://mywebsite.com/notification_url/' #This is the domain url + your webhook path

body = body.replace('{sobject}', sobject)
body = body.replace('{events}', event)
body = body.replace('{url}', "'" + url + "'")

response = client.create_apex_trigger('WebhookTrigger', body, sobject)

That's all, you should receive notifications every time you create a new user in your Salesforce dashboard.

Requirements

  • requests

Contributing

We are always grateful for any kind of contribution including but not limited to bug reports, code enhancements, bug fixes, and even functionality suggestions.

You can report any bug you find or suggest new functionality with a new issue.

If you want to add yourself some functionality to the wrapper:

  1. Fork it ( https://github.com/GearPlug/salesforce-python )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Adds my new feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Metadata

Release files for salesforce-python 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for salesforce-python 0.3.5
File Size Uploaded Provenance Actions
salesforce_python-0.3.5.tar.gz 4.7 kB Without provenance Details for salesforce_python-0.3.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for salesforce-python 0.3.5
File Interpreter ABI Platform Actions
salesforce_python-0.3.5-py3-none-any.whl Python 3 none any Details for salesforce_python-0.3.5-py3-none-any.whl

Total release size: 10.5 kB

Release files / salesforce_python-0.3.5.tar.gz

Download URL salesforce_python-0.3.5.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
23627f3adef8f519ca13b060873c618f72b30176f457c4acd55618f0e91985cf
BLAKE2b-256 checksum
How to use checksums
9ca453932a1cf2875aa25650bf197d8ebcbc5e787cad802bf0c68bc2e941d521
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Release files / salesforce_python-0.3.5-py3-none-any.whl

Download URL salesforce_python-0.3.5-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0be56b0194e603239c8ccd74c1b66730354e441d5a0e01afa70bb7991500ef2
BLAKE2b-256 checksum
How to use checksums
a3d92ee0796f3fc8fdc738e1843241a8302b1f8f83680e7b1b1f5a50ccd2c238
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.9

Security for salesforce-python 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page