# httpx-file
Transport adapter fort __[httpx](https://github.com/encode/httpx)__ to allow
`file://` URI fetching in the local filesystem.
## Installation
<a href="https://pypi.org/project/httpx-file/"><pre>
pip install httpx-file
</pre></a>
## 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.
```python
from httpx_file import Client
client = Client()
client.get('file:///etc/fstab)
```
Or you can also mount `FileTransport` in a `httpx.Client` instance.
```python
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'.
```python
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.
```python
from httpx_file import FileTransport
from httpx import AsyncClient
client = AsyncClient(mounts={'file://': FileTransport()})
client.get('file:///etc/fstab)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/nuno-andre/httpx-file#readme",
"name": "httpx-file",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6.1",
"maintainer_email": "",
"keywords": "",
"author": "Nuno Andr\u00e9",
"author_email": "mail@nunoand.re",
"download_url": "https://files.pythonhosted.org/packages/b4/f7/737dbfaa3b3288ce69f75fad9a4cd22cae60d71763618ddd849018895172/httpx-file-0.2.0.tar.gz",
"platform": "any",
"description": "# httpx-file\r\n\r\nTransport adapter fort __[httpx](https://github.com/encode/httpx)__ to allow\r\n`file://` URI fetching in the local filesystem.\r\n\r\n\r\n## Installation\r\n\r\n<a href=\"https://pypi.org/project/httpx-file/\"><pre>\r\npip install httpx-file\r\n</pre></a>\r\n\r\n\r\n## Usage \r\n\r\n### Synchronous\r\n\r\n_httpx-file_ subclasses `httpx.Client`, so you can just replace `httpx.Client`\r\nwith `httpx_file.Client` to get the same behavior with added `file://` protocol\r\nsupport.\r\n\r\n```python\r\nfrom httpx_file import Client\r\n\r\nclient = Client()\r\nclient.get('file:///etc/fstab)\r\n```\r\n\r\nOr you can also mount `FileTransport` in a `httpx.Client` instance.\r\n\r\n```python\r\nfrom httpx_file import FileTransport\r\nfrom httpx import Client\r\n\r\nclient = Client(mounts={'file://': FileTransport()})\r\nclient.get('file:///etc/fstab)\r\n```\r\n\r\n### Asynchronous\r\n\r\nIt is also possible to use _httpx-file_ possibilities asynchronous way. \r\nTo do this, you can just replace 'httpx.AsyncClient' with 'httpx_file.AsyncClient'.\r\n\r\n```python\r\nfrom httpx_file import AsyncClient\r\n\r\n# Taken from tests/test_transport.py\r\n\r\nfrom pathlib import Path\r\n\r\nTHIS = Path(__file__)\r\n\r\nasync def test_async_client():\r\n async_client = AsyncClient()\r\n async_response = await async_client.get(THIS.as_uri())\r\n\r\n assert async_response.content == THIS.read_bytes()\r\n```\r\n\r\nOr you can also mount `FileTransport` in a `httpx.AsyncClient` instance.\r\n\r\n```python\r\nfrom httpx_file import FileTransport\r\nfrom httpx import AsyncClient\r\n\r\nclient = AsyncClient(mounts={'file://': FileTransport()})\r\nclient.get('file:///etc/fstab)\r\n```\r\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "File transport adapter for httpx.",
"version": "0.2.0",
"project_urls": {
"Bug Tracker": "https://github.com/nuno-andre/httpx-file/issues",
"Homepage": "https://github.com/nuno-andre/httpx-file#readme",
"Source": "https://github.com/nuno-andre/httpx-file"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f49c4f3fba4c1b5a8919c3f6d407a41df43980c6a03a631d49f458b9546da128",
"md5": "b8e6410b268ec1012490007c10fbe2f7",
"sha256": "9a425b351bf65aa394c02096204dc3fa8b647573a289079f927d3e3abfa3c7c8"
},
"downloads": -1,
"filename": "httpx_file-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b8e6410b268ec1012490007c10fbe2f7",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.1",
"size": 4471,
"upload_time": "2023-07-23T17:14:54",
"upload_time_iso_8601": "2023-07-23T17:14:54.535159Z",
"url": "https://files.pythonhosted.org/packages/f4/9c/4f3fba4c1b5a8919c3f6d407a41df43980c6a03a631d49f458b9546da128/httpx_file-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b4f7737dbfaa3b3288ce69f75fad9a4cd22cae60d71763618ddd849018895172",
"md5": "8df2c67b3983c35d6360048969c2f78d",
"sha256": "a00f1dd02c9ffb5e7e072205c30f7ae0d867c397318b045a40b3268f2cdfa932"
},
"downloads": -1,
"filename": "httpx-file-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "8df2c67b3983c35d6360048969c2f78d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.1",
"size": 4250,
"upload_time": "2023-07-23T17:14:56",
"upload_time_iso_8601": "2023-07-23T17:14:56.080433Z",
"url": "https://files.pythonhosted.org/packages/b4/f7/737dbfaa3b3288ce69f75fad9a4cd22cae60d71763618ddd849018895172/httpx-file-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-23 17:14:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nuno-andre",
"github_project": "httpx-file#readme",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "httpx-file"
}