Recipes

Recipes

Load CSV to Identity Streme

A simple python script which resolves a CSV of customer records (in MultiFieldRequest format) and creates an output CSV file with appended personIds for each record (if available).

See more examples and read about the python Resolve library here: https://github.com/fullcontact/fullcontact-python-client#resolve-api

In this Recipe

  1. Import libraries

  2. Fetch API key from secure location

  3. Define input and output files

  4. Instantiate FullContact client

  5. Open input file

  6. Call identity.resolve for each row (record)

  7. Write output file from stored outputs


Python Code

#!/usr/bin/env python3

import csv
import os
from fullcontact import FullContactClient

# Fetch API Key from env variable "FC_API_KEY"
API_KEY = os.environ.get('FC_API_KEY')

# Define input, output file names
input_file = './input.csv'
output_filename= './output.csv'
outputs = []

fullcontact_client = FullContactClient(api_key=API_KEY)

with open(input_file, encoding='utf-8') as csvf:
    csv_reader = csv.DictReader(csvf)
    for row in csv_reader:
        try:
            # Pass all row K:V pairings to API.
            future = fullcontact_client.identity.resolve_async(**row)
            result = future.result()
            personIds = result.get_personIds()
            row['personIds'] = personIds
        except Exception as e:
            # Generic exception handling. Should be more granular in a production env
            print('something went wrong: ', e)
            row['personIds'] = []
        outputs.append(row)

with open(output_filename, 'w', newline='') as output_file:
    # Define header based on one row's keys
    keys = outputs[0].keys()
    out_writer = csv.DictWriter(output_file, keys)
    out_writer.writeheader()
    for row in outputs:
        out_writer.writerow(row)