Name | sfq JSON |
Version |
0.0.4
JSON |
| download |
home_page | None |
Summary | Python wrapper for the Salesforce's Query API. |
upload_time | 2024-12-21 03:45:18 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | None |
keywords |
salesforce
salesforce query
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# sfq (Salesforce Query)
sfq is a lightweight Python wrapper library designed to simplify querying Salesforce, reducing repetitive code for accessing Salesforce data.
For more varied workflows, consider using an alternative like [Simple Salesforce](https://simple-salesforce.readthedocs.io/en/stable/). This library was even referenced on the [Salesforce Developers Blog](https://developer.salesforce.com/blogs/2021/09/how-to-automate-data-extraction-from-salesforce-using-python).
## Features
- Simplified query execution for Salesforce instances.
- Integration with Salesforce authentication via refresh tokens.
- Option to interact with Salesforce Tooling API for more advanced queries.
## Installation
You can install the `sfq` library using `pip`:
```bash
pip install sfq
```
## Usage
### Querying Salesforce Data
```python
from sfq import SFAuth
# Initialize the SFAuth class with authentication details
sf = SFAuth(
instance_url="https://example-dev-ed.trailblaze.my.salesforce.com",
client_id="PlatformCLI",
refresh_token="your-refresh-token-here"
)
# Execute a query to fetch account records
print(sf.query("SELECT Id FROM Account LIMIT 5"))
# Execute a query to fetch Tooling API data
print(sf.query("SELECT Id, FullName, Metadata FROM SandboxSettings LIMIT 5", tooling=True))
```
### Querying from Bash
You can easily incorporate this into ad-hoc bash scripts or commands:
```bash
python -c "from sfq import SFAuth; sf = SFAuth(instance_url='$instance_url', client_id='$client_id', refresh_token='$refresh_token'); print(sf.query('$query'))" | jq -r '.records[].Id'
```
## How to Obtain Salesforce Tokens
To use the `sfq` library, you'll need a **client ID** and **refresh token**. The easiest way to obtain these is by using the Salesforce CLI:
### Steps to Get Tokens
1. **Install the Salesforce CLI**:
Follow the instructions on the [Salesforce CLI installation page](https://developer.salesforce.com/tools/salesforcecli).
2. **Authenticate with Salesforce**:
Login to your Salesforce org using the following command:
```bash
sf org login web --alias int --instance-url https://corpa--int.sandbox.my.salesforce.com
```
3. **Display Org Details**:
To get the client ID, refresh token, and instance URL, run:
```bash
sf org display --target-org int --verbose --json
```
The output will look like this:
```json
{
"status": 0,
"result": {
"id": "00Daa0000000000000",
"apiVersion": "62.0",
"accessToken": "your-access-token-here",
"instanceUrl": "https://example-dev-ed.trailblaze.my.salesforce.com",
"username": "user@example.com",
"clientId": "PlatformCLI",
"connectedStatus": "Connected",
"sfdxAuthUrl": "force://PlatformCLI::your-refresh-token-here::https://example-dev-ed.trailblaze.my.salesforce.com",
"alias": "int"
}
}
```
4. **Extract and Use the Tokens**:
The `sfdxAuthUrl` is structured as:
```
force://<client_id>::<refresh_token>::<instance_url>
```
You can extract and use the tokens in a bash script like this:
```bash
query="SELECT Id FROM User WHERE IsActive = true AND Profile.Name = 'System Administrator'"
sfdxAuthUrl=$(sf org display --target-org int --verbose --json | jq -r '.result.sfdxAuthUrl' | sed 's/force:\/\///')
clientId=$(echo "$sfdxAuthUrl" | sed 's/::/\n/g' | sed -n '1p')
refreshToken=$(echo "$sfdxAuthUrl" | sed 's/::/\n/g' | sed -n '2p')
instanceUrl=$(echo "$sfdxAuthUrl" | sed 's/::/\n/g' | sed -n '3p')
pip install sfq && python -c "from sfq import SFAuth; sf = SFAuth(instance_url='$instanceUrl', client_id='$clientId', refresh_token='$refreshToken'); print(sf.query('$query'))" | jq -r '.records[].Id'
```
## Notes
- **Authentication**: Make sure your refresh token is kept secure, as it grants access to your Salesforce instance.
- **Tooling API**: You can set the `tooling=True` argument in the `query` method to access the Salesforce Tooling API for more advanced metadata queries.
Raw data
{
"_id": null,
"home_page": null,
"name": "sfq",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "salesforce, salesforce query",
"author": null,
"author_email": "David Moruzzi <sfq.pypi@dmoruzi.com>",
"download_url": "https://files.pythonhosted.org/packages/39/9c/a379902530c2b2c36c55f60cc44eb152e727d5898ab3f44dc1eaa5b070fb/sfq-0.0.4.tar.gz",
"platform": null,
"description": "# sfq (Salesforce Query)\n\nsfq is a lightweight Python wrapper library designed to simplify querying Salesforce, reducing repetitive code for accessing Salesforce data.\n\nFor more varied workflows, consider using an alternative like [Simple Salesforce](https://simple-salesforce.readthedocs.io/en/stable/). This library was even referenced on the [Salesforce Developers Blog](https://developer.salesforce.com/blogs/2021/09/how-to-automate-data-extraction-from-salesforce-using-python).\n\n## Features\n\n- Simplified query execution for Salesforce instances.\n- Integration with Salesforce authentication via refresh tokens.\n- Option to interact with Salesforce Tooling API for more advanced queries.\n \n## Installation\n\nYou can install the `sfq` library using `pip`:\n\n```bash\npip install sfq\n```\n\n## Usage\n\n### Querying Salesforce Data\n\n```python\nfrom sfq import SFAuth\n\n# Initialize the SFAuth class with authentication details\nsf = SFAuth(\n instance_url=\"https://example-dev-ed.trailblaze.my.salesforce.com\",\n client_id=\"PlatformCLI\",\n refresh_token=\"your-refresh-token-here\"\n)\n\n# Execute a query to fetch account records\nprint(sf.query(\"SELECT Id FROM Account LIMIT 5\"))\n\n# Execute a query to fetch Tooling API data\nprint(sf.query(\"SELECT Id, FullName, Metadata FROM SandboxSettings LIMIT 5\", tooling=True))\n```\n\n### Querying from Bash\n\nYou can easily incorporate this into ad-hoc bash scripts or commands:\n\n```bash\npython -c \"from sfq import SFAuth; sf = SFAuth(instance_url='$instance_url', client_id='$client_id', refresh_token='$refresh_token'); print(sf.query('$query'))\" | jq -r '.records[].Id'\n```\n\n## How to Obtain Salesforce Tokens\n\nTo use the `sfq` library, you'll need a **client ID** and **refresh token**. The easiest way to obtain these is by using the Salesforce CLI:\n\n### Steps to Get Tokens\n\n1. **Install the Salesforce CLI**: \n Follow the instructions on the [Salesforce CLI installation page](https://developer.salesforce.com/tools/salesforcecli).\n \n2. **Authenticate with Salesforce**: \n Login to your Salesforce org using the following command:\n \n ```bash\n sf org login web --alias int --instance-url https://corpa--int.sandbox.my.salesforce.com\n ```\n \n3. **Display Org Details**: \n To get the client ID, refresh token, and instance URL, run:\n \n ```bash\n sf org display --target-org int --verbose --json\n ```\n\n The output will look like this:\n\n ```json\n {\n \"status\": 0,\n \"result\": {\n \"id\": \"00Daa0000000000000\",\n \"apiVersion\": \"62.0\",\n \"accessToken\": \"your-access-token-here\",\n \"instanceUrl\": \"https://example-dev-ed.trailblaze.my.salesforce.com\",\n \"username\": \"user@example.com\",\n \"clientId\": \"PlatformCLI\",\n \"connectedStatus\": \"Connected\",\n \"sfdxAuthUrl\": \"force://PlatformCLI::your-refresh-token-here::https://example-dev-ed.trailblaze.my.salesforce.com\",\n \"alias\": \"int\"\n }\n }\n ```\n\n4. **Extract and Use the Tokens**: \n The `sfdxAuthUrl` is structured as:\n \n ```\n force://<client_id>::<refresh_token>::<instance_url>\n ```\n\n You can extract and use the tokens in a bash script like this:\n\n ```bash\n query=\"SELECT Id FROM User WHERE IsActive = true AND Profile.Name = 'System Administrator'\"\n\n sfdxAuthUrl=$(sf org display --target-org int --verbose --json | jq -r '.result.sfdxAuthUrl' | sed 's/force:\\/\\///')\n clientId=$(echo \"$sfdxAuthUrl\" | sed 's/::/\\n/g' | sed -n '1p')\n refreshToken=$(echo \"$sfdxAuthUrl\" | sed 's/::/\\n/g' | sed -n '2p')\n instanceUrl=$(echo \"$sfdxAuthUrl\" | sed 's/::/\\n/g' | sed -n '3p')\n\n pip install sfq && python -c \"from sfq import SFAuth; sf = SFAuth(instance_url='$instanceUrl', client_id='$clientId', refresh_token='$refreshToken'); print(sf.query('$query'))\" | jq -r '.records[].Id'\n ```\n\n## Notes\n\n- **Authentication**: Make sure your refresh token is kept secure, as it grants access to your Salesforce instance.\n- **Tooling API**: You can set the `tooling=True` argument in the `query` method to access the Salesforce Tooling API for more advanced metadata queries.\n",
"bugtrack_url": null,
"license": null,
"summary": "Python wrapper for the Salesforce's Query API.",
"version": "0.0.4",
"project_urls": null,
"split_keywords": [
"salesforce",
" salesforce query"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4ef6edaf4081ede3ab3fb364499ee350031efbee8f0842fff265a5558e06f080",
"md5": "6f6f0373888ced1e184bc13b6ba612da",
"sha256": "8696106560f9078f129ff65adc4ccfb63f8652f5f7dba55e15fd7bb6d1e49757"
},
"downloads": -1,
"filename": "sfq-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f6f0373888ced1e184bc13b6ba612da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 4628,
"upload_time": "2024-12-21T03:45:15",
"upload_time_iso_8601": "2024-12-21T03:45:15.791391Z",
"url": "https://files.pythonhosted.org/packages/4e/f6/edaf4081ede3ab3fb364499ee350031efbee8f0842fff265a5558e06f080/sfq-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "399ca379902530c2b2c36c55f60cc44eb152e727d5898ab3f44dc1eaa5b070fb",
"md5": "a2246ea82be1bc01ae7c6760f2f6b788",
"sha256": "5088b8e0f1fc3251779fdab4e4bbac22952693bb5d6eefa80467e2300c433c7c"
},
"downloads": -1,
"filename": "sfq-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "a2246ea82be1bc01ae7c6760f2f6b788",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 4602,
"upload_time": "2024-12-21T03:45:18",
"upload_time_iso_8601": "2024-12-21T03:45:18.278397Z",
"url": "https://files.pythonhosted.org/packages/39/9c/a379902530c2b2c36c55f60cc44eb152e727d5898ab3f44dc1eaa5b070fb/sfq-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-21 03:45:18",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "sfq"
}