Registry / aws / requests-aws4auth

requests-aws4auth

JSON →
library1.3.2pypypi✓ verified 27d ago

requests-aws4auth is a Python library providing AWS Signature Version 4 authentication for the popular Requests HTTP library. It enables secure interaction with AWS APIs by signing HTTP requests according to the SigV4 protocol. The library is actively maintained with a history of regular releases and improvements.

pip install requests-aws4auth
INSTALL
IMPORT
SIG · REQUESTS-AWS4AUTH
R
requests-aws4auth
awspythonv1.3.2
Install
2.2s avg
Import
366ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.384s · 21.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.348s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AWS4Auth
from requests_aws4auth import AWS4Auth

This example demonstrates how to set up AWS4Auth using access keys and a service endpoint, then make a GET request using the `requests` library. For production, always use environment variables or a secure credential provider (like `boto3`'s session credentials with `RefreshableCredentials`).

import os import requests from requests_aws4auth import AWS4Auth # It's highly recommended to use environment variables for sensitive AWS credentials aws_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_ID') aws_secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_ACCESS_KEY') aws_session_token = os.environ.get('AWS_SESSION_TOKEN', '') # Optional for temporary STS credentials # Replace with your target AWS service region and canonical service name aws_region = os.environ.get('AWS_REGION', 'us-east-1') aws_service = os.environ.get('AWS_SERVICE', 's3') # e.g., 's3', 'es', 'execute-api' if aws_access_key_id == 'YOUR_ACCESS_KEY_ID' or aws_secret_access_key == 'YOUR_SECRET_ACCESS_KEY': print("WARNING: AWS credentials are not set in environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). " "Using placeholder values, which will likely fail authentication.") # Construct the authentication object auth = AWS4Auth( aws_access_key_id, aws_secret_access_key, aws_region, aws_service, session_token=aws_session_token if aws_session_token else None ) # Example endpoint for S3 (adjust to your specific AWS endpoint) endpoint = f"https://s3.{aws_region}.amazonaws.com/" print(f"Attempting to connect to: {endpoint} with service: {aws_service}") try: response = requests.get(endpoint, auth=auth) response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx) print(f"Successfully authenticated and received status code: {response.status_code}") # print(response.text) # Uncomment to see the response body except requests.exceptions.HTTPError as e: print(f"HTTP Error: {e.response.status_code} - {e.response.text}") except requests.exceptions.RequestException as e: print(f"Request failed: {e}")
Debug
Known issues
breakingPython 2.7 support was officially dropped in v1.1.0, and support for Python versions below 3.7 was explicitly removed in v1.3.0. Users on older Python versions will need to upgrade.
fix
Upgrade Python to >=3.7 and then upgrade requests-aws4auth to the latest version.
affects: <1.3.0
breakingThe `six` compatibility library was removed in v1.3.0, signifying a full transition to Python 3 syntax. Code relying on `six` within or alongside `requests-aws4auth` may break.
fix
Update your code to use native Python 3 constructs or ensure `six` is not inadvertently relied upon by other dependencies in a way that conflicts with `requests-aws4auth`.
affects: >=1.3.0
gotchaA regression error was present in versions 1.2.0 and 1.2.1 related to header port numbers, requiring a revert in v1.2.2. These versions should be avoided if port handling is critical.
fix
Upgrade to v1.2.2 or later.
affects: 1.2.0, 1.2.1
gotchaVersion 0.8 introduced automatic request date checking and key regeneration. This significantly changed behavior regarding multithreading and secret key storage, as an `AWS4Auth` instance might modify its internal signing key during a request if date headers mismatch.
fix
Review the 'Date handling', 'Automatic key regeneration', 'Secret key storage', and 'Multithreading' sections in the library's documentation to understand the implications for long-running or multi-threaded applications.
affects: All versions >=0.8
gotchaThere are two popular, similarly named libraries: `requests-aws4auth` (this library, `tedder/requests-aws4auth`) and `aws-requests-auth` (`DavidMuller/aws-requests-auth`). Ensure you are importing from `requests_aws4auth` if you intend to use this specific package.
fix
Double-check your `pip install` command and `import` statements to confirm you are using the intended library.
affects: All versions
breakingThe library requires valid AWS credentials (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) to be provided, typically via environment variables or directly in the `AWS4Auth` constructor, to successfully authenticate requests. Without them, requests will fail with authentication errors (e.g., 403 InvalidAccessKeyId).
fix
Ensure AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are set with valid AWS credentials before running the application, or pass credentials directly to the `AWS4Auth` constructor.
affects: All versions
gotchaAuthentication failures (e.g., HTTP 403 InvalidAccessKeyId) commonly occur if AWS credentials (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) are not correctly set in environment variables or passed to the `AWS4Auth` constructor, or if the provided credentials lack the necessary permissions for the requested action/resource.
fix
Ensure `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables are correctly set, or explicitly pass valid credentials to the `AWS4Auth` constructor. Verify that the IAM user/role associated with the credentials has sufficient permissions for the AWS service and resource being accessed.
affects: All versions
Upgrade
Version history
1.3.2latest on PyPI · released May 1, 2026
Audit
Dependencies
requestsrequiredCore HTTP client library.
botocoreoptionalOptional, for `RefreshableCredentials` to handle dynamically expiring STS tokens, typically via `boto3.session.Session().get_credentials()`.
httpxoptionalOptional, if using `httpx` as an extra dependency, though the primary integration is with `requests`.
Agent activity
15 hits · last 30 days
node
14
Resources
requests-aws4auth — pip install requests-aws4auth · libregistry