Registry / crm-productivity / salesforce-api

salesforce-api

JSON →
library0.1.46pypypi✓ verified 84d ago

The `salesforce-api` library (felixlindstrom/python-salesforce-api) provides an easy-to-use, flexible, and testable solution for communicating with Salesforce through its REST and SOAP APIs. It handles authentication, record management (CRUD), SOQL queries, and bulk operations. The library is currently at version 0.1.46 and is actively maintained with contributions as recent as 2024.

pip install salesforce-api
INSTALL
IMPORT
SIG · SALESFORCE-API
S
salesforce-api
crm-productivitypythonv0.1.46
Install
3.1s avg
Import
677ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.705s · 23.3MB
glibc
py 3.103.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}")
Debug
Known issues
gotchaSalesforce API calls are subject to daily and hourly limits. Exceeding these limits can lead to `TOO_MANY_REQUESTS` (429 HTTP status) or other errors, temporarily blocking API access.
fix
Implement error handling with exponential backoff for retries. Monitor API usage in Salesforce 'System Overview' to anticipate limits.
affects: All
gotchaAuthentication with username, password, and security token may require relaxing IP restrictions in Salesforce or whitelisting client IP addresses if operating from a new location.
fix
In Salesforce Setup, navigate to 'App Manager' -> 'Connected Apps', then 'Manage' -> 'Edit Policies'. Ensure 'IP Relaxation' is set to 'Relax IP restrictions' or that your application's IP is whitelisted under 'Network Access'.
affects: All
gotchaThe default login URL is for production. For sandbox environments, you must explicitly specify `domain='test'` or the full sandbox login URL during client initialization.
fix
Initialize the `Salesforce` client with `client = Salesforce(..., domain='test')` for sandbox environments.
affects: All
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.
fix
Adjust 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.
fix
Ensure 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.
fix
Verify 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.
fix
Implement 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.
Agent activity
36 hits · last 30 days
node
32
OpenAI (training)
1
Resources
salesforce-api — pip install salesforce-api · libregistry