Requests transport adapters for bearer-authenticated http(s)://, file://,
s3://, and oci:// URLs.
session-adapters lets you use a standard requests.Session with authenticated
HTTP requests and non-HTTP backends:
http://andhttps://with bearer token authenticationfile://for local filesystem artifactss3://for AWS S3 objects and prefix listingsoci://for OCI registry artifacts (via ORAS client)
This keeps one client interface while changing only the URL scheme.
pip install session-adaptersimport requests
from session_adapters.bearer_auth_http_adapter import BearerAuthHTTPAdapter
from session_adapters.file_adapter import FileAdapter
from session_adapters.oci_adapter import OCIAdapter
from session_adapters.s3_adapter import S3Adapter
session = requests.Session()
session.mount("https://", BearerAuthHTTPAdapter("my-token"))
session.mount("file://", FileAdapter())
session.mount("s3://", S3Adapter())
session.mount("oci://", OCIAdapter())
# Bearer-authenticated HTTPS request
resp = session.get("https://api.example.com/resource")
print(resp.status_code)
# Local file
resp = session.get("file:///tmp/example.txt")
print(resp.status_code)
# S3 object
resp = session.get("s3://my-bucket/path/to/object.json")
print(resp.status_code)
# OCI artifact
resp = session.get("oci://registry.example.com/my-repo:latest")
print(resp.status_code)- Adds an
Authorization: Bearer <token>header to every request it handles - Replaces an existing
Authorizationheader - Can be mounted on a specific URL prefix to limit where the token is sent
- Mount separate adapters for
http://andhttps://if both schemes are needed
- Supports
GET,HEAD,PUT,DELETE - Uses local filesystem paths from
file://URLs
- Supports
GET,HEAD,PUT,DELETE - Supports query options like:
range=bytes=0-99versionId=...delimiter=/maxKeys=...
- Supports
GET,HEAD,PUT,DELETE - Parses refs as tags (
:tag) or digests (@sha256:...) - Uses
oras.client.OrasClientunder the hood
Run tests:
hatch run test:test-qRun lint checks:
hatch run dev:check
ruff format --check .Preview the documentation:
hatch run docs:serveBuild the documentation with strict validation:
hatch run docs:buildsession-adapters is distributed under the terms of the MIT license.