Extract Accounts, Contacts, Opportunities, and custom objects from Salesforce into Semantica with username/password/security-token, JWT bearer, or session-based authentication.
Installation
Basic Usage
Use environment variables (or a .env file with python-dotenv) to keep credentials out of source code. SalesforceIngestor() with no arguments reads from SALESFORCE_* environment variables automatically.
Authentication Methods
Username / Password / Security Token
JWT Bearer (Recommended for CI/CD)
Session ID + Instance URL
Sandbox
Set the required environment variables before running:The standard server-side flow. The security token is appended to the
password during Salesforce SOAP login. Generate or reset it under
Settings → My Personal Information → Reset My Security Token. The JWT bearer flow authenticates with a signed token — no password
is transmitted. Ideal for server-to-server integrations and CI/CD
pipelines. Requires a Salesforce connected app configured with
Use digital signatures and the pre-authorised user listed under
Manage → Profiles / Permission Sets.If you prefer to pass the key material as a string instead of a file
path, use SALESFORCE_PRIVATE_KEY (the PEM contents) in place of
SALESFORCE_PRIVATE_KEY_FILE. Use this when your environment already manages the OAuth token
lifecycle (e.g. a connected app obtaining tokens via the web-server
or device flow). Pass the access token as session_id and the full
instance URL (e.g. https://myorg.my.salesforce.com) as
instance_url. Replace domain="login" with domain="test" (or set
SALESFORCE_DOMAIN=test in your environment) to connect to a
developer or full sandbox.
Environment variables
All constructor parameters have environment-variable fallbacks:
Object Ingestion
Ingest a standard object
data.row_count is the number of records in data.data (i.e. what was actually returned after any limit). data.total_size is Salesforce’s totalSize — the number of records matching the query before the limit. Compare them to know whether you got all results.
Ingest a custom object
Custom objects end with __c in their API name:
Relationship traversal fields (Owner.Name) are also supported:
Let Semantica choose the fields
When fields is omitted, all selectable fields are fetched via describe()
(one extra API call). Compound address and geolocation fields (type=address,
type=location) are automatically excluded — select their components
(BillingStreet, BillingCity, Location__Latitude__s, …) individually if
you need them.
Raw SOQL Ingestion
Pass any valid SOQL query verbatim — pagination is handled automatically:
The query is passed to the Salesforce REST API unchanged. The caller is
responsible for SOQL correctness and safety.
ingest_query does not validate or sanitise the SOQL string. Use
ingest_sobject (which validates sObject names, field names, and WHERE/ORDER
BY fragments) when building queries from application-controlled inputs.
Document Export
Convert ingested records to the Semantica document format for use with
GraphBuilder:
Feed the documents directly into GraphBuilder:
Object and Schema Discovery
Context Manager
Prefer the context manager for long-running jobs — it opens one connection on
entry and closes it on exit, so every ingestion call inside the with block
reuses the same authenticated session:
Convenience Function
Use ingest_salesforce() for one-liner ingestion:
Or use the unified ingest() dispatcher:
Troubleshooting
Common causes of authentication failures:
- Wrong domain: production orgs use
domain="login"; sandboxes use domain="test".
- Stale security token: reset it under Settings → Reset My Security Token. The new token is emailed to you.
- IP restriction: your org’s trusted IP ranges may block the originating IP. Check Setup → Network Access.
- API access disabled: ensure the connected profile has the API Enabled permission.
See Also