Created
July 14, 2025 20:41
-
-
Save jacobpedd/c53ad2728aae4e0616dc3e5ae8e6ed4d to your computer and use it in GitHub Desktop.
Webset CSV search example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Created import: import_01k05anqjyysybg4fh8p8srxt1\n" | |
] | |
} | |
], | |
"source": [ | |
"# pip install exa-py\n", | |
"# pip install python-dotenv\n", | |
"from exa_py import Exa\n", | |
"import dotenv\n", | |
"import os\n", | |
"\n", | |
"dotenv.load_dotenv()\n", | |
"\n", | |
"exa = Exa(os.getenv('EXA_API_KEY'))\n", | |
"\n", | |
"\n", | |
"# Import csv\n", | |
"csv_path = './companies.csv'\n", | |
"with open(csv_path, 'rb') as f:\n", | |
" csv_data = f.read()\n", | |
"\n", | |
"# Parse csv data\n", | |
"csv_size_bytes = len(csv_data)\n", | |
"csv_string = csv_data.decode('utf-8')\n", | |
"csv_size_mb = csv_size_bytes / 1024 / 1024\n", | |
"\n", | |
"# Create an import\n", | |
"csv_import = exa.websets.imports.create(params={\n", | |
" 'entity': {\n", | |
" 'type': 'company',\n", | |
" },\n", | |
" 'format': 'csv',\n", | |
" 'csv_data': csv_string,\n", | |
" 'size': csv_size_mb,\n", | |
" 'count': len(csv_string.split('\\n')),\n", | |
"})\n", | |
"\n", | |
"\n", | |
"import_id = csv_import.id\n", | |
"print(f'Created import: {import_id}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Created webset: webset_01k05anr1rb6sxjc046yd90b45\n" | |
] | |
} | |
], | |
"source": [ | |
"# Create a new webset that searches over the import\n", | |
"webset = exa.websets.create(params={\n", | |
" 'search': {\n", | |
" 'query': 'company is based in SF',\n", | |
" 'count': 1\n", | |
" },\n", | |
" 'import': [{\n", | |
" 'source': 'import',\n", | |
" 'id': import_id\n", | |
" }]\n", | |
"})\n", | |
"\n", | |
"print(f'Created webset: {webset.id}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": ".venv", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.13.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment