Name | urllib3-sigv4 JSON |
Version |
0.4.1
JSON |
| download |
home_page | None |
Summary | Extension to urllib3 adding support for AWS Signature Version 4 |
upload_time | 2025-01-20 19:50:30 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
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/86/32/9dcff4b5518b9c0d65a7632a7a627b95bc08c39a3987d6ea9a8aef43b03b/urllib3_sigv4-0.4.1.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.4.1",
"project_urls": {
"Homepage": "https://github.com/tlinhart/urllib3-sigv4"
},
"split_keywords": [
"urllib",
" aws",
" sigv4"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "570b28939d0d26d211d4a44287b342dab5a4a198c1087793457e52ad1e3ea1b1",
"md5": "6ac4bed953e0ee18e011b57e25609035",
"sha256": "b15d1bbc754050564da2469e5141450850c4cbeb16d8c4f64f0b8f6da6a8cf9a"
},
"downloads": -1,
"filename": "urllib3_sigv4-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "6ac4bed953e0ee18e011b57e25609035",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5098,
"upload_time": "2025-01-20T19:50:28",
"upload_time_iso_8601": "2025-01-20T19:50:28.461613Z",
"url": "https://files.pythonhosted.org/packages/57/0b/28939d0d26d211d4a44287b342dab5a4a198c1087793457e52ad1e3ea1b1/urllib3_sigv4-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "86329dcff4b5518b9c0d65a7632a7a627b95bc08c39a3987d6ea9a8aef43b03b",
"md5": "ac4ed631a042c20c49db46b57f61a63b",
"sha256": "68f33c6e0782cbd99e1880d9624ae7a7a34ddf039bbd91cb318c663d2345bae0"
},
"downloads": -1,
"filename": "urllib3_sigv4-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "ac4ed631a042c20c49db46b57f61a63b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7327,
"upload_time": "2025-01-20T19:50:30",
"upload_time_iso_8601": "2025-01-20T19:50:30.165704Z",
"url": "https://files.pythonhosted.org/packages/86/32/9dcff4b5518b9c0d65a7632a7a627b95bc08c39a3987d6ea9a8aef43b03b/urllib3_sigv4-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-20 19:50:30",
"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"
}