Group bulk handler

Retrieving the bulk handler

class GroupBulkhandlerMixin
get_group_bulkhandler(feedback=False, create_groups=False, callback=None)

Perform bulk “update” and/or “insert” operations on groups. This functions returns a BulkHandler object that can be used to perform the bulk operations.

  • feedback (bool) – If set to True feedback will be shown when groups have been written to BlueConic. Defaults to False.

  • create_groups (bool) – Create new groups if Group is not found

  • callback (Callable) – Callback to perform when REST response is received


BulkHandler for groups

Return type


Using the bulk handler

class BulkHandler

Closes the stream and writes the changes to BlueConic.


Open a stream to BlueConic.


Writes the changes in a bulkhandler object back to BlueConic.


writable_object (ProfileOperation, Profile (deprecated), Group) – The object to be updated in BlueConic

  • ValueError – The temporary file is not open.

  • TypeError – The variable ‘writable_object’ is not of type HashMap.

The with statement simplifies the writing and ensures that clean-up code is executed. It is possible to write groups to BlueConic without the with statement. The following code block provides such an example.

>>> import blueconic
>>> bc = blueconic.Client()
>>> group_bulkhandler = bc.get_group_bulkhandler(feedback=True)
>>> group_bulkhandler.open_stream()
>>> example_group = bc.get_group(group_id='group_0', group_type_id='company')
>>> example_group.add_value('nr_of_employees', 42)
>>> group_bulkhandler.write(example_group)
>>> group_bulkhandler.flush()
[{'groupId': 'company_group_0', 'state': 'MODIFIED'}]
<Response [200]>

Importing data from an external source

The bulk handler can also be used to create or update groups without retrieving them from BlueConic first. This allows to more efficiently import data from an external data source. The following code would import group data into BlueConic, update a group if the given group_id exists, and otherwise create a new group.

>>> from blueconic import Client, Group
>>> bc = Client()
>>> group_type_id = "company"
>>> with bc.get_group_bulkhandler(create_groups=True) as handler:
...     for group in group_data:
...         group = Group(group['id'], group_type_id)
...         group.set_value('nr_of_employees', 42)
...         handler.write(group)

If create_groups=False is passed, and an existing group cannot be found, the data is ignored.