Skip to main content

Extension to urllib3 adding support for AWS Signature Version 4

Project description

urllib3 SigV4

Extension to urllib3 adding support for signing the requests with AWS Signature Version 4. It uses the Boto3 library for handling the AWS credentials and the actual signing process.

Installation

To install the package, use either pip:

pip install urllib3_sigv4

or uv:

uv add urllib3_sigv4

Usage

This library provides a drop-in replacement for two main components of urllib3, the PoolManager class and the top-level request method. It adds a new optional parameter which determines if and how the requests should be signed.

Creating a Signer

First, create an instance of the SigV4RequestSigner class which defines the parameters for request signing:

from urllib3_sigv4 import SigV4RequestSigner

signer = SigV4RequestSigner(
    "lambda",
    region="eu-central-1",
    access_key="AKIAIOSFODNN7EXAMPLE",
    secret_key="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
)

The first parameter is mandatory and identifies the AWS service we want to make requests to (AWS Lambda in this case). The region, access_key and secret_key parameters are optional and will be inferred from the environment if not passed (via the default Boto3 session, see here and here for more details).

Making Requests

To make signed requests to an AWS service, pass the signer instance via the signer parameter when creating the PoolManager:

from urllib3_sigv4 import PoolManager, SigV4RequestSigner

signer = SigV4RequestSigner("lambda")
http = PoolManager(signer=signer)

response = http.request(
    "POST",
    "https://my-lambda-url-id.lambda-url.eu-central-1.on.aws",
    json={"name": "John Doe", "age": 30}
)
print(response.json())

You can also provide the signer in individual request method calls to override the default behavior:

from urllib3_sigv4 import PoolManager, SigV4RequestSigner

signer = SigV4RequestSigner("lambda")
http = PoolManager()

# The same as when using urllib3's PoolManager.
response = http.request("GET", "https://httpbin.org/get")
print(response.json())

# This request will be signed.
response = http.request(
    "POST",
    "https://my-lambda-url-id.lambda-url.eu-central-1.on.aws",
    json={"name": "John Doe", "age": 30},
    signer=signer
)
print(response.json())

You can also use a convenience top-level request method which uses a module-global PoolManager instance:

from urllib3_sigv4 import SigV4RequestSigner, request

signer = SigV4RequestSigner("lambda")

response = request(
    "POST",
    "https://my-lambda-url-id.lambda-url.eu-central-1.on.aws",
    json={"name": "John Doe", "age": 30},
    signer=signer
)
print(response.json())

Reference

Project details


Download files

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

Source Distribution

urllib3_sigv4-1.0.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

urllib3_sigv4-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file urllib3_sigv4-1.0.0.tar.gz.

File metadata

  • Download URL: urllib3_sigv4-1.0.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for urllib3_sigv4-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6b0cf36e1fcdfe555bcca32b173a3a4a8e60ac4593f0afe1d86458b0e9c9a4b1
MD5 5f98de205ea1c5085247af34edec1223
BLAKE2b-256 a60bf48b26f5752b636b9cb2180c0641ce872aaa4445a45e9e3b81718113d8cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for urllib3_sigv4-1.0.0.tar.gz:

Publisher: ci.yml on tlinhart/urllib3-sigv4

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

File details

Details for the file urllib3_sigv4-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: urllib3_sigv4-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for urllib3_sigv4-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d04a76992b8d2df51cc1b931167c5b4966b0db9a88bd9c05e9a862b48da957b
MD5 eca497768314993a0f26df52017fa577
BLAKE2b-256 10e6efdefd4d221cc04aa0777151d2279f1aa83e37969a203fb99e9a7339ba3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for urllib3_sigv4-1.0.0-py3-none-any.whl:

Publisher: ci.yml on tlinhart/urllib3-sigv4

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page