Skip to main content

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


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)

Uploaded Source

Built Distribution

httpx_file-0.2.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page