Dynamic Dataclasses for the Super Lazy
Project description
awspydk
Async boto3 with Autogenerated JIT Data Classes
Motivation
This library is forked from an internal project that works with a lot of backend AWS APIs, and I got tired of having to constantly parse the returned responses before being able to work with them for (most of the time), a few seconds. Any API-driven application that uses boto3 tends to suffer from being syncronous only. So this library solves a few major problems:
-
Enables both
syncandasyncfrom the same client. -
Client can be called implicitly without needing initialization, i.e. you can directly use
AwsClientwithout needing to initialize. -
Dynamically generates class functions based on the
boto3.clientchild functions, and allows you to call them. This is useful inreploripythonenvironments where type-hints are always helpful, especially when the names are so long. -
Automatically initializes the
awsclient if its not initialized from the defaults, simply by calling it. -
Translates all results into Automatically Generated Dataclasses through
lazycls.- Can be disabled by setting
aws.config.AutoCls = False
- Can be disabled by setting
Quickstart
pip install --upgrade aws-sdk
from aws import AwsClient
# Sync Method
buckets = AwsClient.v1.s3_list_buckets(as_cls=True)
# Async Method
buckets = await AwsClient.v1.async_s3_list_buckets(as_cls=True)
"""
Both yield the same results.
The underlying classes are auto-generated from Pydantic BaseModels, so anything you can do with Pydantic Models, you can do with these.
{
'Buckets': [
AwsS3Bucket(CreationDate=datetime.datetime(2021, 8, 25, 16, 42, 46, tzinfo=tzutc()), Name='...'),
AwsS3Bucket(CreationDate=datetime.datetime(2021, 9, 2, 17, 54, 56, tzinfo=tzutc()), Name='...',
AwsS3Bucket(CreationDate=datetime.datetime(2021, 9, 3, 4, 20, 10, tzinfo=tzutc()), Name='...'),
AwsS3Bucket(CreationDate=datetime.datetime(2021, 9, 1, 20, 50, 33, tzinfo=tzutc()), Name='...'),
AwsS3Bucket(CreationDate=datetime.datetime(2021, 9, 2, 4, 2, 28, tzinfo=tzutc()), Name='...')
],
'Owner': AwsS3Owner(DisplayName='...', ID='...')
}
"""
## Change Regions
AwsClient.reset(region='us-west-1')
## Change the defaut clients created
from aws.config import DefaultClients
## Modify to only create ec2 client
DefaultClients = {
'ec2': 'ec2'
}
## Reset implicitly
AwsClient.reset()
BotoKwargs = {
'AWS_PROFILE': ...,
}
## Reset Explicitly
AwsClient.reset(clients=DefaultClients, boto_kwargs=BotoKwargs)
Client Defaults
These are found in aws.config
AwsRegion = envToStr('AWS_REGION', 'us-east-1')
AutoCls = envToBool('AWSSDK_AUTOCLS', 'true')
## These are the default clients that will be autogenerated.
## Key is the shorthand, value is the actual AWS API Name in boto3
DefaultClients = {
'ec2': 'ec2',
'ecr': 'ecr',
'r53' :'route53',
'acm': 'acm',
'elb': 'elb',
'elbv2': 'elbv2',
'asg': 'autoscaling',
's3': 's3'
}
## These are the default resources that will be autogenerated.
## Key is the shorthand, value is the actual AWS Resource API Name in boto3
DefaultResources = {
'Ec2': 'ec2',
'S3': 's3',
'Iam': 'iam'
}
# These are the default filter args for querying
DefaultFilterArgs = {
'string_only': True,
'remove_null': True
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awspydk-0.0.1.tar.gz.
File metadata
- Download URL: awspydk-0.0.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c45a75ddb35f07c75050c38ffceba45712893b9da141c2034018cdaf3647cf8
|
|
| MD5 |
106f36434fe4c4257990a4e1ab174deb
|
|
| BLAKE2b-256 |
90c6ab4567fb8001254c932f48573de6f152ac9b4f092095f60fe154ed2f9edc
|
File details
Details for the file awspydk-0.0.1-py3-none-any.whl.
File metadata
- Download URL: awspydk-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5894e44d75790443a620817884d00f37bed341356ec4814c8940b472db250e4a
|
|
| MD5 |
6ded9668af0cc9273d9fd673d303581f
|
|
| BLAKE2b-256 |
3183c05d0c637b04a648884d8628b532d9c7c781c31fcec9dce5221ebd4653a6
|