Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add pd.read_soql() for Salesforce data retrieval #60966

Open
1 of 3 tasks
benvigano opened this issue Feb 19, 2025 · 1 comment
Open
1 of 3 tasks

ENH: Add pd.read_soql() for Salesforce data retrieval #60966

benvigano opened this issue Feb 19, 2025 · 1 comment
Assignees
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@benvigano
Copy link

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish I could use Pandas to query Salesforce using SOQL (Salesforce Object Query Language) just as you do with relational databases using pd.read_sql(). Currently, to retrieve Salesforce data into a Pandas DataFrame, users must execute queries using simple_salesforce and manually convert results to DataFrames, which in case of multi-level queries can become quite inefficient (due to the nested format of the outputs of Salesforce REST API).

Feature Description

The function would parallel pd.read_sql() and would look like this:

def read_soql(
    query: str,  # Equivalent to `query` in `pd.read_sql()`, representing the SOQL query string.
    con,  # Expects a `simple_salesforce.Salesforce` object instead of an SQLAlchemy connection.
    index_col: str | list[str] | None = None,  # Same as in `pd.read_sql()`
    parse_dates=None,  # Same as in `pd.read_sql()`
    dtype: DtypeArg | None = None,  # Same as in `pd.read_sql()`
    dtype_backend: DtypeBackend | lib.NoDefault = lib.no_default  # Same as in `pd.read_sql()`
) -> DataFrame:

    # validate connection is Salesforce object
    # validate dtype_backend is valid option

    # execute SOQL query and get all records
    # flatten output and remove metadata
    # convert records to DataFrame

    # if dtype specified: convert columns to specified types
    # if parse_dates specified: convert date columns
    # if index_col specified: set DataFrame index

    # if dtype_backend != 'numpy': convert to nullable types
    # return DataFrame

Alternative Solutions

Alternative naming
Since pd.read_sql() is a convenience wrapper around read_sql_table and read_sql_query, a more "formally" correct name might be read_soql_query, as there is no corresponding read_soql_table. This would maintain a closer parallel to Pandas' SQL functions.
However, I propose read_soql for brevity, and for consistency with other I/O functions such as pd.read_excel(), pd.read_parquet(), pd.read_feather(), pd.read_orc() etc.

Additional Context

I am interested in developing this feature as I have already done some work towards its implementation.

@benvigano benvigano added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 19, 2025
@benvigano
Copy link
Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant