boto3-refresh-session


Nameboto3-refresh-session JSON
Version 1.0.14 PyPI version JSON
download
home_pagehttps://github.com/michaelthomasletts/boto3-refresh-session
SummaryA simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically.
upload_time2025-03-06 18:12:10
maintainerMichael Letts
docs_urlNone
authorMike Letts
requires_python>=3.10
licenseMIT
keywords boto3 botocore aws
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # boto3-refresh-session
[![PyPI Download](https://img.shields.io/pypi/v/boto3-refresh-session?logo=pypis.svg)](https://pypi.org/project/boto3-refresh-session/)
[![Workflow](https://img.shields.io/github/actions/workflow/status/michaelthomasletts/boto3-refresh-session/push.yml?logo=github)](https://github.com/michaelthomasletts/boto3-refresh-session/actions/workflows/push.yml)
![Python Version](https://img.shields.io/pypi/pyversions/boto3-refresh-session?style=pypi)
![GitHub last commit](https://img.shields.io/github/last-commit/michaelthomasletts/boto3-refresh-session?logo=github)
![PyPI - Downloads](https://img.shields.io/pypi/dm/boto3-refresh-session?logo=pypi)

![BRS Image](https://raw.githubusercontent.com/michaelthomasletts/boto3-refresh-session/refs/heads/main/doc/brs.png)

A simple Python package for refreshing the temporary security credentials in a `boto3.session.Session` object automatically.

- [Official Documentation](https://michaelthomasletts.github.io/boto3-refresh-session/index.html)
- [Source Code](https://github.com/michaelthomasletts/boto3-refresh-session)
- [PyPI](https://pypi.org/project/boto3-refresh-session/)
- [Contributing](https://michaelthomasletts.github.io/boto3-refresh-session/contributing.html)
- [Authorization](https://michaelthomasletts.github.io/boto3-refresh-session/authorization.html)

### Installation

```bash
pip install boto3-refresh-session
```

### Usage

```python
import boto3_refresh_session as brs

# you can pass all of the params associated with boto3.session.Session
profile_name = '<your-profile-name>'
region_name = 'us-east-1'
...

# as well as all of the params associated with STS.Client.assume_role
assume_role_kwargs = {
  'RoleArn': '<your-role-arn>',
  'RoleSessionName': '<your-role-session-name>',
  'DurationSeconds': '<your-selection>',
  ...
}

# as well as all of the params associated with STS.Client, except for 'service_name'
sts_client_kwargs = {
  'region_name': region_name,
  ...
}

# basic initialization of boto3.session.Session
session = brs.RefreshableSession(
  assume_role_kwargs=assume_role_kwargs, # required
  sts_client_kwargs=sts_client_kwargs,
  region_name=region_name,
  profile_name=profile_name,
  ...
)

# now you can create clients, resources, etc. without worrying about expired temporary 
# security credentials
s3 = session.client(service_name='s3')
buckets = s3.list_buckets()
```

### Raison d'ĂȘtre

It is common for data pipelines and workflows that interact with the AWS API via 
`boto3` to run for a long time and, accordingly, for temporary credentials to 
expire. 

Usually, engineers deal with that problem one of two ways: 

- `try except` blocks that catch `ClientError` exceptions
- A similar approach as that used in this project -- that is, using methods available 
  within `botocore` for refreshing temporary credentials automatically. 
  
Speaking personally, variations of the code found herein exists in code bases at 
nearly every company where I have worked. Sometimes, I turned that code into a module; 
other times, I wrote it from scratch. Clearly, that is inefficient.

I decided to finally turn that code into a proper Python package with unit testing, 
automatic documentation, and quality checks; the idea being that, henceforth, depending 
on my employer's open source policy, I may simply import this package instead of 
reproducing the code herein for the Nth time.

If any of that sounds relatable, then `boto3-refresh-session` should help you.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/michaelthomasletts/boto3-refresh-session",
    "name": "boto3-refresh-session",
    "maintainer": "Michael Letts",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "lettsmt@gmail.com",
    "keywords": "boto3, botocore, aws",
    "author": "Mike Letts",
    "author_email": "lettsmt@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2b/41/5db8d6490635283f57bb00c8846a0c898e00292801f1d498a6b8a15341c4/boto3_refresh_session-1.0.14.tar.gz",
    "platform": null,
    "description": "# boto3-refresh-session\n[![PyPI Download](https://img.shields.io/pypi/v/boto3-refresh-session?logo=pypis.svg)](https://pypi.org/project/boto3-refresh-session/)\n[![Workflow](https://img.shields.io/github/actions/workflow/status/michaelthomasletts/boto3-refresh-session/push.yml?logo=github)](https://github.com/michaelthomasletts/boto3-refresh-session/actions/workflows/push.yml)\n![Python Version](https://img.shields.io/pypi/pyversions/boto3-refresh-session?style=pypi)\n![GitHub last commit](https://img.shields.io/github/last-commit/michaelthomasletts/boto3-refresh-session?logo=github)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/boto3-refresh-session?logo=pypi)\n\n![BRS Image](https://raw.githubusercontent.com/michaelthomasletts/boto3-refresh-session/refs/heads/main/doc/brs.png)\n\nA simple Python package for refreshing the temporary security credentials in a `boto3.session.Session` object automatically.\n\n- [Official Documentation](https://michaelthomasletts.github.io/boto3-refresh-session/index.html)\n- [Source Code](https://github.com/michaelthomasletts/boto3-refresh-session)\n- [PyPI](https://pypi.org/project/boto3-refresh-session/)\n- [Contributing](https://michaelthomasletts.github.io/boto3-refresh-session/contributing.html)\n- [Authorization](https://michaelthomasletts.github.io/boto3-refresh-session/authorization.html)\n\n### Installation\n\n```bash\npip install boto3-refresh-session\n```\n\n### Usage\n\n```python\nimport boto3_refresh_session as brs\n\n# you can pass all of the params associated with boto3.session.Session\nprofile_name = '<your-profile-name>'\nregion_name = 'us-east-1'\n...\n\n# as well as all of the params associated with STS.Client.assume_role\nassume_role_kwargs = {\n  'RoleArn': '<your-role-arn>',\n  'RoleSessionName': '<your-role-session-name>',\n  'DurationSeconds': '<your-selection>',\n  ...\n}\n\n# as well as all of the params associated with STS.Client, except for 'service_name'\nsts_client_kwargs = {\n  'region_name': region_name,\n  ...\n}\n\n# basic initialization of boto3.session.Session\nsession = brs.RefreshableSession(\n  assume_role_kwargs=assume_role_kwargs, # required\n  sts_client_kwargs=sts_client_kwargs,\n  region_name=region_name,\n  profile_name=profile_name,\n  ...\n)\n\n# now you can create clients, resources, etc. without worrying about expired temporary \n# security credentials\ns3 = session.client(service_name='s3')\nbuckets = s3.list_buckets()\n```\n\n### Raison d'\u00eatre\n\nIt is common for data pipelines and workflows that interact with the AWS API via \n`boto3` to run for a long time and, accordingly, for temporary credentials to \nexpire. \n\nUsually, engineers deal with that problem one of two ways: \n\n- `try except` blocks that catch `ClientError` exceptions\n- A similar approach as that used in this project -- that is, using methods available \n  within `botocore` for refreshing temporary credentials automatically. \n  \nSpeaking personally, variations of the code found herein exists in code bases at \nnearly every company where I have worked. Sometimes, I turned that code into a module; \nother times, I wrote it from scratch. Clearly, that is inefficient.\n\nI decided to finally turn that code into a proper Python package with unit testing, \nautomatic documentation, and quality checks; the idea being that, henceforth, depending \non my employer's open source policy, I may simply import this package instead of \nreproducing the code herein for the Nth time.\n\nIf any of that sounds relatable, then `boto3-refresh-session` should help you.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A simple Python package for refreshing the temporary security credentials in a boto3.session.Session object automatically.",
    "version": "1.0.14",
    "project_urls": {
        "Documentation": "https://michaelthomasletts.github.io/boto3-refresh-session/index.html",
        "Homepage": "https://github.com/michaelthomasletts/boto3-refresh-session",
        "Repository": "https://github.com/michaelthomasletts/boto3-refresh-session"
    },
    "split_keywords": [
        "boto3",
        " botocore",
        " aws"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f66e79daa854a78052466d9b53afdcd8f038f05b4234cce63901957bd3f40e34",
                "md5": "2064280c481450d63141d5542ac3a687",
                "sha256": "998a5cc0d7aefbf626b159ba246aa3d92335d516ce2a5800abe156da1b344582"
            },
            "downloads": -1,
            "filename": "boto3_refresh_session-1.0.14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2064280c481450d63141d5542ac3a687",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 5558,
            "upload_time": "2025-03-06T18:12:04",
            "upload_time_iso_8601": "2025-03-06T18:12:04.620425Z",
            "url": "https://files.pythonhosted.org/packages/f6/6e/79daa854a78052466d9b53afdcd8f038f05b4234cce63901957bd3f40e34/boto3_refresh_session-1.0.14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2b415db8d6490635283f57bb00c8846a0c898e00292801f1d498a6b8a15341c4",
                "md5": "55847a669c4f675d5cfe8ddf8f33b895",
                "sha256": "cb0f86cf704c058d346a7a3221be88f6964f73203b3b453c74d12c60f4b3d26f"
            },
            "downloads": -1,
            "filename": "boto3_refresh_session-1.0.14.tar.gz",
            "has_sig": false,
            "md5_digest": "55847a669c4f675d5cfe8ddf8f33b895",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 4818,
            "upload_time": "2025-03-06T18:12:10",
            "upload_time_iso_8601": "2025-03-06T18:12:10.746984Z",
            "url": "https://files.pythonhosted.org/packages/2b/41/5db8d6490635283f57bb00c8846a0c898e00292801f1d498a6b8a15341c4/boto3_refresh_session-1.0.14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-03-06 18:12:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "michaelthomasletts",
    "github_project": "boto3-refresh-session",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "boto3-refresh-session"
}
        
Elapsed time: 1.56202s