Async Files
Project description
async-files
async-files is a fast, lightweight, and extensible asyncio file library, written in pure python and inspired by aiofiles. This works just like aiofiles which delegates file IO operations to a separate thread pool. Although, async-files have been completely re-written from scratch to use modern async...await...
syntax and with extensibility and flexibility in mind.
Usage
Files can be opened with async context manager or by calling FileIO instance.
async with FileIO("README.md") as f:
s = await f.read()
print(s)
or
f = await FileIO("README.md")() # __init__ can't be asynchronous.
s = await f.read()
print(s)
await f.close()
Asynchronous iteration is also supported.
async with FileIO("README.md") as f:
async for line in f:
print(line, end="")
You can also extend functionality of FileIO to support other classes like tempfile.TemporaryFile
very easily:
from tempfile import TemporaryFile as _TemporaryFile
from async_files import FileIO
class TemporaryFile(FileIO):
OPEN = _TemporaryFile
You can do same for any IO classes like GzipFile
, SpooledTemporaryFile
, etc.
Following are asynchronous attributes of the FileIO object.
close: Callable[[], Awaitable[None]]
flush: Callable[[], Awaitable[None]]
isatty: Callable[[], Awaitable[bool]]
read: Callable[[], Awaitable[Union[str, bytes]]]
read1: Callable[[], Awaitable[bytes]]
readinto: Callable[[bytearray], Awaitable[int]]
readinto1: Callable[[bytearray], Awaitable[int]]
readline: Callable[[], Awaitable[Union[str, bytes]]]
readlines: Callable[[], Awaitable[List[Union[str, bytes]]]]
seek: Callable[[], Awaitable[int]]
tell: Callable[[], Awaitable[int]]
truncate: Callable[[], Awaitable[int]]
write: Callable[[Union[str, bytes]], Awaitable[int]]
writelines: Callable[[List[Union[str, bytes]]], Awaitable[None]]
Other attributes are synchronous just like standard library fileobj.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for async_files-0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9fbc3ae35f6d150cdb8e28e9819aa64b1bf2400a7a80ef76708d3cccbeb47bba |
|
MD5 | a782ab4dfe5196c26857bdd7837ff41b |
|
BLAKE2b-256 | 430b2e502f6335fb9b9c92b51823afa14471f3c1b89f7498e828b0422f13ccfe |