Skip to main content

Nameko extension for easy communication with Salesforce (Including Streaming API)

Project description

https://travis-ci.org/Overseas-Student-Living/nameko-salesforce.svg?branch=extract-from-internal-salesforce-lib

Nameko Salesforce

A Nameko extension with entrypoints for handling Salesforce Streaming API events and a dependency provider for easy communication with Salesforce REST API.

The Streaming API extension is based on Nameko Cometd Bayeux Client and the REST API dependency id based on Simple Salesforce.

Quick Start

Install from PyPI:

pip install nameko-salesforce

Create a service which handles Salesforce Contact objects changes and also has an RPC endpoint for creating new Contact objects in Salesforce:

# service.py

from nameko.rpc import rpc
from nameko_salesforce.streaming import handle_sobject_notification
from nameko_salesforce.api import SalesforceAPI

class Service:

    name = 'some-service'

    salesforce = SalesforceAPI()

    @handle_sobject_notification('Contact', exclude_current_user=False)
    def handle_contact_updates(
        self, sobject_type, record_type, notification
    ):
    """ Handle Salesforce contacts updates
    """
    print(notification)

    @rpc
    def create_contact(self, last_name, email_address):
    """ Create a contact in Salesforce
    """
    self.salesforce.Contact.create(
        {'LastName': last_name,'Email': email_address})

Create a config file with essential settings:

# config.yaml

AMQP_URI: 'pyamqp://guest:guest@localhost'
SALESFORCE:
    USERNAME: ${SALESFORCE_USERNAME}
    PASSWORD: ${SALESFORCE_PASSWORD}
    SECURITY_TOKEN: ${SALESFORCE_SECURITY_TOKEN}
    SANDBOX: False

Run the service providing your Salesforce credentials:

$ SALESFORCE_USERNAME=rocky \
  SALESFORCE_PASSWORD=*** \
  SALESFORCE_SECURITY_TOKEN=*** \
  nameko run --config config.yaml service

Finally, open another shell and call the RPC endpoint to create a new user:

$ nameko shell --config config.yaml
In [1]: n.rpc['some-service'].create_contact('Yo', 'yo@yo.yo')

You should see a new contact created in Salesforce and your service should get a notification. In the first shell you’ll find the notification printed:

{'event': {'replayId': 1, 'type': 'created' ...

For more checkout the documentation.

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

nameko-salesforce-1.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

nameko_salesforce-1.1.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file nameko-salesforce-1.1.0.tar.gz.

File metadata

File hashes

Hashes for nameko-salesforce-1.1.0.tar.gz
Algorithm Hash digest
SHA256 eec81081f8b37f90396c2571d45fa3ec0e2c88fbd8322491fd2502cc53464721
MD5 ab2635493253adab52d53243dcd91fe5
BLAKE2b-256 e0cfec57d55a908ca4ad40851d1cf968cc41ad58e09f653e4134f1972802f15d

See more details on using hashes here.

File details

Details for the file nameko_salesforce-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for nameko_salesforce-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1777b1caac14b4f3a02f70d3ef72abe82d2a9b0d4b5fc9437bc23ece428af317
MD5 6b3c29400f1bf09504bf4580c14a9886
BLAKE2b-256 a4563940c5afc34c57c4b05f58ddd0345c21a2f4bda032f04612caeed1b16b5f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page