Skip to content

Latest commit

 

History

History
49 lines (35 loc) · 1.36 KB

README.md

File metadata and controls

49 lines (35 loc) · 1.36 KB

asynctempfile

DEPRECATED

**This code has been incorporated into the aiofiles depedency and will no longer be maintained here. Please see github.com/Tinche/aiofiles


Async interface for the standard tempfile module. Implements the following 4 interfaces:

  • TemporaryFile
  • NamedTemporaryFile
  • SpooledTemporaryFile
  • TemporaryDirectory

Blocking methods are delegated to threadpools using loop.run_in_executor(). Non-blocking methods and properties retain a sync interface. SpooledTemporaryFile only delegates if the in-memory stream is rolled to disk. New instances of the above classes return wrapped with a context manager allowing use with async with and async for.

Installation

pip install asynctempfile

Examples

import asynctempfile

async with asynctempfile.TemporaryFile('wb+') as f:
    await f.write(b'Hello, World!')
import asynctempfile

async with asynctempfile.NamedTemporaryFile('wb+') as f:
    await f.write(b'Line1\n Line2')
    await f.seek(0)
    async for line in f:
        print(line)

Dependencies

aiofiles

Release Notes

0.5.0

  • Adjusted TemporaryDirectory to return its path as opposed to the object when used with a context manager, aligning behaviour with the sync library (thank you to hellocoldworld).
  • Fixed name attribute for TemporaryFile as this property is now included in the aiofiles wrapper.