Skip to content

Introduction

Overview

aiosalesforce is an asynchronous Python client for the Salesforce API. It allows performing the following operations against Salesforce:

  • Authentication
  • CRUD operations on Salesforce objects (also known as sobjects)
  • Executing SOQL queries
  • Bulk data operations

The general pattern for using aiosalesforce is to create an authentication instance and pass it to the Salesforce client. The client is then used to make requests to the Salesforce APIs.

import asyncio

from aiosalesforce import Salesforce, SoapLogin
from httpx import AsyncClient

auth = SoapLogin(
    username="username",
    password="password",
    security_token="security-token",
)

async def main():
    async with AsyncClient() as client:
        salesforce = Salesforce(
            client=client,
            base_url="https://your-instance.my.salesforce.com",
            auth=auth,
        )
        contact = salesforce.sobject.get("Contact", "0033h00000KzZ3AAAV")
        print(contact)


if __name__ == "__main__":
    asyncio.run(main())

Note

Since aiosalesforce is an asynchronous library, you need to define your functions using async def and use the await keyword when calling asynchronous methods. In subsequent sections of this documentation the definition of the asynchronous function is often ommited for brevity and it is assumed that everything is written inside one.

As you are using aiosalesforce, you should familiarize yourself with the Python's asyncio library.

Relevant Salesforce API documentation: