Install & Compatibility
Where this runs
tested against v0.1.46 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.705s · 23.3MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.1s · import 0.648s · 24MB
21MB installed
● package 21MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Salesforce
✓ from salesforce_api import Salesforce
Salesforce
✓ from salesforce_api import Salesforce
✗ from simple_salesforce import Salesforce
This library (`salesforce-api` by felixlindstrom) is distinct from `simple-salesforce`, a different popular Salesforce Python client. Ensure you import from the correct package.
This quickstart demonstrates how to establish a connection to Salesforce using username, password, and security token authentication. It then performs a simple SOQL query to retrieve account records. Always use environment variables or a secure configuration management system for credentials in production. You may need to create a Connected App in Salesforce and use OAuth for more robust authentication flows.
import os
from salesforce_api import Salesforce
# It's recommended to use environment variables for sensitive credentials.
SF_USERNAME = os.environ.get('SF_USERNAME', 'your_username@example.com')
SF_PASSWORD = os.environ.get('SF_PASSWORD', 'your_password')
SF_SECURITY_TOKEN = os.environ.get('SF_SECURITY_TOKEN', 'your_security_token')
# For sandbox environments, you might need to specify the domain.
# For example, domain='test'
try:
client = Salesforce(
username=SF_USERNAME,
password=SF_PASSWORD,
security_token=SF_SECURITY_TOKEN
)
print("Successfully connected to Salesforce!")
# Example: Query an SObject
# Note: Replace 'Account' and field names with actual objects/fields in your org.
accounts = client.query("SELECT Id, Name FROM Account LIMIT 5")
print("First 5 Accounts:")
for record in accounts['records']:
print(f" ID: {record['Id']}, Name: {record['Name']}")
# Example: Create a new contact (adjust fields as per your Salesforce org)
# new_contact_data = {
# 'LastName': 'TestContact',
# 'Email': 'test@example.com'
# }
# result = client.Contact.create(new_contact_data)
# print(f"Created Contact ID: {result['id']}")
except Exception as e:
print(f"An error occurred: {e}")
Errors
Common errors & fixes
statusCode='DUPLICATES_DETECTED', message='You're creating a duplicate record.'
Salesforce org has active duplicate rules or matching rules that prevent the creation or update of records that match existing ones.
fixAdjust your data to avoid duplicates, or configure Salesforce Duplicate Rules to exclude the integration user or specific scenarios.
statusCode='INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST'
Attempting to insert or update a picklist field with a value that is not defined in Salesforce's picklist options, or the picklist is restricted.
fixEnsure that picklist values provided in your code exactly match the values configured in Salesforce. If the picklist is restricted, only defined values are allowed. Consider making picklists non-restricted if appropriate for your integration.
The access token in the request is missing, invalid, or expired.
The authentication token used for API calls is either not provided, has become invalid (e.g., password change), or has expired.
fixVerify that your username, password, and security token are correct and up-to-date. If using OAuth, ensure the refresh token mechanism is correctly implemented to obtain new access tokens.
UNABLE_TO_LOCK_ROW
Multiple processes or API calls are attempting to update the same Salesforce record simultaneously, leading to a database locking conflict.
fixImplement retry logic with a delay (e.g., exponential backoff) for operations that may encounter this error. Design integrations to minimize concurrent updates to the same records where possible.
Upgrade
Version history
0.1.46latest on PyPI · released Jan 5, 2026
Audit
Dependencies
requestsrequiredHTTP client for making API calls.
xmltodictrequiredXML parsing for SOAP API interactions.
iso8601requiredDate and time parsing/formatting for API requests.