Skip to main content
CI Status PyPI status

This package provides declarative models for Salesforce objects and utilities for generating Salesforce Object Query Language (SOQL) queries from these models.

This package works well with Simple Salesforce.

Usage

from simple_salesforce import Salesforce
from soql import attributes
from soql import load_models_from_salesforce_data
from soql import Model
from soql import select


class Account(Model):
    id = attributes.String('Id')
    deleted = attributes.Boolean('IsDeleted')
    name = attributes.String('Name')
    owner = attributes.Relationship('Owner', related_model=User)
    custom_field = attributes.String('CustomField__c', nullable=True)

class User(Model):
    id = attributes.String('Id')
    email = attributes.String('Email')

sf = Salesforce(...)

query = select(Account) \
    .where(Account.id == '50130000000014c') \
    .join(Account.owner)

resp = sf.query(str(query))

account = load_models_from_salesforce_data(resp)[0]

print(account.id)
print(account.owner.id)

Models

Models define in-memory representations of Salesforce object, and provide an idiomatic way to access the data.

from soql import attributes
from soql import Model

class User(Model):
    # The first argument to an attribute is its name in Salesforce.
    id = attributes.String('Id')
    email = attributes.String('Email')

user = User(id='123', email='a@b.com')

assert user.id == '123'

Helpers are available to load models directly from simple_salesforce:

query = select(User)

resp = sf.query(str(query))

users = load_models_from_salesforce_data(resp)

Relationships can also be declared:

class Account(Model):
    id = attributes.String('Id')
    owner = attributes.Relationship('Owner', related_model=User)
    contacts = attributes.Relationship('Contacts', related_model=User, many=True, nullable=True)

Queries

SOQL queries can be generated from models:

from soql import select

query = select(User).where(User.id == '123')

assert str(query) == "SELECT User.Id, User.Email FROM User WHERE User.Id = '123'"

Most of SOQL is supported, including…

Joins:

from soql import select

query = select(Account).join(Account.contacts)

assert str(query) == "SELECT Account.Id, (SELECT User.Id, User.Email FROM Account.Contacts) FROM Account"

Subqueries:

from soql import select

subquery = select(User).columns(User.email).subquery()
query = select(User).where(User.email.in_(subquery))

assert str(query) == "SELECT User.Id, User.Email FROM User WHERE User.Email IN (SELECT User.Email FROM User)"

And more!

Installation

pip install soql

Contributing

There is still work to be done, and contributions are encouraged! Check out the contribution guide for more information.

Metadata

Release files for soql 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for soql 1.2.0
File Size Uploaded
soql-1.2.0.tar.gz 21.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for soql 1.2.0
File Interpreter ABI Platform
soql-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.3 kB

Release files / soql-1.2.0.tar.gz

Download URL soql-1.2.0.tar.gz
Size 21.5 kB
Tags Source
SHA-256 checksum
How to use checksums
e3dfee7f9606018f36a063e974d7e57fcb7a548843cb7454dde803caabec3642
BLAKE2b-256 checksum
How to use checksums
2f8b5dc2daa2e13122366c908313407165904aa1a58e58c65d31c941d8ea0fa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / soql-1.2.0-py3-none-any.whl

Download URL soql-1.2.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7d2c3878f263dcd46b7726b7a53ea307d6bb8be7f92e8c2388850c54a9a73956
BLAKE2b-256 checksum
How to use checksums
360d62e6d08f37faca5a646750f5e1a6359fdf701dcee6ca56b2e518325de3af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.2

1 release file

1.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page