Created
July 14, 2025 20:37
-
-
Save jacobpedd/fef9f9a5e5dae4af5e8fd9a2527eb3a2 to your computer and use it in GitHub Desktop.
Websets 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": 18, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Created import: import_01k05abe1vpbcj6737ddf8ptgg\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", | |
"csv_path = './companies.csv'\n", | |
"\n", | |
"with open(csv_path, 'rb') as f:\n", | |
" csv_data = f.read()\n", | |
" csv_size_bytes = len(csv_data)\n", | |
"\n", | |
"csv_string = csv_data.decode('utf-8')\n", | |
"csv_size_mb = csv_size_bytes / 1024 / 1024\n", | |
"\n", | |
"import_job = 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 = import_job.id\n", | |
"print(f'Created import: {import_id}')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Created webset: webset_01k05actq7efahbg6kzxxg3f7t\n" | |
] | |
} | |
], | |
"source": [ | |
"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}')" | |
] | |
} | |
], | |
"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