mixpanel/salesforce-bulk

Name: salesforce-bulk

Owner: Mixpanel, Inc

Description: Python interface to the Salesforce.com Bulk API

Created: 2016-03-22 00:38:34.0

Updated: 2016-03-22 00:38:35.0

Pushed: 2016-03-22 00:48:24.0

Homepage: null

Size: 46

Language: Python

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Salesforce Bulk

Python client library for accessing the asynchronous Salesforce.com Bulk API.

Installation
uthentication

ccess the Bulk API you need to authenticate a user into Salesforce. The easiest
to do this is just to supply `username` and `password`. This library
 use the `salesforce-oauth-request` package (which you must install) to run
Salesforce OAUTH2 Web flow and return an access token.

from salesforce_bulk import SalesforceBulk

bulk = SalesforceBulk(username=username,password=password) …

rnatively if you run have access to a session ID and instance_url you can use
e directly:

from urlparse import urlparse from salesforce_bulk import SalesforceBulk

bulk = SalesforceBulk(sessionId=sessionId, host=urlparse(instance_url).hostname) …

perations

basic sequence for driving the Bulk API is:

reate a new job
dd one or more batches to the job
ait for each batch to finish
lose the job


ulk Query

esforceBulk.create_query_job(object_name, contentType='CSV', concurrency=None)`

ple

job = bulk.create_query_job(“Contact”, contentType='CSV') batch = bulk.query(job, “select Id,LastName from Contact”) while not bulk.is_batch_done(job, batch):

sleep(10)

bulk.close_job(job)

for row in bulk.get_batch_result_iter(job, batch, parse_csv=True):

print row   #row is a dict
ulk Insert, Update, Delete

Bulk upload operations work the same. You set the operation when you create the
 Then you submit one or more documents that specify records with columns to
rt/update/delete. When deleting you should only submit the Id for each record.

efficiency you should use the `post_bulk_batch` method to post each batch of
. (Note that a batch can have a maximum 10,000 records and be 1GB in size.)
pass a generator or iterator into this function and it will stream data via
 to Salesforce. For help sending CSV formatted data you can use the
sforce_bulk.CsvDictsAdapter class. It takes an iterator returning dictionaries
returns an iterator which produces CSV data.

 example:

from salesforce_bulk import CsvDictsAdapter

job = bulk.create_insert_job(“Account”, contentType='CSV')

accounts = [dict(Name=“Account%d” % idx) for idx in xrange(5)]

csv_iter = CsvDictsAdapter(iter(accounts))

batch = bulk.post_bulk_batch(job, csv_iter)

bulk.wait_for_batch(job, batch)

bulk.close_job(job)

print “Done. Accounts uploaded.”

Concurrency mode

 creating the job, pass `concurrency=Serial` or `concurrency=Parallel` to set the
urrency mode for the job.

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.