Real asynchronous file operations with asyncio support.
Status
Development - Stable
Features
Code examples
All code examples requires python 3.5+.
Write and Read
import asyncio
from aiofile import AIOFile, Reader, Writer
async def main():
async with AIOFile("/tmp/hello.txt", 'w+') as afp:
await afp.write("Hello ")
await afp.write("world", offset=7)
await afp.fsync()
print(await afp.read())
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Write and read with helpers
import asyncio
from aiofile import AIOFile, Reader, Writer
async def main():
async with AIOFile("/tmp/hello.txt", 'w+') as afp:
writer = Writer(afp)
reader = Reader(afp, chunk_size=8)
await writer("Hello")
await writer(" ")
await writer("World")
await afp.fsync()
async for chunk in reader:
print(chunk)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Read file line by line
import asyncio
from aiofile import AIOFile, LineReader, Writer
async def main():
async with AIOFile("/tmp/hello.txt", 'w+') as afp:
writer = Writer(afp)
await writer("Hello")
await writer(" ")
await writer("World")
await writer("\n")
await writer("\n")
await writer("From async world")
await afp.fsync()
async for line in LineReader(afp):
print(line)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Reading and Writing for the unix pipe
import os
import asyncio
from aiofile import AIOFile, Reader, Writer
async def reader(fname):
print('Start reader')
async with AIOFile(fname, 'r') as afp:
while True:
# Maximum expected chunk size, must be passed.
# Otherwise will be read zero bytes
# (because unix pipe has zero size)
data = await afp.read(4096)
print(data)
async def writer(fname):
print('Start writer')
async with AIOFile(fname, 'w') as afp:
while True:
await asyncio.sleep(1)
await afp.write('%06f' % loop.time())
async def main():
fifo_name = "/tmp/test.fifo"
if os.path.exists(fifo_name):
os.remove(fifo_name)
os.mkfifo(fifo_name)
# Starting two readers and one writer, but only one reader
# will be reading at the same time.
await asyncio.gather(
reader(fifo_name),
reader(fifo_name),
writer(fifo_name),
)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
try:
loop.run_until_complete(main())
finally:
# Shutting down and closing file descriptors after interrupt
loop.run_until_complete(loop.shutdown_asyncgens())
loop.close()
print('Exited')
Metadata
Release files for aiofile 1.4.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiofile-1.4.2.tar.gz | 76.6 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| aiofile-1.4.2-cp36-cp36m-manylinux1_x86_64.whl | CPython 3.6 | CPython 3.6 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| aiofile-1.4.2-cp36-cp36m-macosx_10_6_intel.whl | CPython 3.6 | CPython 3.6 pymalloc | macOS 10.6+ Intel (x86-64, i386) | Details |
| aiofile-1.4.2-cp35-cp35m-manylinux1_x86_64.whl | CPython 3.5 | CPython 3.5 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| aiofile-1.4.2-cp35-cp35m-macosx_10_6_intel.whl | CPython 3.5 | CPython 3.5 pymalloc | macOS 10.6+ Intel (x86-64, i386) | Details |
| aiofile-1.4.2-cp34-cp34m-manylinux1_x86_64.whl | CPython 3.4 | CPython 3.4 pymalloc | Linux glibc 2.5+ x86-64 | Details |
| aiofile-1.4.2-cp34-cp34m-macosx_10_6_intel.whl | CPython 3.4 | CPython 3.4 pymalloc | macOS 10.6+ Intel (x86-64, i386) | Details |
Total release size: 932.2 kB
Release files / aiofile-1.4.2.tar.gz
| Download URL | aiofile-1.4.2.tar.gz |
|---|---|
| Size | 76.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd96a8615f55373d53b14fbd269fbc712cfc3c859ea1ae0b2a5ea47bda6a35f7
|
|
BLAKE2b-256 checksum How to use checksums |
017c9ebede7399adf80cd4169c21bf3c539a3bace0c850e983f5d8c2cb7ec692
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp36-cp36m-manylinux1_x86_64.whl
| Download URL | aiofile-1.4.2-cp36-cp36m-manylinux1_x86_64.whl |
|---|---|
| Size | 184.5 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
51f2ff00be78356a99b4daf64ece69382d28e775576324b6254847cdbc5a4e2c
|
|
BLAKE2b-256 checksum How to use checksums |
8abedbf758ff67215391280c11931974ede135a26330af309c22f9c40446708e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp36-cp36m-macosx_10_6_intel.whl
| Download URL | aiofile-1.4.2-cp36-cp36m-macosx_10_6_intel.whl |
|---|---|
| Size | 100.0 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
9d20e29030172f72fd407a456090a9615f87cff6e7d916149d7244678246b46a
|
|
BLAKE2b-256 checksum How to use checksums |
684dcb2bd710ce73eacdf61a8cc65501df0b3b45b7e7c6b2f5f347da2e4345b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp35-cp35m-manylinux1_x86_64.whl
| Download URL | aiofile-1.4.2-cp35-cp35m-manylinux1_x86_64.whl |
|---|---|
| Size | 185.2 kB |
| Tags | CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
a3efa8ae12f8649e173b025ea8f0eb85c1ed4746e8b4379126617e897e469456
|
|
BLAKE2b-256 checksum How to use checksums |
53e07487cd4586af0bd55b78f6667396a86da8b92cacc492a0fb0958ed7ccca0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp35-cp35m-macosx_10_6_intel.whl
| Download URL | aiofile-1.4.2-cp35-cp35m-macosx_10_6_intel.whl |
|---|---|
| Size | 99.2 kB |
| Tags | CPython 3.5 CPython 3.5 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
f1bea098107215418d2ffd1688bf6e01de6c6406851f11a1c4b6b94077c24481
|
|
BLAKE2b-256 checksum How to use checksums |
76c185fe63f85d165ef62fd0cc8935700557f1a198a59980d90b3b2ad42e8806
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp34-cp34m-manylinux1_x86_64.whl
| Download URL | aiofile-1.4.2-cp34-cp34m-manylinux1_x86_64.whl |
|---|---|
| Size | 189.5 kB |
| Tags | CPython 3.4 CPython 3.4 pymalloc Linux glibc 2.5+ x86-64 |
|
SHA-256 checksum How to use checksums |
821b99e79114ce7d42ff06d65dcc41652958a7135e57d3e5823fd94ade862d6a
|
|
BLAKE2b-256 checksum How to use checksums |
f93abe79caf807a9a35925efa9248678b9d12c01d1db7f70c856c16a094232f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / aiofile-1.4.2-cp34-cp34m-macosx_10_6_intel.whl
| Download URL | aiofile-1.4.2-cp34-cp34m-macosx_10_6_intel.whl |
|---|---|
| Size | 97.1 kB |
| Tags | CPython 3.4 CPython 3.4 pymalloc macOS 10.6+ Intel (x86-64, i386) |
|
SHA-256 checksum How to use checksums |
e2f8b44aed7d742d387c915f1b9d93e71639061c1cb3bc35ddce9e4c267cec84
|
|
BLAKE2b-256 checksum How to use checksums |
db8641e96f339f81c013af1114b4ed2d9966daf7f78f65c35ed83cb092d6b147
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |