{"id":573,"library":"requests-file","title":"Requests-File","description":"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.","status":"active","version":"3.0.1","language":"python","source_language":"en","source_url":"https://github.com/dashea/requests-file","tags":["requests","http","file-access","transport-adapter","filesystem"],"install":[{"cmd":"pip install requests-file","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core HTTP library that requests-file extends.","package":"requests","optional":false}],"imports":[{"note":"Import the FileAdapter class to mount onto a requests Session.","symbol":"FileAdapter","correct":"from requests_file import FileAdapter"}],"quickstart":{"code":"import requests\nfrom requests_file import FileAdapter\nimport os\n\n# Create a dummy file for demonstration\nfile_content = \"Hello from local file!\"\nfile_path = \"./test_file.txt\"\nwith open(file_path, \"w\") as f:\n    f.write(file_content)\n\ns = requests.Session()\ns.mount('file://', FileAdapter())\n\n# Construct a file:// URL (absolute path is recommended)\nabsolute_file_path = os.path.abspath(file_path)\nfile_url = f'file://{absolute_file_path}'\n\ntry:\n    response = s.get(file_url)\n    response.raise_for_status() # Raise an exception for HTTP errors\n    print(f\"Status Code: {response.status_code}\")\n    print(f\"Content: {response.text}\")\nexcept requests.exceptions.RequestException as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the dummy file\n    os.remove(file_path)\n","lang":"python","description":"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."},"warnings":[{"fix":"For explicit encoding, use `response.content.decode('your_encoding')`. For binary data, process `response.content` directly.","message":"When 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement error handling expecting HTTP status codes 400, 403, and 404 for underlying filesystem issues.","message":"requests-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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"As 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.","severity":"gotcha","affected_versions":"Potentially future requests-file versions if underlying requests API changes"}],"env_vars":null,"last_verified":"2026-05-12T16:13:50.450Z","next_check":"2026-06-26T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install requests-file`","cause":"The 'requests-file' library has not been installed or is not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'requests_file'"},{"fix":"Prefix the local file path with `file://`, e.g., `requests.get('file:///path/to/my_local_file.txt')`.","cause":"The URL provided to requests lacks a scheme (like `http://`, `https://`, or `file://`), which is required for `requests-file` to handle local paths.","error":"requests.exceptions.MissingSchema: Invalid URL 'my_local_file.txt': No schema supplied. Perhaps you meant http://my_local_file.txt?"},{"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`.","cause":"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).","error":"requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"3.0.1","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.58,"mem_mb":9.7,"disk_size":"21.2M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.57,"mem_mb":9.6,"disk_size":"21.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.3,"import_time_s":0.4,"mem_mb":9.7,"disk_size":"22M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.41,"mem_mb":9.6,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.76,"mem_mb":10.8,"disk_size":"23.2M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.79,"mem_mb":10.8,"disk_size":"23.2M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.3,"import_time_s":0.62,"mem_mb":10.8,"disk_size":"24M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.59,"mem_mb":10.8,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":11.3,"disk_size":"15.0M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.7,"mem_mb":11.2,"disk_size":"15.0M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2,"import_time_s":0.68,"mem_mb":11.3,"disk_size":"16M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.65,"mem_mb":11.2,"disk_size":"15M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":11.6,"disk_size":"14.8M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":11.6,"disk_size":"14.7M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.9,"import_time_s":0.62,"mem_mb":11.6,"disk_size":"15M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.66,"mem_mb":11.6,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.51,"mem_mb":9.4,"disk_size":"20.4M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.53,"mem_mb":9.5,"disk_size":"20.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.6,"import_time_s":0.44,"mem_mb":9.4,"disk_size":"21M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.43,"mem_mb":9.5,"disk_size":"21M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}