Name | urllib3-sigv4 JSON |
Version |
0.4.0
JSON |
| download |
home_page | None |
Summary | Extension to urllib3 adding support for AWS Signature Version 4 |
upload_time | 2024-09-05 12:09:27 |
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/38/ea/6aeb50bc75145c0cf776950292d947ce05f94f2f33da75f7b8d724f85d06/urllib3_sigv4-0.4.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.4.0",
"project_urls": {
"Homepage": "https://github.com/tlinhart/urllib3-sigv4"
},
"split_keywords": [
"urllib",
" aws",
" sigv4"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4f6f4450f5d54af065496d6c418f5b3aefbe95b6f9acf60c286d579714bd23de",
"md5": "1875b8c477e1ed167feef32bf51dd2d0",
"sha256": "4509618c667bcdaaf959582bb05513d915896b84904d30c409f21647e2ea96b6"
},
"downloads": -1,
"filename": "urllib3_sigv4-0.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1875b8c477e1ed167feef32bf51dd2d0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5100,
"upload_time": "2024-09-05T12:09:25",
"upload_time_iso_8601": "2024-09-05T12:09:25.785344Z",
"url": "https://files.pythonhosted.org/packages/4f/6f/4450f5d54af065496d6c418f5b3aefbe95b6f9acf60c286d579714bd23de/urllib3_sigv4-0.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "38ea6aeb50bc75145c0cf776950292d947ce05f94f2f33da75f7b8d724f85d06",
"md5": "6fe37340c25918e7f7b596da9ea901c0",
"sha256": "05daee4e78673db85d0c4b552a675ddfe6667e40a3c26f45487644065e4ccc6e"
},
"downloads": -1,
"filename": "urllib3_sigv4-0.4.0.tar.gz",
"has_sig": false,
"md5_digest": "6fe37340c25918e7f7b596da9ea901c0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7323,
"upload_time": "2024-09-05T12:09:27",
"upload_time_iso_8601": "2024-09-05T12:09:27.059008Z",
"url": "https://files.pythonhosted.org/packages/38/ea/6aeb50bc75145c0cf776950292d947ce05f94f2f33da75f7b8d724f85d06/urllib3_sigv4-0.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-05 12:09:27",
"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"
}