Skip to main content

A simple library to interact with Salesforce REST API using OAuth 2.0 Client Credentials Flow.

Project description

SalesforceRESTAPI

A simple Python library to interact with the Salesforce REST API using OAuth 2.0 Client Credentials Flow.

Features

  • Authenticate with Salesforce using OAuth 2.0 Client Credentials
  • Basic CRUD operations (create, read, update, delete) for Salesforce objects
  • Bulk API 2.0 support for inserting large datasets
  • SOQL query support
  • Apex script execution via Tooling API
  • Record verification utilities
  • HTTP status code tracking for all API requests

Installation

pip install SalesforceRESTAPI

Usage

Note: As of version 0.1.3, authentication state (instance_url, access_token, headers) is stored as class variables. You must call SalesforceRESTAPI.authenticate(...) before using any instance methods. All instances share the same authentication state.

from SalesforceRESTAPI import SalesforceRESTAPI

# Authenticate (call this once before using any instance methods)
SalesforceRESTAPI.authenticate(client_id='YOUR_CLIENT_ID', client_secret='YOUR_CLIENT_SECRET', login_url='https://login.salesforce.com')

# Now you can use instance methods
sf = SalesforceRESTAPI()

# Create a record
account_id = sf.create_record('Account', Name='Test Account', Industry='Technology')

# Get a record
account = sf.get_record('Account', account_id)

# Update a record
sf.update_record('Account', account_id, Name='Updated Name')

# Delete a record
sf.delete_record('Account', account_id)

# Run a SOQL query
results = sf.queryRecords('SELECT Id, Name FROM Account')

# Execute anonymous Apex
apex_result = sf.execute_apex('System.debug("Hello World");')

# Bulk insert records (for large datasets)
records = [
    {'Subject': 'Test Case 1', 'Status': 'New', 'Priority': 'Medium'},
    {'Subject': 'Test Case 2', 'Status': 'New', 'Priority': 'High'},
    {'Subject': 'Test Case 3', 'Status': 'New', 'Priority': 'Low'}
]
result = sf.bulk_insert_records('Case', records)
print(f"Job ID: {result['job_id']}, Records Processed: {result['records_processed']}")

# Get last HTTP status code
status_code = SalesforceRESTAPI.get_last_http_status()
print(f"Last HTTP Status: {status_code}")

# Revoke authentication (clears class-level state)
sf.revoke()

Requirements

  • Python 3.6+
  • requests
  • python-dotenv (for loading .env files in tests)

License

MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

salesforcerestapi-0.2.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

salesforcerestapi-0.2.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file salesforcerestapi-0.2.0.tar.gz.

File metadata

  • Download URL: salesforcerestapi-0.2.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for salesforcerestapi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2c1d4b09b17ddc5b75fd50c110c530b64b6ac4d4a2bbea7e52393ce9b21e64c9
MD5 e5a3522abbbcbc52485aa3e8bf24d924
BLAKE2b-256 bdb67dd3131c3bf6dafb81406b0a5b6533e3f0b5ee20709d4940f70a796fc6d8

See more details on using hashes here.

File details

Details for the file salesforcerestapi-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for salesforcerestapi-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 121117d7e90988884271659a583e749b941609797e389614d9f17940e4b75468
MD5 b5bd31d77bde60d5beaeb5c586b26358
BLAKE2b-256 5e4a946e11f9747d774793c937ca7842bc5728412350ac08229befac7d6190e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page