{"id":694,"library":"requests-aws4auth","title":"AWS4 Authentication for Requests","description":"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.","status":"active","version":"1.3.1","language":"python","source_language":"en","source_url":"https://github.com/tedder/requests-aws4auth","tags":["aws","authentication","requests","aws4","sigv4"],"install":[{"cmd":"pip install requests-aws4auth","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core HTTP client library.","package":"requests","optional":false},{"reason":"Optional, for `RefreshableCredentials` to handle dynamically expiring STS tokens, typically via `boto3.session.Session().get_credentials()`.","package":"botocore","optional":true},{"reason":"Optional, if using `httpx` as an extra dependency, though the primary integration is with `requests`.","package":"httpx","optional":true}],"imports":[{"symbol":"AWS4Auth","correct":"from requests_aws4auth import AWS4Auth"}],"quickstart":{"code":"import os\nimport requests\nfrom requests_aws4auth import AWS4Auth\n\n# It's highly recommended to use environment variables for sensitive AWS credentials\naws_access_key_id = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY_ID')\naws_secret_access_key = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_ACCESS_KEY')\naws_session_token = os.environ.get('AWS_SESSION_TOKEN', '') # Optional for temporary STS credentials\n\n# Replace with your target AWS service region and canonical service name\naws_region = os.environ.get('AWS_REGION', 'us-east-1')\naws_service = os.environ.get('AWS_SERVICE', 's3') # e.g., 's3', 'es', 'execute-api'\n\nif aws_access_key_id == 'YOUR_ACCESS_KEY_ID' or aws_secret_access_key == 'YOUR_SECRET_ACCESS_KEY':\n    print(\"WARNING: AWS credentials are not set in environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). \"\n          \"Using placeholder values, which will likely fail authentication.\")\n\n# Construct the authentication object\nauth = AWS4Auth(\n    aws_access_key_id,\n    aws_secret_access_key,\n    aws_region,\n    aws_service,\n    session_token=aws_session_token if aws_session_token else None\n)\n\n# Example endpoint for S3 (adjust to your specific AWS endpoint)\nendpoint = f\"https://s3.{aws_region}.amazonaws.com/\"\nprint(f\"Attempting to connect to: {endpoint} with service: {aws_service}\")\n\ntry:\n    response = requests.get(endpoint, auth=auth)\n    response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)\n    print(f\"Successfully authenticated and received status code: {response.status_code}\")\n    # print(response.text) # Uncomment to see the response body\nexcept requests.exceptions.HTTPError as e:\n    print(f\"HTTP Error: {e.response.status_code} - {e.response.text}\")\nexcept requests.exceptions.RequestException as e:\n    print(f\"Request failed: {e}\")","lang":"python","description":"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`)."},"warnings":[{"fix":"Upgrade Python to >=3.7 and then upgrade requests-aws4auth to the latest version.","message":"Python 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.","severity":"breaking","affected_versions":"<1.3.0"},{"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`.","message":"The `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.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Upgrade to v1.2.2 or later.","message":"A 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.","severity":"gotcha","affected_versions":"1.2.0, 1.2.1"},{"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.","message":"Version 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.","severity":"gotcha","affected_versions":"All versions >=0.8"},{"fix":"Double-check your `pip install` command and `import` statements to confirm you are using the intended library.","message":"There 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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).","severity":"breaking","affected_versions":"All versions"},{"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.","message":"Authentication 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-05-12T17:54:41.058Z","next_check":"2026-06-26T00:00:00.000Z","problems":[],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":"1.3.2","install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.57,"mem_mb":9.8,"disk_size":"21.3M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.61,"mem_mb":9.7,"disk_size":"21.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.1,"import_time_s":0.43,"mem_mb":9.8,"disk_size":"22M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.44,"mem_mb":9.7,"disk_size":"22M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.72,"mem_mb":10.9,"disk_size":"23.3M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.81,"mem_mb":10.9,"disk_size":"23.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.1,"import_time_s":0.61,"mem_mb":10.9,"disk_size":"24M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.61,"mem_mb":10.9,"disk_size":"24M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.71,"mem_mb":11.4,"disk_size":"15.1M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.73,"mem_mb":11.3,"disk_size":"15.1M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":1.9,"import_time_s":0.65,"mem_mb":11.4,"disk_size":"16M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.67,"mem_mb":11.3,"disk_size":"16M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.64,"mem_mb":11.7,"disk_size":"14.9M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.71,"mem_mb":11.7,"disk_size":"14.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2,"import_time_s":0.63,"mem_mb":11.7,"disk_size":"15M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.68,"mem_mb":11.7,"disk_size":"15M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":null,"import_time_s":0.51,"mem_mb":9.5,"disk_size":"20.5M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.54,"mem_mb":9.6,"disk_size":"20.6M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":" $EXIT -eq 0 ","exit_code":0,"wheel_type":"wheel","failure_reason":null,"install_time_s":2.5,"import_time_s":0.52,"mem_mb":9.5,"disk_size":"21M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0.46,"mem_mb":9.6,"disk_size":"21M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}