Skip to main content

Async Salesforce library for Python with Bulk API 2.0 support

Project description

aio-sf

An async Salesforce library for Python with Bulk API 2.0 support.

Features

✅ Supported APIs

  • OAuth Client Credentials Flow - Automatic authentication
  • Bulk API 2.0 - Efficient querying of large datasets
  • Describe API - Field metadata and object descriptions
  • SOQL Query API - Standard Salesforce queries

🔄 Planned APIs

  • SObjects API - Standard CRUD operations
  • Tooling API - Development and deployment tools
  • Bulk API 1.0 - Legacy bulk operations
  • Streaming API - Real-time event streaming

🚀 Export Features

  • Parquet Export - Efficient columnar storage with schema mapping
  • CSV Export - Simple text format export
  • Resume Support - Resume interrupted queries using job IDs
  • Streaming Processing - Memory-efficient processing of large datasets
  • Type Mapping - Automatic Salesforce to PyArrow type conversion

Installation

Core (Connection Only)

uv add aio-sf
# or: pip install aio-sf

With Export Capabilities

uv add "aio-sf[exporter]"
# or: pip install "aio-sf[exporter]"

Quick Start

Authentication & Connection

import asyncio
import os
from aio_salesforce import SalesforceConnection, ClientCredentialsAuth

async def main():
    auth = ClientCredentialsAuth(
        client_id=os.getenv('SF_CLIENT_ID'),
        client_secret=os.getenv('SF_CLIENT_SECRET'),
        instance_url=os.getenv('SF_INSTANCE_URL'),
    )
    
    async with SalesforceConnection(auth_strategy=auth) as sf:
        print(f"✅ Connected to: {sf.instance_url}")

        sobjects = await sf.describe.list_sobjects()
        print(sobjects[0]["name"])

        contact_describe = await sf.describe.sobject("Contact")

        # retrieve first 5 "creatable" fields on contact
        queryable_fields = [
            field.get("name", "")
            for field in contact_describe["fields"]
            if field.get("createable")
        ][:5]

        query = f"SELECT {', '.join(queryable_fields)} FROM Contact LIMIT 5"
        print(query)

        query_result = await sf.query.soql(query)
        # Loop over records using async iteration
        async for record in query_result:
            print(record.get("AccountId"))

asyncio.run(main())

Exporter

The Exporter library contains a streamlined and "opinionated" way to export data from Salesforce to various formats.

2. Query Records

from aio_salesforce.exporter import bulk_query

async def main():
    # ... authentication code from above ...
    
    async with SalesforceConnection(auth_strategy=auth) as sf:
        # Execute bulk query
        query_result = await bulk_query(
            sf=sf,
            soql_query="SELECT Id, Name, Email FROM Contact LIMIT 1000"
        )
        
        # Process records
        count = 0
        async for record in query_result:
            print(f"Contact: {record['Name']} - {record['Email']}")
            count += 1
            
        print(f"Processed {count} records")

3. Export to Parquet

from aio_salesforce.exporter import bulk_query, write_query_to_parquet

async def main():
    # ... authentication code from above ...
    
    async with SalesforceConnection(auth_strategy=auth) as sf:
        # Query with proper schema
        query_result = await bulk_query(
            sf=sf,
            soql_query="SELECT Id, Name, Email, CreatedDate FROM Contact"
        )
        
        # Export to Parquet
        write_query_to_parquet(
            query_result=query_result,
            file_path="contacts.parquet"
        )
        
        print(f"✅ Exported {len(query_result)} contacts to Parquet")

License

MIT License

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

aio_sf-0.1.0b1.tar.gz (173.1 kB view details)

Uploaded Source

Built Distribution

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

aio_sf-0.1.0b1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file aio_sf-0.1.0b1.tar.gz.

File metadata

  • Download URL: aio_sf-0.1.0b1.tar.gz
  • Upload date:
  • Size: 173.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aio_sf-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 557fa7e7fa691bc84f81f1ca77f6af84db0d73f6957a23d5ac2b798e119a3909
MD5 81e19e67ea4fc4178eb0a0e73c916b1b
BLAKE2b-256 1f801ca7cf6f27b91ce4d1a1e4957ba271fc9756a8a2ade6dd0ff868af2810f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_sf-0.1.0b1.tar.gz:

Publisher: publish.yml on callawaycloud/aio-salesforce

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aio_sf-0.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: aio_sf-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aio_sf-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 47e94769fb00175636c8ffcbae355342a46387caa9497613c4713ef2d1fc9886
MD5 79e85228845e14edd7ebb98d6a1aa508
BLAKE2b-256 c0d6cda63466fe5cf58deb160e8a8549491b1f159735dfe01ea168b95646f537

See more details on using hashes here.

Provenance

The following attestation bundles were made for aio_sf-0.1.0b1-py3-none-any.whl:

Publisher: publish.yml on callawaycloud/aio-salesforce

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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