# pip install aiohttp aiofiles
import aiohttp
import aiofiles
async def download_file(url: str, output_file_path: str, *, session: aiohttp.ClientSession | None = None) -> None:
close_session = False
if session is None:
session = aiohttp.ClientSession()
close_session = True
try:
async with session.get(url) as response:
response.raise_for_status()
async with aiofiles.open(output_file_path, 'wb') as file:
async for chunk in response.content.iter_any():
await file.write(chunk)
finally:
if close_session:
await session.close()