aioboto3-assume
Easily create aioboto3 assume role sessions with automatic credential refreshing.
NOTE - For
boto3support, see boto3-assume.
Installation
Install with pip:
$ pip install aioboto3-assume
Tutorial
import aioboto3
from aioboto3_assume import assume_role
assume_session = assume_role(
source_session=aioboto3.Session(), # You must pass in an aioboto3 session that automatically refreshes!
assume_role_kwargs={
"RoleArn": "arn:aws:iam::123412341234:role/my_role",
"RoleSessionName": "my-role-session"
}
)
async def main():
# Create clients, and their credentials will auto-refresh when expired!
async with assume_session.client("sts", region_name="us-east-1") as sts_client:
print(await sts_client.get_caller_identity())
# {
# "UserId": "EXAMPLEID",
# "Account": "123412341234",
# "Arn": "arn:aws:sts::123412341234:role/my_role",
# "ResponseMetadata": {
# "RequestId": "asdfqwfqwfasdfasdfasfsdf",
# "HTTPStatusCode": 200,
# "HTTPHeaders": {
# "server": "amazon.com",
# "date": "Tue, 27 Jun 2023 00:00:00 GMT"
# },
# "RetryAttempts": 0
# }
# }
asyncio.run(main())
Under the hood an aioboto3 sts client will be created and assume_role called to get/refresh credentials.
You can pass the kwargs parameters as so:
assume_role_kwargs- Keyword arguments to pass when calling assume_role with a boto3 STS client.- Must at least provide
RoleArnandRoleSessionNameas outlined in the boto3 docs.
- Must at least provide
sts_client_kwargs- Kwargs to pass when creating the boto3 low level client for STS- By default only the service argument will be passed as
"sts". - Note that you should not pass in the
service_nameor credentials here.
- By default only the service argument will be passed as
target_session_kwargs- Keyword arguments to pass when creating a the new target boto3 Session- By default no arguments are passed.
- Note that you should only pass in
region_nameoraws_account_idor other variables that will not effect credentials or credential refreshing.
A more complex example:
import aioboto3
from aioboto3_assume import assume_role
from botocore.config import Config
assume_session = assume_role(
source_session=aioboto3.Session(),
assume_role_kwargs={
"RoleArn": "arn:aws:iam::123412341234:role/my_role",
"RoleSessionName": "my-role-session",
"DurationSeconds": 900,
"Tags": [
{
"Key": "MyKey",
"Value": "MyValue"
}
]
},
sts_client_kwargs={
"config": Config(
retries={
"total_max_attempts": 10,
"mode": "adaptive"
}
)
},
target_session_kwargs={
"region_name": "us-east-1"
}
)
Development
Install the package in editable mode with dev dependencies.
(venv) $ pip install -e .[dev]
nox is used to manage various dev functions. Start with
(venv) $ nox --help
pyenv is used to manage python versions. To run the nox tests for applicable python version you will first need to install them. In the root project dir run:
(venv) $ pyenv install
Changelog
Changelog for aioboto3-assume.
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
[0.1.2] - 2026-01-14
Fixed
- README link
[0.1.1] - 2026-01-14
Fixed
- type hints and docstrings on
assume_role - README formatting
[0.1.0] - 2026-01-13
Initial Release.
Split from boto3-assume package.
Metadata
Release files for aioboto3-assume 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aioboto3_assume-0.1.2.tar.gz | 10.1 kB | Without provenance | Details for aioboto3_assume-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aioboto3_assume-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for aioboto3_assume-0.1.2-py3-none-any.whl |
Total release size: 20.6 kB
Release files / aioboto3_assume-0.1.2.tar.gz
| Download URL | aioboto3_assume-0.1.2.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a4a7047bfe83974478b4a35193e9ad3b5303effbac4f56e18d9908f42d93b0c
|
|
BLAKE2b-256 checksum How to use checksums |
7606045ead4f08282cb62a10c1692e31a53c58d4577af01bbefb86650c5f65b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Release files / aioboto3_assume-0.1.2-py3-none-any.whl
| Download URL | aioboto3_assume-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
661d1a656daa58f10c875b299c991ad8d3e862f879426bbd1e7deac3382540ec
|
|
BLAKE2b-256 checksum How to use checksums |
ca37165ed4f5a989fb3d7d69468e11a57f4dcfd3d51c95a8d0256f0defc8def1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.3
|
Security for aioboto3-assume 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.