Skip to main content

An integration package connecting Salesforce and LangChain

Project description

langchain-salesforce

PyPI version License: MIT Python Versions

The langchain-salesforce package provides a seamless integration between LangChain and Salesforce CRM, enabling developers to leverage LangChain's powerful framework to interact with Salesforce data.

Overview

This package allows you to connect to your Salesforce instance and perform various operations, such as querying data with SOQL, inspecting object schemas, and managing records (Create, Read, Update, Delete - CRUD). It is designed to be a flexible tool within the LangChain ecosystem.

Key Features

  • Salesforce CRM Integration: Connect LangChain applications directly to Salesforce.
  • SOQL Execution: Run Salesforce Object Query Language (SOQL) queries.
  • Schema Inspection: Describe Salesforce object structures.
  • Object Listing: List all available SObjects in your Salesforce org.
  • CRUD Operations: Create, update, and delete Salesforce records.
  • Environment Variable Configuration: Easy setup using standard environment variables.
  • Comprehensive Error Handling: Robust error management for Salesforce API interactions.

Installation

To install the package, run the following command:

pip install -U langchain-salesforce

Configuration

Before using the tool, configure your Salesforce credentials by setting the following environment variables:

  • SALESFORCE_USERNAME: Your Salesforce username.
  • SALESFORCE_PASSWORD: Your Salesforce password.
  • SALESFORCE_SECURITY_TOKEN: Your Salesforce security token.
  • SALESFORCE_DOMAIN: Your Salesforce domain (e.g., "login" for production, "test" for sandbox environments). Defaults to "login".

Quick Start

Here's a quick example of how to initialize the SalesforceTool and query for contacts:

from langchain_salesforce import SalesforceTool
import os

# Initialize the tool (credentials can also be sourced from environment variables)
tool = SalesforceTool(
    username=os.getenv("SALESFORCE_USERNAME", "your-username"),
    password=os.getenv("SALESFORCE_PASSWORD", "your-password"),
    security_token=os.getenv("SALESFORCE_SECURITY_TOKEN", "your-token"),
    domain=os.getenv("SALESFORCE_DOMAIN", "login")
)

# Example: Query for the first 5 contacts
query_result = tool.run({
    "operation": "query",
    "query": "SELECT Id, Name, Email FROM Contact LIMIT 5"
})

print(query_result)

SalesforceTool Usage

The SalesforceTool is the primary interface for interacting with Salesforce. It accepts a dictionary input specifying the operation and its required parameters.

Supported Operations

1. Query Data (query)

Execute SOQL queries to retrieve data from Salesforce.

result = tool.run({
    "operation": "query",
    "query": "SELECT Id, Name, Industry FROM Account WHERE Industry = 'Technology' LIMIT 10"
})
print(result)

2. Describe Object Schema (describe)

Get the schema information for a specific Salesforce object.

schema = tool.run({
    "operation": "describe",
    "object_name": "Account"
})
print(schema)

3. List Available Objects (list_objects)

Retrieve a list of all available SObjects in your Salesforce organization.

available_objects = tool.run({
    "operation": "list_objects"
})
print(available_objects)

4. Create New Record (create)

Create a new record for a specified Salesforce object.

new_contact_details = tool.run({
    "operation": "create",
    "object_name": "Contact",
    "record_data": {
        "LastName": "Doe",
        "FirstName": "John",
        "Email": "john.doe@example.com",
        "Phone": "123-456-7890"
    }
})
print(new_contact_details) # Returns ID of the new record and success status

5. Update Existing Record (update)

Update fields on an existing Salesforce record.

update_status = tool.run({
    "operation": "update",
    "object_name": "Contact",
    "record_id": "003XXXXXXXXXXXXXXX",  # Replace with an actual Contact ID
    "record_data": {
        "Email": "john.doe.updated@example.com",
        "Description": "Updated contact information."
    }
})
print(update_status) # Returns ID of the updated record and success status

6. Delete Record (delete)

Delete a Salesforce record by its ID.

delete_confirmation = tool.run({
    "operation": "delete",
    "object_name": "Contact",
    "record_id": "003YYYYYYYYYYYYYYY"  # Replace with an actual Contact ID
})
print(delete_confirmation) # Returns ID of the deleted record and success status

Development

Interested in contributing? Follow these steps to set up your development environment:

  1. Clone the repository:

    git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY.git # Replace with your repository URL
    cd langchain-salesforce
    
  2. Install dependencies: This project uses Poetry for dependency management.

    poetry install
    
  3. Run tests:

    make test
    
  4. Run linters and formatters:

    make lint
    

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have suggestions or improvements. Consider creating a CONTRIBUTING.md file for detailed guidelines.

License

This project is licensed under the MIT License. See the LICENSE file for more 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

langchain_salesforce-0.2.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

langchain_salesforce-0.2.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: langchain_salesforce-0.2.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.13.3 Darwin/24.5.0

File hashes

Hashes for langchain_salesforce-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7eed0beffc17c41962c3287f0c5375b7d1202842ac529c882a36131d6e6f774e
MD5 2aa87a96ca27ee670f11d817a8877150
BLAKE2b-256 e60708c5f8424035a5f1cf766d9334076c2472a491bd549a9bc6fdb0dbc933c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_salesforce-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af2383055271efcdd0a056d00b62ab1a86d228fd8646ff4fc5868b95ebae1dca
MD5 7e9f2d0f75574df6f7648eb7df86b03d
BLAKE2b-256 7b321441c2f8d45b8f93e0cefe075f7d761953718e72e10963a4475dca407005

See more details on using hashes here.

Supported by

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