feat: add s3_exists to DataStore

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-08 08:31:40 -07:00
parent ba003bd293
commit 0cb2de58c5

View File

@@ -3,6 +3,7 @@ import csv
import io import io
import json import json
import boto3 import boto3
from botocore.exceptions import ClientError
from dataclasses import dataclass from dataclasses import dataclass
from typing import Any from typing import Any
import hashlib import hashlib
@@ -87,5 +88,16 @@ class DataStore:
Metadata=metadata, Metadata=metadata,
) )
async def s3_exists(self, key: str) -> bool:
def _check():
try:
self._client.head_object(Bucket=self.config.bucket, Key=key)
return True
except ClientError as e:
if e.response["Error"]["Code"] == "404":
return False
raise
return await asyncio.to_thread(_check)
def hash(self, content: str): def hash(self, content: str):
return hashlib.md5(content.encode()).hexdigest() return hashlib.md5(content.encode()).hexdigest()