CRM Analytics REST API Client
Project description
crma-api-client
CRM Analytics REST API Client
Features:
- Execute SAQL queries
- List dataset versions
Table of Contents:
Installation
crma-api-client requires Python 3.9 or above.
pip install crma-api-client
# or
poetry add crma-api-client
Guide
First, you need to create a new client instance. To do that, you either need to have credentials for an OAuth app or an existing access token handy:
from crma_api_client.client import ConnectionInfo, CRMAAPIClient
# Generate connection info if you don't already have an access token
conn = await ConnectionInfo.generate(
client_id="abc123",
client_secret="***",
username="me@salesforce.com",
password="***"
)
# If you already have an instance URL and access token, you can instantiate directly
conn = ConnectionInfo(instance_url="https://company.my.salesforce.com", access_token="XYZ123")
# Create the client, passing in the connection object
client = CRMAAPIClient(conn)
Next, you can use methods on the client to make requests:
response = await client.list_dataset_versions("Sample_Superstore_xls_Orders")
version = response.versions[0]
query = "\n".join(
[
f"""q = load "{version.dataset.id}/{version.id}";""",
"""q = group q by 'Category';""",
"""q = foreach q generate q.'Category' as 'Category', sum(q.'Sales') as 'Sales';""",
"""q = order q by 'Category' asc;""",
]
)
response = await client.query(query)
assert response.results.records == [
{"Category": "Furniture", "Sales": 741999.7953},
{"Category": "Office Supplies", "Sales": 719047.032},
{"Category": "Technology", "Sales": 836154.033},
]
Development
To develop crma-api-client, install dependencies and enable the pre-commit hook:
pip install pre-commit poetry
poetry install
pre-commit install -t pre-commit -t pre-push
To run tests:
poetry run pytest
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crma-api-client-0.9.0.tar.gz.
File metadata
- Download URL: crma-api-client-0.9.0.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.13.0-1023-aws
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8bc273914f7327607554f7bbe5b76a959a0a324fa448dd390258599af54809c
|
|
| MD5 |
e7e6775522844116a6398d687be55e06
|
|
| BLAKE2b-256 |
4a27928c87aa0212d667da8b66e7b42a3d15e8e14d51946adda0b926b2638c86
|
File details
Details for the file crma_api_client-0.9.0-py3-none-any.whl.
File metadata
- Download URL: crma_api_client-0.9.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.13 Linux/5.13.0-1023-aws
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
223201d6c952f3fa71dfa7ca3a84c90c286cdfb7aba5dc7839a5008b5cfcf4df
|
|
| MD5 |
175bddef9c85575ac16e09ae4fc39d7d
|
|
| BLAKE2b-256 |
0cf72a36598fd306d74f7ba812f74124c01e5bfaa615d9fd47b6f51b51c27bde
|