---
updatedAt: 2025-06-09T20:46:12.000Z
agentTools:
  projectIndex: https://docs.fullcontact.com/llms.txt
---

# Load CSV to Identity Streme

```python Python
#!/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)


```

# Import libraries

<!-- python@2-5 -->

Get the FullContact Python client here: https://github.com/fullcontact/fullcontact-python-client

# Fetch API key from secure location

<!-- python@8 -->

Keep your API key safe! In this case, the API key is stored as an environment variable "FC_API_KEY"

# Define input and output files

<!-- python@11-13 -->

This script uses generic names of `input` and `output` but these will likely be different depending on your needs/workflows. 

Note: This script stores output rows in memory as a List

# Instantiate FullContact client

<!-- python@15 -->

Using your API, instantiate the FullContact client. See the full list of configurations here: https://github.com/fullcontact/fullcontact-python-client#client-configuration

# Open input file

<!-- python@17-20 -->

Converts CSV inputs to python dict objects, which will be sent to Resolve as MultiFieldRequest (https://github.com/fullcontact/fullcontact-python-client#multifieldrequest)

# Call identity.resolve for each row (record)

<!-- python@21-31 -->

Each row is sent to the identity.resolve API, the future result is collected and the personIds are collected from the response. A new row is generated by appending the resultant personIds to the input row and stored in a list object named "outputs"

Note: The exception handling of this example is very generic. Tread lightly!

# Write output file from stored outputs

<!-- python@33-39 -->

This section defines the header from one result (input headers + personId in this case). The list of stored outputs are written to the named output file: output.csv