Async version of tempfile
Project description
asynctempfile
Async interface for the standard tempfile module. Implements the following 4 classes:
- 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
Credit
An extension of github.com/Tinche/aiofiles
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asynctempfile-0.5.0.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for asynctempfile-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cec59bdb71c850e3de9bb4415f88998165c364709696240eea9ec5204a7439af |
|
MD5 | 7ccebb82935d7b696a6a5d4dbf4e4a35 |
|
BLAKE2b-256 | 2069d9119d7ebd3af8a111605453982b7c107f28cbccac5ce068104b25437afc |