urllib3-sigv4


Nameurllib3-sigv4 JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryExtension to urllib3 adding support for AWS Signature Version 4
upload_time2024-06-14 11:33:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords urllib aws sigv4
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # urllib3 SigV4

Extension to [urllib3](https://github.com/urllib3/urllib3) adding support for
signing the requests with AWS Signature Version 4. It uses the
[Boto3](https://github.com/boto/boto3) library for handling the AWS credentials
and the actual signing process.

## Installation

Use `pip` to install the package:

```bash
pip install urllib3_sigv4
```

## Usage

This library provides a drop-in replacement for two main components of urllib3,
the [`PoolManager`](https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html)
class and the top-level [`request`](https://urllib3.readthedocs.io/en/stable/reference/urllib3.request.html)
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:

```python
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](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/session.html)
and [here](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html)
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`:

```python
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:

```python
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:

```python
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

- https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html
- https://github.com/aws-samples/sigv4-signing-examples
- https://github.com/awslabs/aws-sdk-python-signers

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "urllib3-sigv4",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "urllib, aws, sigv4",
    "author": null,
    "author_email": "Tom\u00e1\u0161 Linhart <pasmen@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f6/c4/f6ec7a7dbd783de73fb8106cee5d04953de24a41eb9db4a7af6dc617fcd1/urllib3_sigv4-0.2.0.tar.gz",
    "platform": null,
    "description": "# urllib3 SigV4\n\nExtension to [urllib3](https://github.com/urllib3/urllib3) adding support for\nsigning the requests with AWS Signature Version 4. It uses the\n[Boto3](https://github.com/boto/boto3) library for handling the AWS credentials\nand the actual signing process.\n\n## Installation\n\nUse `pip` to install the package:\n\n```bash\npip install urllib3_sigv4\n```\n\n## Usage\n\nThis library provides a drop-in replacement for two main components of urllib3,\nthe [`PoolManager`](https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html)\nclass and the top-level [`request`](https://urllib3.readthedocs.io/en/stable/reference/urllib3.request.html)\nmethod. It adds a new optional parameter which determines if and how the\nrequests should be signed.\n\n### Creating a Signer\n\nFirst, create an instance of the `SigV4RequestSigner` class which defines the\nparameters for request signing:\n\n```python\nfrom urllib3_sigv4 import SigV4RequestSigner\n\nsigner = SigV4RequestSigner(\n    \"lambda\",\n    region=\"eu-central-1\",\n    access_key=\"AKIAIOSFODNN7EXAMPLE\",\n    secret_key=\"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\"\n)\n```\n\nThe first parameter is mandatory and identifies the AWS service we want to make\nrequests to (AWS Lambda in this case). The `region`, `access_key` and\n`secret_key` parameters are optional and will be inferred from the environment\nif not passed (via the default Boto3 session, see\n[here](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/session.html)\nand [here](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html)\nfor more details).\n\n### Making Requests\n\nTo make signed requests to an AWS service, pass the signer instance via the\n`signer` parameter when creating the `PoolManager`:\n\n```python\nfrom urllib3_sigv4 import PoolManager, SigV4RequestSigner\n\nsigner = SigV4RequestSigner(\"lambda\")\nhttp = PoolManager(signer=signer)\n\nresponse = http.request(\n    \"POST\",\n    \"https://my-lambda-url-id.lambda-url.eu-central-1.on.aws\",\n    json={\"name\": \"John Doe\", \"age\": 30}\n)\nprint(response.json())\n```\n\nYou can also provide the signer in individual `request` method calls to\noverride the default behavior:\n\n```python\nfrom urllib3_sigv4 import PoolManager, SigV4RequestSigner\n\nsigner = SigV4RequestSigner(\"lambda\")\nhttp = PoolManager()\n\n# The same as when using urllib3's PoolManager.\nresponse = http.request(\"GET\", \"https://httpbin.org/get\")\nprint(response.json())\n\n# This request will be signed.\nresponse = http.request(\n    \"POST\",\n    \"https://my-lambda-url-id.lambda-url.eu-central-1.on.aws\",\n    json={\"name\": \"John Doe\", \"age\": 30},\n    signer=signer\n)\nprint(response.json())\n```\n\nYou can also use a convenience top-level `request` method which uses a\nmodule-global `PoolManager` instance:\n\n```python\nfrom urllib3_sigv4 import SigV4RequestSigner, request\n\nsigner = SigV4RequestSigner(\"lambda\")\n\nresponse = request(\n    \"POST\",\n    \"https://my-lambda-url-id.lambda-url.eu-central-1.on.aws\",\n    json={\"name\": \"John Doe\", \"age\": 30},\n    signer=signer\n)\nprint(response.json())\n```\n\n## Reference\n\n- https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html\n- https://github.com/aws-samples/sigv4-signing-examples\n- https://github.com/awslabs/aws-sdk-python-signers\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Extension to urllib3 adding support for AWS Signature Version 4",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/tlinhart/urllib3-sigv4"
    },
    "split_keywords": [
        "urllib",
        " aws",
        " sigv4"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "473d0dfc585b29eec5541dacfe25427125895279d510ec6fc51347c1f01dce51",
                "md5": "b9386abae5c2d89991f7a22c069727e4",
                "sha256": "3d43dc46be9ee0b1f75befbbc4f6449f9cb3756a1e064c23c886d0c8ffc8bf8d"
            },
            "downloads": -1,
            "filename": "urllib3_sigv4-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9386abae5c2d89991f7a22c069727e4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 4903,
            "upload_time": "2024-06-14T11:33:22",
            "upload_time_iso_8601": "2024-06-14T11:33:22.399114Z",
            "url": "https://files.pythonhosted.org/packages/47/3d/0dfc585b29eec5541dacfe25427125895279d510ec6fc51347c1f01dce51/urllib3_sigv4-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f6c4f6ec7a7dbd783de73fb8106cee5d04953de24a41eb9db4a7af6dc617fcd1",
                "md5": "dc221d6512f89cc4ebb91cf60ba3ef8b",
                "sha256": "f620f14cfb7ac43048b5697c4aa6e91b19ffa0ec87e15f2aee3e2d4d8502cb48"
            },
            "downloads": -1,
            "filename": "urllib3_sigv4-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "dc221d6512f89cc4ebb91cf60ba3ef8b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 6359,
            "upload_time": "2024-06-14T11:33:23",
            "upload_time_iso_8601": "2024-06-14T11:33:23.704128Z",
            "url": "https://files.pythonhosted.org/packages/f6/c4/f6ec7a7dbd783de73fb8106cee5d04953de24a41eb9db4a7af6dc617fcd1/urllib3_sigv4-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-14 11:33:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tlinhart",
    "github_project": "urllib3-sigv4",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "urllib3-sigv4"
}
        
Elapsed time: 0.37411s