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
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdd8bc24bf6fc156e0928d6c75604ce139932d82ca04241f48defcd50a78ea7c |
|
MD5 | d8e3197d5f7069cb925080439026d9bf |
|
BLAKE2b-256 | b126b84771422478edb591857590922e2f9dcf1a6ae9d70e764a9c9c5a627298 |
Close
Hashes for requests_file_adapter-2024.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78cb5ac2f7e5acd23b1ffc71e48aa306d0942accddfbe0378b2b6a51043b1bb5 |
|
MD5 | 749f2d4fa3336b3b6d6f8dc3862e6300 |
|
BLAKE2b-256 | e9f051ee203cdc98fa7dc96e0958697ab02c87be90add4437acc6cee77801282 |