Skip to main content

How to contribute

After clone repository

1.- Install dependencies

poetry install

2.- Run test

make test

3.- Run lint

make lint && make isort

How to publish new version

Once we have done a merge of our Pull request and we have the updated master branch we can generate a new version. For them we have 3 commands that change the version of our library and generate the corresponding tag so that the Bitbucket pipeline starts and publishes our library automatically.

make release-patch
make release-minor
make release-major

How works

This project provides an API for querying Salesforce opportunities data and transforming it into an easy-to-use format. The API is built upon the SalesforceQueryExecutor and Project classes, with the latter inheriting from SalesforceQueryExecutor.

Installation

Make sure you have Python 3.8+ installed. Then, install the required dependencies using poetry:

poetry install ms-salesforce-api

Testing

To run the unit tests, simply execute the following command:

make test

This will run all the tests and display the results. Make sure that all tests pass before using the API in a production environment.

Usage

First, import the necessary classes:

from ms_salesforce_api.salesforce.project import Project

Then, initialize the Project class with your Salesforce credentials:

project = Project(
    client_id="your_client_id",
    username="your_username",
    domain="your_domain",
    private_key="your_private_key",
    audience="https://login.salesforce.com", # Default value
    session_duration_hours=1, # Default value
    api_version='57.0',  # Default value
)

Now, you can call the get_all method with a query to get the opportunities data:

opportunities = project.get_all()

The opportunities variable will contain an array of opportunity objects with the transformed data. For example:

[
 {
    "account_assigment_group": None,
    "account_billing_address": "C/ XXX XXX, 8 Planta 9ª, 28020, Spain",
    "account_billing_city": None,
    "account_billing_country": "ES",
    "account_billing_postal_code": "28020",
    "account_billing_state_code": None,
    "account_billing_street": "C/ XXX XXX, 8 Planta 9ª",
    "account_business_function": "XXXX",
    "account_business_name": "XXXXXX",
    "account_cif": "ESXXXXXXX",
    "account_company_invoicing": "2411",
    "account_created_date": "2022-03-28T09:05:44.000+0000",
    "account_currency_code": "",
    "account_fax": None,
    "account_invoicing_email": None,
    "account_mail_invoicing": None,
    "account_name": "XXXXXXXX",
    "account_office": "XXXXXXXX",
    "account_payment_terms": "T030",
    "account_pec_email": None,
    "account_phone": None,
    "account_sap_id": "10001210",
    "account_tax_category": None,
    "account_tax_classification": None,
    "account_tax_id_type": "ES0",
    "account_tier": "T1",
    "account_website": None,
    "amount": 0,
    "billing_lines": [
        {
            "billing_amount": 274.33,
            "billing_date": "2022-01-31",
            "billing_period_ending_date": "2022-03-31",
            "billing_period_starting_date": "2022-01-01",
            "billing_plan_amount": "274.33",
            "billing_plan_billing_date": "2022-01-31",
            "billing_plan_item": "0",
            "billing_plan_service_end_date": "2022-03-31",
            "billing_plan_service_start_date": "2022-01-01",
            "created_date": "2022-07-08T10:07:08.000+0000",
            "currency": "EUR",
            "hourly_price": None,
            "id": "XXXXXXXXXXXX",
            "last_modified_date": "2023-05-04T12:24:25.000+0000",
            "name": "BL-XXXXXXXX",
            "project_id": "YYYYYYYYYYYYY",
            "revenue_dedication": None,
        }
    ],
    "controller_email": "employee@makingscience.com",
    "controller_sub_email": "",
    "cost_center": "0220001800",
    "created_at": "2021-10-06T14:35:18.000+0000",
    "currency": "EUR",
    "invoicing_country_code": "ES",
    "jira_task_url": "<a href=https://makingscience.atlassian.net/browse/ESMSBD0001-1080 target=_blank>View Jira Task</a>",
    "last_updated_at": "2023-06-08T11:22:55.000+0000",
    "lead_source": "Employee Referral",
    "operation_coordinator_email": "employee@makingscience.com",
    "operation_coordinator_sub_email": "",
    "opportunity_name": "Branding Campaign",
    "opportunity_percentage": 100.0,
    "profit_center": "200018",
    "project_code": "ESMSEX01652",
    "project_id": "a003X00001WS2YHQA1",
    "project_line_items": [
        {
            "country": "Spain",
            "created_date": "2022-05-05T12:28:48.000+0000",
            "effort": None,
            "ending_date": "2022-03-31",
            "id": "a0V7U000001OdiUUAS",
            "last_modified_date": "2023-06-08T11:20:42.000+0000",
            "ms_pli_name": "Omnichannel_ESMSEx01652_ES",
            "product_name": "Advertising Lead Gen Proj",
            "quantity": None,
            "starting_date": "2022-01-01",
            "total_price": 0.0,
            "unit_price": 2230.99,
        }
    ],
    "project_name": "BrandingCampaignPilotESMSEx01652",
    "project_start_date": "2021-12-01",
    "project_tier": "Unkown",
    "stage": "Closed Won",
}
]

You can customize the query as needed to retrieve different data from Salesforce.

query = "SELECT Id, Name FROM Project WHERE Project.Id = 'ESMS0000'"

opportunities = project.get_all(query=query)

Export data

This library allow to export all opportunities data to a external database such Postgres and BigQuery. Podemos importar cualquiera de las clases:

from ms_salesforce_api.salesforce.api.project.export_data.Bigquery import (
    BigQueryExporter,
)

o

from ms_salesforce_api.salesforce.api.project.export_data.CloudSQL import (
    CloudSQL
)

Both classes, when initialized, are in charge of creating the databases and the tables to export the data in case they do not exist.

BigQueryExporter

The Bigquery class provides functionalities to export data to Google BigQuery.

ℹ️ Información
The "BigqueryExporter" class needs an environment variable named "GOOGLE_SERVICE_ACCOUNT_CREDENTIALS" to exist and its value must be the JSON of the Service Account that has permissions to write to BigQuery and must be in base64
class BigqueryExporter:
    def __init__(self, project_id: str, dataset_id: str):
        """
        Initializes the Bigquery exporter with the given project ID and dataset ID.

        Args:
            project_id (str): The ID of the Google Cloud project.
            dataset_id (str): The ID of the BigQuery dataset.
        """

Methods

  • export_data(data: List[Dict[str, Any]]) -> None Exports the provided data to BigQuery.

    • data (List[Dict[str, Any]]): This variable has the value of "opportunities" returned by the "get_all" method.
  • delete_all_rows() -> None Delete all data for each table (Opportunities, Accounts, Billing line and PLIs). In this way we can have the database updated at all times.

CloudSQL

The CloudSQL class provides functionalities to interact with a Google Cloud SQL database.

Constructor

class CloudSQL:
     def __init__(self, host, user, password, dbname, debug_mode=False):
        """
        Connect with a Postgres Database with the given
        host name, database name, username, and password.

        Args:
            host (str): The host name for the Postgres database.
            user (str): The username for accessing the database.
            password (str): The password for accessing the database.
            dbname (str): The name of the database.
        """

Methods

  • export_data(data: List[Dict[str, Any]]) -> None Exports the provided data to BigQuery.

    • data (List[Dict[str, Any]]): This variable has the value of "opportunities" returned by the "get_all" method.
  • delete_all_rows() -> None Delete all data for each table (Opportunities, Accounts, Billing line and PLIs). In this way we can have the database updated at all times.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ms_salesforce_api-3.13.0.tar.gz (66.6 kB view details)

Uploaded Source

Built Distribution

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

ms_salesforce_api-3.13.0-py3-none-any.whl (108.7 kB view details)

Uploaded Python 3

File details

Details for the file ms_salesforce_api-3.13.0.tar.gz.

File metadata

  • Download URL: ms_salesforce_api-3.13.0.tar.gz
  • Upload date:
  • Size: 66.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for ms_salesforce_api-3.13.0.tar.gz
Algorithm Hash digest
SHA256 2525ed3d43d67fd4cd55032b197b0a923cceda2f0103b40a3b9a7da99e33d199
MD5 b97ee9e1657f32c2df8ab22b9bca9859
BLAKE2b-256 6baa90a227e29a253bfffcf6c0840529d52fc26d2354c64d4ff5c5a7797652ae

See more details on using hashes here.

File details

Details for the file ms_salesforce_api-3.13.0-py3-none-any.whl.

File metadata

  • Download URL: ms_salesforce_api-3.13.0-py3-none-any.whl
  • Upload date:
  • Size: 108.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.3 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for ms_salesforce_api-3.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8fdd4e8f48187f72b3494c518dbdf7ff2e6776cd30b8128b08337e478c75a21
MD5 efa98ac8700e72da0e7cc4ff6be8bb77
BLAKE2b-256 0085e262a0410b343751b21ecccae3ae3df90a5a361a034477927ce76934560f

See more details on using hashes here.

Release history Release notifications | RSS feed

3.13.1

2 files

This release

3.13.0 This release

2 files

3.12.0

2 files

3.11.0

2 files

3.10.2

2 files

3.10.1

2 files

3.10.0

2 files

3.9.1

2 files

3.9.0

2 files

3.8.1

2 files

3.8.0

2 files

3.7.0

2 files

3.6.0

2 files

3.5.0

2 files

3.4.0

2 files

3.3.0

2 files

3.2.0

2 files

3.1.1

2 files

3.1.0

2 files

3.0.1

2 files

3.0.0

2 files

2.24.0

2 files

2.23.0

2 files

2.21.0

2 files

2.20.0

2 files

2.19.1

2 files

2.19.0

2 files

2.18.1

2 files

2.18.0

2 files

2.17.0

2 files

2.16.1

2 files

2.16.0

2 files

2.15.0

2 files

2.14.0

2 files

2.13.0

2 files

2.12.0

2 files

2.11.1

2 files

2.11.0

2 files

2.10.0

2 files

2.9.0

2 files

2.8.1

2 files

2.8.0

2 files

2.7.0

2 files

2.6.3

2 files

2.6.2

2 files

2.6.1

2 files

2.6.0

2 files

2.5.0

2 files

2.4.1

2 files

2.4.0

2 files

2.3.0

2 files

2.2.1

2 files

2.2.0

2 files

2.1.1

2 files

2.1.0

2 files

2.0.0

2 files

1.6.4

2 files

1.6.3

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.4

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.0

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.0.44

2 files

0.0.43

2 files

0.0.42

2 files

0.0.41

2 files

0.0.40

2 files

0.0.39

2 files

0.0.38

2 files

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