Skip to content

Instantly share code, notes, and snippets.



Last active Sep 29, 2016
What would you like to do?
Get addresses with contact information over api

Set the environment variables:

export FULFIL_SUBDOMAIN=your_subdomain
export FULFIL_API_KEY=a-long-api-key-which-is-secret

Install the dependencies

$ pip install -r requirements.txt

Run the script

import os
from fulfil_client import Client
from unicodecsv import DictWriter
client = Client(os.environ['FULFIL_SUBDOMAIN'], os.environ['FULFIL_API_KEY'])
Contact = client.model('')
Address = client.model('party.address')
def get_addresses(fields, writer):
contact_count = Contact.search_count([])
address_count = Address.search_count([])
print "Total contacts in DB: %s" % contact_count
print "Total addresses in DB: %s" % address_count
addresses = []
batch_size = 1000
for offset in xrange(0, address_count, batch_size):
print "Fetching %s to %s" % (
offset + 1, offset + batch_size
addresses = Address.search_read(
[], offset, batch_size, None, fields
return addresses
if __name__ == '__main__':
fields = [
with open('addresses1.csv', 'w') as csv_file:
writer = DictWriter(csv_file, fields)
get_addresses(fields, writer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.