File adapter for the Requests library.
Project description
title: README
Synopsis
A file adapter for the Requests library. This adapter is similar to and inspired by Requests-File but with the following changes:
- HEAD requests return a response without content instead of opening the file.
- The following HTTP response headers are set for regular files:
- Content-Length (always)
- Last-Modified (always)
- Content-Type (if successfully detected by the mimetypes package)
- Content-Encoding (if successfully detected by the mimetypes package)
- The request supports URI hosts that resolve to the localhost or any local IP address.
- A convenience function is provided to get a requests.Session object with the provided file adapter already mounted.
Links
GitLab
Other Repositories
Usage
Using the get_session
function:
import pathlib
from requests_file_manager import get_session
path = pathlib.Path("example.txt").resolve()
uri = path.as_uri
session = get_session()
resp = session.get(uri)
for header, value in resp.headers.items():
print(header, value)
print(header.content)
Alternatively, create the session without using the get_session
function:
import requests
from requests_file_adapter import FileAdapter
session = requests.Session()
session.mount("file://", FileAdapter())
# ...
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
Built Distribution
Close
Hashes for requests_file_adapter-2024.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9f6abe30d3ac56de21b46868494c92fc7f6c442b5ff51024fd3c570cb7aa7e2 |
|
MD5 | 3d49fff5098446cd90e850eaebfb4b4b |
|
BLAKE2b-256 | 8d3b96175a8f26e771de28d5ee003eb7031de4a2e0c4345bece1d78e14a80b62 |
Close
Hashes for requests_file_adapter-2024.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca208129ca030dc7255be728c9c5f4ae2f5fe2a59a8e717aa9275b1a384d7ecc |
|
MD5 | aba1100414b2c05b4359251551725c9f |
|
BLAKE2b-256 | fa9d3727d705822e378e7cce1c475a59bd508aeb422bb13253568d46cfd640e4 |