even-simpler-salesforce¶
Beyond simple-salesforce
The parts you no longer write yourself
Six things simple-salesforce leaves to you. Here they come built in.
Async and sync
One API. Await it in FastAPI, call it from Flask or a script.
Moving over? One command rewrites the mechanical part of your code.
async with esf.AsyncSalesforce(auth) as sf:
await sf.query(soql)
with esf.Salesforce(auth) as sf:
sf.query(soql)
simple-salesforce Sync only
Token refresh
An expired token is refreshed once, and the call is sent again.
# The token expired an hour ago.
await sf.query("SELECT Id FROM Lead")
# 401 -> refreshed -> sent again -> rows
simple-salesforce Raises SalesforceExpiredSession
Typed errors
One exception class per Salesforce error code, with the fields that failed.
except esf.ValidationRuleFailed as exc:
print(exc.fields) # ('Company',)
except esf.RowLocked:
retry_later()
simple-salesforce One class per HTTP status
API budget
Every app on the org shares one daily API limit. Pause batch jobs first, so live traffic keeps working.
budget = esf.Budget()
sf = esf.AsyncSalesforce(auth, budget=budget)
job = sf.tagged(priority="low")
# above 80% of the daily limit, job calls
# raise BudgetExceeded. Live calls still run.
simple-salesforce Reads usage, never stops a call
Readable logs
One event per call, secrets redacted. Works with structlog and OpenTelemetry.
$ ESF_DEBUG=1 python sync.py
esf GET query Lead 200 115ms
esf PATCH sobject.update Lead 400 88ms
esf POST oauth.refresh rotated 240ms
simple-salesforce No structured events
Test fakes
An in-memory org as a pytest fixture. No network, no mocks to write.
def test_close(esf_fake):
lead = esf_fake.add("Lead", record)
close_lead(esf_fake, lead)
assert esf_fake.calls_for("sobject.update")
simple-salesforce No test helpers
esf migrate src/
Beta (0.5)
Breaking changes are still possible in 0.x releases. See the project status for what is covered and where it has been tested.