Skip to main content

session-adapters

PyPI - Version PyPI - Python Version

Requests transport adapters for bearer-authenticated http(s)://, file://, s3://, and oci:// URLs.

Read the documentation

Why This Project

session-adapters lets you use a standard requests.Session with authenticated HTTP requests and non-HTTP backends:

  • http:// and https:// with bearer token authentication
  • file:// for local filesystem artifacts
  • s3:// for AWS S3 objects and prefix listings
  • oci:// for OCI registry artifacts (via ORAS client)

This keeps one client interface while changing only the URL scheme.

Installation

pip install session-adapters

Quick Start

import 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)

Adapter Notes

Bearer Auth HTTP Adapter

  • Adds an Authorization: Bearer <token> header to every request it handles
  • Replaces an existing Authorization header
  • Can be mounted on a specific URL prefix to limit where the token is sent
  • Mount separate adapters for http:// and https:// if both schemes are needed

File Adapter

  • Supports GET, HEAD, PUT, DELETE
  • Uses local filesystem paths from file:// URLs

S3 Adapter

  • Supports GET, HEAD, PUT, DELETE
  • Supports query options like:
    • range=bytes=0-99
    • versionId=...
    • delimiter=/
    • maxKeys=...

OCI Adapter

  • Supports GET, HEAD, PUT, DELETE
  • Parses refs as tags (:tag) or digests (@sha256:...)
  • Uses oras.client.OrasClient under the hood

Development

Run tests:

hatch run test:test-q

Run lint checks:

hatch run dev:check
ruff format --check .

Preview the documentation:

hatch run docs:serve

Build the documentation with strict validation:

hatch run docs:build

License

session-adapters is distributed under the terms of the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

session_adapters-0.5.0.tar.gz (107.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

session_adapters-0.5.0-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file session_adapters-0.5.0.tar.gz.

File metadata

  • Download URL: session_adapters-0.5.0.tar.gz
  • Upload date:
  • Size: 107.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for session_adapters-0.5.0.tar.gz
Algorithm Hash digest
SHA256 af32c40445d757c8d5ae334ff6151b709ac1d2a9cb45e730f91bc26c58c91671
MD5 8a538b73321efb105b071861155e2b1f
BLAKE2b-256 10e42d83bc83197a62d989a707a0c96f0b38baff84aed02da5d3fe75cc8625ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for session_adapters-0.5.0.tar.gz:

Publisher: package.yaml on Terradue/session-adapters

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file session_adapters-0.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for session_adapters-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dfb7e09c266fae7774eb10c8e16f5a4b766c0ac3c913294b1689dbb2937acf74
MD5 9696fd6811c3241020cb781db34c491c
BLAKE2b-256 1e8cd3896c1d6bc2a5835872e558f5efac0228f051f8a7c31926c5966abf956d

See more details on using hashes here.

Provenance

The following attestation bundles were made for session_adapters-0.5.0-py3-none-any.whl:

Publisher: package.yaml on Terradue/session-adapters

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page