File transport adapter for httpx.
Project description
httpx-file
Transport adapter fort httpx to allow
file://
URI fetching in the local filesystem.
Installation
pip install httpx-file
Usage
Synchronous
httpx-file subclasses httpx.Client
, so you can just replace httpx.Client
with httpx_file.Client
to get the same behavior with added file://
protocol
support.
from httpx_file import Client
client = Client()
client.get('file:///etc/fstab)
Or you can also mount FileTransport
in a httpx.Client
instance.
from httpx_file import FileTransport
from httpx import Client
client = Client(mounts={'file://': FileTransport()})
client.get('file:///etc/fstab)
Asynchronous
It is also possible to use httpx-file possibilities asynchronous way. To do this, you can just replace 'httpx.AsyncClient' with 'httpx_file.AsyncClient'.
from httpx_file import AsyncClient
# Taken from tests/test_transport.py
from pathlib import Path
THIS = Path(__file__)
async def test_async_client():
async_client = AsyncClient()
async_response = await async_client.get(THIS.as_uri())
assert async_response.content == THIS.read_bytes()
Or you can also mount FileTransport
in a httpx.AsyncClient
instance.
from httpx_file import FileTransport
from httpx import AsyncClient
client = AsyncClient(mounts={'file://': FileTransport()})
client.get('file:///etc/fstab)
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
httpx-file-0.2.0.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for httpx_file-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a425b351bf65aa394c02096204dc3fa8b647573a289079f927d3e3abfa3c7c8 |
|
MD5 | b8e6410b268ec1012490007c10fbe2f7 |
|
BLAKE2b-256 | f49c4f3fba4c1b5a8919c3f6d407a41df43980c6a03a631d49f458b9546da128 |