You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

156 lines
4.3 KiB

  1. Metadata-Version: 2.0
  2. Name: aiofiles
  3. Version: 0.4.0
  4. Summary: File support for asyncio.
  5. Home-page: https://github.com/Tinche/aiofiles
  6. Author: Tin Tvrtkovic
  7. Author-email: tinchester@gmail.com
  8. License: Apache 2.0
  9. Platform: UNKNOWN
  10. Classifier: Development Status :: 4 - Beta
  11. Classifier: Intended Audience :: Developers
  12. Classifier: License :: OSI Approved :: Apache Software License
  13. Classifier: Programming Language :: Python :: 3.5
  14. Classifier: Programming Language :: Python :: 3.6
  15. Classifier: Programming Language :: Python :: 3.7
  16. Classifier: Topic :: System :: Filesystems
  17. aiofiles: file support for asyncio
  18. ==================================
  19. .. image:: https://img.shields.io/pypi/v/aiofiles.svg
  20. :target: https://pypi.python.org/pypi/aiofiles
  21. .. image:: https://travis-ci.org/Tinche/aiofiles.svg?branch=master
  22. :target: https://travis-ci.org/Tinche/aiofiles
  23. .. image:: https://codecov.io/gh/Tinche/aiofiles/branch/master/graph/badge.svg
  24. :target: https://codecov.io/gh/Tinche/aiofiles
  25. **aiofiles** is an Apache2 licensed library, written in Python, for handling local
  26. disk files in asyncio applications.
  27. Ordinary local file IO is blocking, and cannot easily and portably made
  28. asynchronous. This means doing file IO may interfere with asyncio applications,
  29. which shouldn't block the executing thread. aiofiles helps with this by
  30. introducing asynchronous versions of files that support delegating operations to
  31. a separate thread pool.
  32. .. code-block:: python
  33. async with aiofiles.open('filename', mode='r') as f:
  34. contents = await f.read()
  35. print(contents)
  36. 'My file contents'
  37. Asynchronous iteration is also supported.
  38. .. code-block:: python
  39. async with aiofiles.open('filename') as f:
  40. async for line in f:
  41. ...
  42. Features
  43. --------
  44. - a file API very similar to Python's standard, blocking API
  45. - support for buffered and unbuffered binary files, and buffered text files
  46. - support for ``async``/``await`` (:PEP:`492`) constructs
  47. Installation
  48. ------------
  49. To install aiofiles, simply:
  50. .. code-block:: bash
  51. $ pip install aiofiles
  52. Usage
  53. -----
  54. Files are opened using the ``aiofiles.open()`` coroutine, which in addition to
  55. mirroring the builtin ``open`` accepts optional ``loop`` and ``executor``
  56. arguments. If ``loop`` is absent, the default loop will be used, as per the
  57. set asyncio policy. If ``executor`` is not specified, the default event loop
  58. executor will be used.
  59. In case of success, an asynchronous file object is returned with an
  60. API identical to an ordinary file, except the following methods are coroutines
  61. and delegate to an executor:
  62. * ``close``
  63. * ``flush``
  64. * ``isatty``
  65. * ``read``
  66. * ``readall``
  67. * ``read1``
  68. * ``readinto``
  69. * ``readline``
  70. * ``readlines``
  71. * ``seek``
  72. * ``seekable``
  73. * ``tell``
  74. * ``truncate``
  75. * ``writable``
  76. * ``write``
  77. * ``writelines``
  78. In case of failure, one of the usual exceptions will be raised.
  79. The ``aiofiles.os`` module contains executor-enabled coroutine versions of
  80. several useful ``os`` functions that deal with files:
  81. * ``stat``
  82. * ``sendfile``
  83. Writing tests for aiofiles
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. Real file IO can be mocked by patching ``aiofiles.threadpool.sync_open``
  86. as desired. The return type also needs to be registered with the
  87. ``aiofiles.threadpool.wrap`` dispatcher:
  88. .. code-block:: python
  89. aiofiles.threadpool.wrap.register(mock.MagicMock)(
  90. lambda *args, **kwargs: threadpool.AsyncBufferedIOBase(*args, **kwargs))
  91. async def test_stuff():
  92. data = 'data'
  93. mock_file = mock.MagicMock()
  94. with mock.patch('aiofiles.threadpool.sync_open', return_value=mock_file) as mock_open:
  95. async with aiofiles.open('filename', 'w') as f:
  96. await f.write(data)
  97. mock_file.write.assert_called_once_with(data)
  98. History
  99. ~~~~~~~
  100. 0.4.0 (2018-08-11)
  101. ``````````````````
  102. - Python 3.7 support.
  103. - Removed Python 3.3/3.4 support. If you use these versions, stick to aiofiles 0.3.x.
  104. 0.3.2 (2017-09-23)
  105. ``````````````````
  106. - The LICENSE is now included in the sdist.
  107. `#31 <https://github.com/Tinche/aiofiles/pull/31>`_
  108. 0.3.1 (2017-03-10)
  109. ``````````````````
  110. - Introduced a changelog.
  111. - ``aiofiles.os.sendfile`` will now work if the standard ``os`` module contains a ``sendfile`` function.
  112. Contributing
  113. ~~~~~~~~~~~~
  114. Contributions are very welcome. Tests can be run with ``tox``, please ensure
  115. the coverage at least stays the same before you submit a pull request.