Skip to main content

SalesPyForce

A Python toolset for performing Salesforce API calls

Latest Stable Release PyPI
Latest Beta/RC Release PyPI
Build Status GitHub Workflow Status
Supported Versions PyPI - Supported Python Versions
Code Coverage Code Coverage Badge
Documentation Documentation Status
Security Audits Bandit
License License (GitHub)
Issues GitHub open issues
GitHub closed issues
Pull Requests GitHub pull open requests
GitHub closed pull requests

Overview

salespyforce is a Python toolkit focused on interacting with Salesforce APIs, with a primary Salesforce class that centralizes authentication, version selection, and access to helper feature sets (Chatter, Knowledge).

Installation

The package can be installed via pip using the syntax below.

pip install salespyforce --upgrade

Development and Testing

For local development, this repository uses split test directories: tests/unit/ and tests/integration/.

poetry install
poetry run pytest -q

Development Quality Checks

This repository uses Ruff for linting, import sorting, and formatting. The standard maximum line length for this package is 130 characters.

Line-length exceptions should be rare and limited to comments or special cases where wrapping harms readability. When an exception is required, use a targeted per-line # noqa: E501 comment.

poetry run ruff check .
poetry run ruff check . --fix
poetry run ruff format .
poetry run ruff format --check .

These checks are enforced in CI via .github/workflows/ci.yml.

Changelog

The changelog can be found in the documentation for the stable and latest versions.

Usage

This section provides basic usage instructions for the package.

Importing the package

Rather than importing the base package, it is recommended that you import the primary Salesforce class using the syntax below.

from salespyforce import Salesforce

Initializing a Salesforce object instance

The primary Salesforce object serves many purposes, the most important being to establish a connection to the Salesforce environment with which you intend to interact. As such, when initializing an instance of the Salesforce object, you will need to pass it the following information:

  • The username and password of the API user
  • The Organization ID of the Salesforce environment
  • The Base URL and Endpoint URL
  • The client ID, client secret, and security token

The Salesforce object can be initiated in two different ways:

  • Passing the information directly into the object
  • Leveraging a "helper" configuration file

Passing the information directly into the object

The environment and connection information can be passed directly into the Salesforce object when initializing it, as demonstrated in the example below.

sfdc = Salesforce(
    username='admin.user@example.com',
    password='example123',
    org_id='4DJ000000CeMFYA0',
    base_url='https://example-dev-ed.lightning.force.com/',
    endpoint_url='https://example-dev-ed.my.salesforce.com/services/oauth2/token',
    client_id='3MVG9gTv.DiE8cKRIpEtSN_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_TAoy1Zk_AKGukbqa4KbhM6nVYVUu6md',
    client_secret='7536F4A7865559XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX53797BEA88174713CC3C',
    security_token='2muXaXXXXXXXXXXXXXXXoVKxz'
)

Leveraging a "helper" configuration file

As an alternative to passing the connection information to the Salesforce class in the way demonstrated above, a "helper" configuration file in yaml or json format can be leveraged instead and passed to the Salesforce class when initializing the object.

This is an example of how the configuration file would be written in YAML format:

# Helper configuration file for the SalesPyForce package

# Define how to obtain the connection information
connection:
    # Define the credentials
    username: admin.user@example.com
    password: example123

    # Define the org information
    org_id: 4DJ000000CeMFYA0
    base_url: https://example-dev-ed.lightning.force.com/
    endpoint_url: https://example-dev-ed.my.salesforce.com/services/oauth2/token

    # Define the API connection info
    client_key: 3MVG9gTv.DiE8cKRIpEtSN_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_TAoy1Zk_AKGukbqa4KbhM6nVYVUu6md
    client_secret: 7536F4A7865559XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX53797BEA88174713CC3C
    security_token: 2muXaXXXXXXXXXXXXXXXoVKxz

# Define if SSL certificates should be verified when making API calls
ssl_verify: yes

The file can then be referenced using the helper argument when initializing the object instance, as shown below.

HELPER_FILE = '/path/to/helper.yml'
sfdc = Salesforce(helper=HELPER_FILE)

Documentation

The documentation is located here: https://salespyforce.readthedocs.io/en/stable/

License

MIT License

Reporting Issues

Issues can be reported within the GitHub repository.

Donations

If you would like to donate to this project then you can do so using this PayPal link.

Disclaimer

This package is considered unofficial and is in no way endorsed or supported by Salesforce Inc.

Release files for salespyforce 2.0.1

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

Source distribution (sdist)

Source distribution for salespyforce 2.0.1
File Size Uploaded
salespyforce-2.0.1.tar.gz 48.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for salespyforce 2.0.1
File Interpreter ABI Platform
salespyforce-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 101.9 kB

Release files / salespyforce-2.0.1.tar.gz

Download URL salespyforce-2.0.1.tar.gz
Size 48.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f9002a3ff246b9d86347062fc240d297431f6b4feb9d254212769182cbc8824b
BLAKE2b-256 checksum
How to use checksums
868233477f4acad71aa661a9e62ff6f0fbeff7782b77122567a3fd2dfd6c5ab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / salespyforce-2.0.1-py3-none-any.whl

Download URL salespyforce-2.0.1-py3-none-any.whl
Size 53.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
24d4934784af3f567bbc17a8d7b7dd8bd2080e8136df3a3d479ebf2ed0b4eddd
BLAKE2b-256 checksum
How to use checksums
ce992826d59fdfdc297ff6e258d8017ac8610be68d89ff654e7100b5b3e09321
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7
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