from typing import BinaryIO, cast import smart_open from pydantic import HttpUrl from src.connectors.aws import s3 def create_presigned_url(bucket: str, key: str, *, expires_in_seconds: int) -> HttpUrl: return HttpUrl( s3.generate_presigned_url( "get_object", Params={"Bucket": bucket, "Key": key}, ExpiresIn=expires_in_seconds, ) ) def open_s3_seekable(bucket: str, key: str) -> BinaryIO: return cast(BinaryIO, smart_open.open(f"s3://{bucket}/{key}", "rb", transport_params={"client": s3}))