Registry / http-networking / requests-file

requests-file

JSON →
library3.0.1pypypi✓ verified 27d ago

Requests-File is a transport adapter for the popular Python Requests library, enabling local filesystem access via `file://` URLs. It allows `requests.Session` objects to fetch local files as if they were remote resources. The current version is 3.0.1, and it follows the release cadence of its underlying dependency, `requests`, which is actively maintained and frequently updated.

pip install requests-file
INSTALL
IMPORT
SIG · REQUESTS-FILE
R
requests-file
http-networkingpythonv3.0.1
Install
2.6s avg
Import
365ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.376s · 21.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.6s · import 0.354s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FileAdapter
from requests_file import FileAdapter
Import the FileAdapter class to mount onto a requests Session.

This quickstart demonstrates how to initialize a `requests.Session`, mount the `FileAdapter`, and then make a GET request to a local file using a `file://` URL. It includes error handling and cleanup for the example file.

import requests from requests_file import FileAdapter import os # Create a dummy file for demonstration file_content = "Hello from local file!" file_path = "./test_file.txt" with open(file_path, "w") as f: f.write(file_content) s = requests.Session() s.mount('file://', FileAdapter()) # Construct a file:// URL (absolute path is recommended) absolute_file_path = os.path.abspath(file_path) file_url = f'file://{absolute_file_path}' try: response = s.get(file_url) response.raise_for_status() # Raise an exception for HTTP errors print(f"Status Code: {response.status_code}") print(f"Content: {response.text}") except requests.exceptions.RequestException as e: print(f"An error occurred: {e}") finally: # Clean up the dummy file os.remove(file_path)
Debug
Known issues
gotchaWhen accessing `response.text`, the encoding is inferred by `chardet` (if installed) or defaults to `ISO-8859-1`. This might not always match the actual file encoding, potentially leading to incorrect decoding. For binary files or specific encodings, it's safer to use `response.content` and decode manually.
fix
For explicit encoding, use `response.content.decode('your_encoding')`. For binary data, process `response.content` directly.
affects: All versions
gotcharequests-file maps common file system errors to HTTP status codes: `EACCES` (permission denied) is converted to a 403 Forbidden, `ENOENT` (file not found) to a 404 Not Found, and other `IOError` types to a 400 Bad Request. Be aware of these mappings when implementing error handling.
fix
Implement error handling expecting HTTP status codes 400, 403, and 404 for underlying filesystem issues.
affects: All versions
gotchaAs a `requests` transport adapter, `requests-file` relies on `requests`'s internal adapter API. Future major versions of the `requests` library might introduce breaking changes to this API (e.g., changes to `HTTPAdapter` or connection management), which could potentially affect `requests-file`'s functionality or require updates. For example, recent `requests` versions had changes related to `SSLContext` caching and the `_get_connection` method which could impact custom adapters.
fix
Always test `requests-file` compatibility when upgrading the `requests` library to a new major version. Refer to `requests` release notes for `HTTPAdapter`-related changes.
affects: Potentially future requests-file versions if underlying requests API changes
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'requests_file'
The 'requests-file' library has not been installed or is not accessible in the current Python environment.
fix
Install the library using pip: `pip install requests-file`
requests.exceptions.MissingSchema: Invalid URL 'my_local_file.txt': No schema supplied. Perhaps you meant http://my_local_file.txt?
The URL provided to requests lacks a scheme (like `http://`, `https://`, or `file://`), which is required for `requests-file` to handle local paths.
fix
Prefix the local file path with `file://`, e.g., `requests.get('file:///path/to/my_local_file.txt')`.
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
The specified local file path in the `file://` URL does not exist, or the path is incorrectly formatted (e.g., using backslashes on Windows within the URL).
fix
Verify the file path is correct and the file exists. For Windows paths, ensure forward slashes are used, e.g., `file:///C:/Users/User/document.txt`.
Upgrade
Version history
3.0.1latest on PyPI · released Oct 20, 2025
Audit
Dependencies
requestsrequiredCore HTTP library that requests-file extends.
Agent activity
13 hits · last 30 days
node
10
Resources
requests-file — pip install requests-file · libregistry