Skip to main content

Python interface to the Salesforce.com Bulk API.

Project description

# Salesforce Bulk

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

## Installation

```pip install salesforce-bulk```

## Authentication

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

```
from saleforce_bulk import SalesforceBulk

bulk = SalesforceBulk(username=username,password=password)
...
```

Alternatively if you run have access to a session ID and instance_url you can use
those directly:

```
from urlparse import urlparse
from saleforce_bulk import SalesforceBulk

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

## Operations

The basic sequence for driving the Bulk API is:

1. Create a new job
2. Add one or more batches to the job
3. Wait for each batch to finish
4. Close the job


## Bulk Query

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

Example

```
job = bulk.create_query_job("Contact", contentType='CSV')
batch = bulk.query("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
```

## Bulk Insert, Update, Delete

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

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

Full 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

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

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

salesforce-bulk-1.0.2.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

salesforce-bulk-1.0.2.macosx-10.8-x86_64.exe (78.8 kB view details)

Uploaded Source

File details

Details for the file salesforce-bulk-1.0.2.tar.gz.

File metadata

File hashes

Hashes for salesforce-bulk-1.0.2.tar.gz
Algorithm Hash digest
SHA256 bfaa6a3d7a068d1c20d94df374ccf500a12233c1f45a3d87adbb016267a5cae3
MD5 f6ecd037fc8d28b7955f12069659d822
BLAKE2b-256 fdbce724cb8915101b0508791b086228f0805fa379d9fb52a9c4b7cbfa5bbabb

See more details on using hashes here.

File details

Details for the file salesforce-bulk-1.0.2.macosx-10.8-x86_64.exe.

File metadata

File hashes

Hashes for salesforce-bulk-1.0.2.macosx-10.8-x86_64.exe
Algorithm Hash digest
SHA256 1a12645b63a6bb0a0f54e782a9231ecdbbaaf89271e1c4df2d029690ba425214
MD5 6b03d448ce1027adc6cad6c8a8a29b77
BLAKE2b-256 70d649c86ac39d36463d924873d25f0aff331d7ee133dbf7588ebe7717f21033

See more details on using hashes here.

Supported by

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