Skip to main content

Requests IAMAuth

pypi python pytest coverage maintainability

Use AWS SigV4 authorization with requests.

Accessing an API secured with IAM authorization in AWS API Gateway can be tricky.

This tool uses the built-in authorization strategy in requests to help you access your secured endpoints.

Installation

pip install requests-iamauth

Usage

Signing Version 4

AWS sigv4 is the current standard for signing requests bound for AWS services.

Use requests-iamauth to as an authorizer for the requests Python library:

import requests
from iamauth import Sigv4Auth

sigv4 = Sigv4Auth(
  service_name="execute-api",  # default
)

session = requests.Session()
session.auth = sigv4
session.get('https://abcdef0123.execute-api.us-east-2.amazonaws.com/my/api')

Override the default boto3 session by passing a custom one into the constructor for Sigv4Auth:

import boto3

sigv4 = Sigv4Auth(
  boto3_session=boto3.Session(),
)

Signing Version 4a

AWS sigv4a is an extension to the sigv4 signing process that enables signing requests bound for more than one region.

Note — at the time of this writing, the only API Gateway API type that appears to support sigv4 are REST APIs.

Use requests-iamauth to as an authorizer for the requests Python library:

import requests
from iamauth import Sigv4aAuth

sigv4a = Sigv4aAuth(
  service="execute-api",  # default
  region="*",             # default
)

session = requests.Session()
session.auth = sigv4a
session.get('https://abcdef0123.execute-api.us-east-2.amazonaws.com/my/api')

Override the default AWS credentials provider by passing a custom one into the constructor for Sigv4aAuth:

from botocore.compat import awscrt

sigv4a = Sigv4aAuth(
  credentials_provider=awscrt.auth.AwsCredentialsProvider.new_default_chain(),
)

Metadata

Release files for iamauth 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iamauth 0.7.0
File Size Uploaded
iamauth-0.7.0.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iamauth 0.7.0
File Interpreter ABI Platform
iamauth-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / iamauth-0.7.0.tar.gz

Download URL iamauth-0.7.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5f3b5aa567011ca240ff8d849b233f0fb0651e3c8691dc9eb461f6be39355219
BLAKE2b-256 checksum
How to use checksums
f76f878f8f567ae4dbb84d4fb544d671d83439a97573499b8ac0222492183ed2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release files / iamauth-0.7.0-py3-none-any.whl

Download URL iamauth-0.7.0-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ece1b2356e369fd6a029edfa52981392090ae455126cc7a2fde1a724600d8d78
BLAKE2b-256 checksum
How to use checksums
15af50586736888b3045d55b4bb408524d2e56e6a9af15c50d602440e69f99da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.28.1

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release 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