https://github.com/barneygale/httpio
Python library for reading HTTP resources as random-access file-like objects using the `Range` header
https://github.com/barneygale/httpio
client http python
Last synced: 7 months ago
JSON representation
Python library for reading HTTP resources as random-access file-like objects using the `Range` header
- Host: GitHub
- URL: https://github.com/barneygale/httpio
- Owner: barneygale
- License: other
- Created: 2016-06-09T23:09:51.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-29T10:06:40.000Z (over 3 years ago)
- Last Synced: 2025-05-31T18:49:05.309Z (8 months ago)
- Topics: client, http, python
- Language: Python
- Homepage:
- Size: 54.7 KB
- Stars: 32
- Watchers: 5
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: COPYING.txt
Awesome Lists containing this project
README
httpio
======
HTTP resources as random-access file-like objects
httpio is a small Python library that allows you to access files
served over HTTP as file-like_ objects (which is to say that they
support the interface of the standard library's BufferedIOBase_
class). It differs from libraries like ``urllib`` and ``requests`` in
that it supports ``seek()`` (which moves an internal pointer), and
that ``read()`` makes a request with the ``Range`` header set. It also
supports caching of contents using a configurable block size, and will
reuse TCP connections where possible.
Installation
------------
Use ``pip`` to install httpio:
.. code-block:: console
$ pip install httpio
Usage
-----
.. code-block:: python
import zipfile
import httpio
url = "http://some/large/file.zip"
with httpio.open(url) as fp:
zf = zipfile.ZipFile(fp)
print(zf.namelist())
.. _file-like: https://docs.python.org/3/glossary.html#term-file-object
.. _BufferedIOBase: https://docs.python.org/3/library/io.html#io.BufferedIOBase
Unit Tests
----------
Unit tests are provided for the standard behaviours implemented by
the library. They can be run with
.. code-block:: console
$ python -m unittest discover -s tests
or a ``tox.ini`` file is provided which allows the tests to be run in
virtual environments using the ``tox`` tool:
.. code-block:: console
$ tox