Builder for mypy-boto3.
Project description
mypy_boto3
Type annotations for boto3 compatible with mypy, VSCode, PyCharm and other tools.
Based on boto3_type_annotations by @alliefitter.
Installation
# install `boto3` type annotations
# for ec2, s3, rds, lambda, sqs, dynamo and cloudformation
# Consumes ~7 MB of space
python -m pip install 'boto3-stubs[essential]'
# or install annotations for services you use
python -m pip install 'boto3-stubs[acm,apigateway]'
Build services index manually
This package generates a few source files depending on services that you installed.
Generation is done by a post-install script, so as long as you use pip
, pipfile
or poetry
everything should be done automatically.
However, if you use any other way and notice that services stubs do not work, you can build services index manually.
# Use this command when you add or remove service packages
python -m mypy_boto3
How to uninstall
Some files are generated by service post-install scripts, so pip
does not fully remove packages.
To properly uninstall boto3-stubs
, use these commands:
# remove generated files and cache
python -m mypy_boto3 --clean
# remove boto3-stubs
python -m pip uninstall -y boto3-stubs
# remove mypy-boto3 and submodules
python -m pip freeze | grep mypy-boto3 | xargs python -m pip uninstall -y
Alternatively you can just remove mypy_boto3
folder from site-packages
after uninstall.
rm -r `python -m site --user-site`/mypy_boto3
Usage
- Install mypy and optionally enable it in your IDE
- Install boto3
- VSCode: Use explicit types for
boto3.client
,boto3.session.client
,client.get_waiter
andclient.get_paginator
calls to enjoy code auto-complete and correct type hints
import boto3
from mypy_boto3 import s3
# you need explicit type annotatins only if your IDE do not support
# function overloads (e.g. VSCode). For PyCharm anf mypy you do not need
# to set types explicitly
client: s3.S3Client = boto3.client("s3")
# IDE autocomplete suggests function name and arguments here
client.create_bucket(Bucket="bucket")
# (mypy) error: Missing positional argument "Key" in call to "get_object" of "S3Client"
client.get_object(Bucket="bucket")
# (mypy) error: Argument "Key" to "get_object" of "S3Client" has incompatible type "None"; expected "str"
client.get_object(Bucket="bucket", Key=None)
resource: s3.S3ServiceResource = boto3.Session(region_name="us-west-1").resource("s3")
# IDE autocomplete suggests function name and arguments here
bucket = resource.Bucket("bucket")
# (mypy) error: Unexpected keyword argument "key" for "upload_file" of "Bucket"; did you mean "Key"?
bucket.upload_file(Filename="my.txt", key="my-txt")
# waiters and paginators are annotated as well
waiter: s3.BucketExistsWaiter = client.get_waiter("bucket_exists")
paginator: s3.ListMultipartUploadsPaginator = client.get_paginator(
"list_multipart_uploads"
)
Setup your IDE
VSCode
- Install Official Python extension
- Install mypy
- Activate
mypy
checking in settings:"python.linting.mypyEnabled": true
- Install
boto3-stubs
withboto3
services you use - Use explicit type annotations because
function overload is not fully supported
in
Python
extension.
PyCharm
- Install mypy plugin
- Install mypy
- Set path to
mypy
inmypy plugin
settings - Install
boto3-stubs
withboto3
services you use - Use explicit type annotations for
session.client
andsession.resource
calls
Official mypy
plugin does not work for some reason for me. If you know
how to setup it correctly, please hep me to update this section.
Other IDEs
- Install mypy
- Set path to
mypy
inmypy plugin
settings - Install
boto3-stubs
withboto3
services you use
You need explicit type annotations for code
auto-complete, but mypy
works even without them.
Explicit type annotations
Automatic type discovery is too stressful for PyCharm and does not work in VSCode. So implicit type annotations support has been removed as it is not useful.
To get full advantage of boto3-stubs
, you can set types explicitly.
import boto3
from mypy_boto3 import ec2
# covered by boto3-stubs, no explicit type required
session = boto3.session.Session(region_name="us-west-1")
# by default it is Any, but we explicitly set it to EC2Client
# to make method auto-complete work
ec2_client: ec2.EC2Client = boto3.client("ec2", region_name="us-west-1")
# same for resource
ec2_resource: ec2.EC2ServiceResource = session.resource("ec2")
# PyCharm does not need explicit type annotations here, but VSCode does
bundle_task_complete_waiter: ec2.BundleTaskCompleteWaiter = ec2_client.get_waiter("bundle_task_complete")
describe_volumes_paginator: ec2.DescribeVolumesPaginator = ec2_client.get_paginator("describe_volumes")
# ec2_client, ec2_resource, bundle_task_complete_waiter and describe_volumes_paginator
# now have correct type so IDE autocomplete for methods, arguments and return types
# works as expected. You do not need to specify types explicitly further
Pylint compatibility
It is totally safe to use TYPE_CHECKING
flag in order to avoid boto3-stubs
dependency in production.
However, there is an issue in pylint
that it complains about undefined
variables. To fix it, set all types to object
in non-TYPE_CHECKING
mode.
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3.ec2 import EC2Client, EC2ServiceResource
from mypy_boto3.ec2.waiters import BundleTaskCompleteWaiter
from mypy_boto3.ec2.paginators import DescribeVolumesPaginator
else:
EC2Client = object
EC2ServiceResource = object
BundleTaskCompleteWaiter = object
DescribeVolumesPaginator = object
...
How to build
Locally
mypy-boto3
is built for the latest version of boto3
. If you need type annotations for another
version of boto3
, you can use mypy-boto3-builder
.
# Install preferred version of `boto3`
python -m pip install boto3==1.10.18 botocore==1.13.18
# Install `mypy-boto3-builder`
python -m pip install mypy-boto3-builder
# Build all packages
# You can specify required services explicitly like
# ./scripts/build.sh -s ec2 s3
./scripts/build.sh
# Install custom `mypy-boto3` packages
./scripts/install.sh
With Docker image
- Install Docker
- Pull latest
mypy_boto3_builder
version and tag it
docker pull docker.pkg.github.com/vemel/mypy_boto3/mypy_boto3_builder:latest
docker tag docker.pkg.github.com/vemel/mypy_boto3/mypy_boto3_builder:latest mypy_boto3_builder
- Generate stubs in
output
directory
mkdir output
# generate stubs for all services
docker run -v `pwd`/output:/output -ti mypy_boto3_builder
# generate stubs for s3 service
docker run -v `pwd`/output:/output -ti mypy_boto3_builder -s s3
# generate stubs for a specific boto3 version
docker run -e BOTO3_VERSION=1.10.18 BOTOCORE_VERSION=1.13.18 -v `pwd`/output:/output -ti mypy_boto3_builder
- Install packages from
output
directory as described above
What's new
Implemented features
mypy
,VSCode
andPyCharm
compatibility- Fully type annotated
boto3
library Client
type annotations for each serviceServiceResource
type annotations for each serviceResource
type annotations for each serviceWaiter
type annotations for each servicePaginator
type annotations for each service- Generated
TypeDefs
for each service - Auto discovery of types for
boto3.client
andboto3.session
calls - Auto discovery of types for
session.client
andsession.session
calls - Auto discovery of types for
client.get_waiter
andclient.get_paginator
calls - Auto discovery of types for
ServiceResource
andResource
collections - CLI for managing installed submodules
Latest changes
Full changelog can be found in Releases.
Versioning
mypy_boto3_builder
version is not related to boto3
version and follows
Semantic Versioning.
Generated packages use format <boto3_version>.<build>
, e.g. for boto3 1.10.40
,
mypy_boto3
versions are is 1.10.40.0
and 1.10.40.1
.
Thank you
- Guys behind boto3-type-annotations, this package is based on top of their work
- black developers for awesome formatting tool
- mypy for doing all dirty work for us
Sub-modules
Examples
You can install any sub-modules using pip
# pip install boto3-stubs[<submodule_name>,...]
# install `boto3` type annotations
# for ec2, s3, rds, lambda, sqs, dynamo and cloudformation
python -m pip install 'boto3-stubs[essential]'
# install ec2, s3 and sqs type annotations
python -m pip install 'boto3-stubs[s3,ec2,sqs]'
List of all sub-modules
boto3-stubs[essential]
- Type annotations for CloudFormation, DynamoDB, EC2, Lambda, RDS, S3 and SQS services.boto3-stubs[accessanalyzer]
- Type annotations for AccessAnalyzer service.boto3-stubs[acm]
- Type annotations for ACM service.boto3-stubs[acm-pca]
- Type annotations for ACMPCA service.boto3-stubs[alexaforbusiness]
- Type annotations for AlexaForBusiness service.boto3-stubs[amplify]
- Type annotations for Amplify service.boto3-stubs[apigateway]
- Type annotations for APIGateway service.boto3-stubs[apigatewaymanagementapi]
- Type annotations for ApiGatewayManagementApi service.boto3-stubs[apigatewayv2]
- Type annotations for ApiGatewayV2 service.boto3-stubs[appconfig]
- Type annotations for AppConfig service.boto3-stubs[application-autoscaling]
- Type annotations for ApplicationAutoScaling service.boto3-stubs[application-insights]
- Type annotations for ApplicationInsights service.boto3-stubs[appmesh]
- Type annotations for AppMesh service.boto3-stubs[appstream]
- Type annotations for AppStream service.boto3-stubs[appsync]
- Type annotations for AppSync service.boto3-stubs[athena]
- Type annotations for Athena service.boto3-stubs[autoscaling]
- Type annotations for AutoScaling service.boto3-stubs[autoscaling-plans]
- Type annotations for AutoScalingPlans service.boto3-stubs[backup]
- Type annotations for Backup service.boto3-stubs[batch]
- Type annotations for Batch service.boto3-stubs[budgets]
- Type annotations for Budgets service.boto3-stubs[ce]
- Type annotations for CostExplorer service.boto3-stubs[chime]
- Type annotations for Chime service.boto3-stubs[cloud9]
- Type annotations for Cloud9 service.boto3-stubs[clouddirectory]
- Type annotations for CloudDirectory service.boto3-stubs[cloudformation]
- Type annotations for CloudFormation service.boto3-stubs[cloudfront]
- Type annotations for CloudFront service.boto3-stubs[cloudhsm]
- Type annotations for CloudHSM service.boto3-stubs[cloudhsmv2]
- Type annotations for CloudHSMV2 service.boto3-stubs[cloudsearch]
- Type annotations for CloudSearch service.boto3-stubs[cloudsearchdomain]
- Type annotations for CloudSearchDomain service.boto3-stubs[cloudtrail]
- Type annotations for CloudTrail service.boto3-stubs[cloudwatch]
- Type annotations for CloudWatch service.boto3-stubs[codebuild]
- Type annotations for CodeBuild service.boto3-stubs[codecommit]
- Type annotations for CodeCommit service.boto3-stubs[codedeploy]
- Type annotations for CodeDeploy service.boto3-stubs[codeguru-reviewer]
- Type annotations for CodeGuruReviewer service.boto3-stubs[codeguruprofiler]
- Type annotations for CodeGuruProfiler service.boto3-stubs[codepipeline]
- Type annotations for CodePipeline service.boto3-stubs[codestar]
- Type annotations for CodeStar service.boto3-stubs[codestar-connections]
- Type annotations for CodeStarconnections service.boto3-stubs[codestar-notifications]
- Type annotations for CodeStarNotifications service.boto3-stubs[cognito-identity]
- Type annotations for CognitoIdentity service.boto3-stubs[cognito-idp]
- Type annotations for CognitoIdentityProvider service.boto3-stubs[cognito-sync]
- Type annotations for CognitoSync service.boto3-stubs[comprehend]
- Type annotations for Comprehend service.boto3-stubs[comprehendmedical]
- Type annotations for ComprehendMedical service.boto3-stubs[compute-optimizer]
- Type annotations for ComputeOptimizer service.boto3-stubs[config]
- Type annotations for ConfigService service.boto3-stubs[connect]
- Type annotations for Connect service.boto3-stubs[connectparticipant]
- Type annotations for ConnectParticipant service.boto3-stubs[cur]
- Type annotations for CostandUsageReportService service.boto3-stubs[dataexchange]
- Type annotations for DataExchange service.boto3-stubs[datapipeline]
- Type annotations for DataPipeline service.boto3-stubs[datasync]
- Type annotations for DataSync service.boto3-stubs[dax]
- Type annotations for DAX service.boto3-stubs[detective]
- Type annotations for Detective service.boto3-stubs[devicefarm]
- Type annotations for DeviceFarm service.boto3-stubs[directconnect]
- Type annotations for DirectConnect service.boto3-stubs[discovery]
- Type annotations for ApplicationDiscoveryService service.boto3-stubs[dlm]
- Type annotations for DLM service.boto3-stubs[dms]
- Type annotations for DatabaseMigrationService service.boto3-stubs[docdb]
- Type annotations for DocDB service.boto3-stubs[ds]
- Type annotations for DirectoryService service.boto3-stubs[dynamodb]
- Type annotations for DynamoDB service.boto3-stubs[dynamodbstreams]
- Type annotations for DynamoDBStreams service.boto3-stubs[ebs]
- Type annotations for EBS service.boto3-stubs[ec2]
- Type annotations for EC2 service.boto3-stubs[ec2-instance-connect]
- Type annotations for EC2InstanceConnect service.boto3-stubs[ecr]
- Type annotations for ECR service.boto3-stubs[ecs]
- Type annotations for ECS service.boto3-stubs[efs]
- Type annotations for EFS service.boto3-stubs[eks]
- Type annotations for EKS service.boto3-stubs[elastic-inference]
- Type annotations for ElasticInference service.boto3-stubs[elasticache]
- Type annotations for ElastiCache service.boto3-stubs[elasticbeanstalk]
- Type annotations for ElasticBeanstalk service.boto3-stubs[elastictranscoder]
- Type annotations for ElasticTranscoder service.boto3-stubs[elb]
- Type annotations for ElasticLoadBalancing service.boto3-stubs[elbv2]
- Type annotations for ElasticLoadBalancingv2 service.boto3-stubs[emr]
- Type annotations for EMR service.boto3-stubs[es]
- Type annotations for ElasticsearchService service.boto3-stubs[events]
- Type annotations for EventBridge service.boto3-stubs[firehose]
- Type annotations for Firehose service.boto3-stubs[fms]
- Type annotations for FMS service.boto3-stubs[forecast]
- Type annotations for ForecastService service.boto3-stubs[forecastquery]
- Type annotations for ForecastQueryService service.boto3-stubs[frauddetector]
- Type annotations for FraudDetector service.boto3-stubs[fsx]
- Type annotations for FSx service.boto3-stubs[gamelift]
- Type annotations for GameLift service.boto3-stubs[glacier]
- Type annotations for Glacier service.boto3-stubs[globalaccelerator]
- Type annotations for GlobalAccelerator service.boto3-stubs[glue]
- Type annotations for Glue service.boto3-stubs[greengrass]
- Type annotations for Greengrass service.boto3-stubs[groundstation]
- Type annotations for GroundStation service.boto3-stubs[guardduty]
- Type annotations for GuardDuty service.boto3-stubs[health]
- Type annotations for Health service.boto3-stubs[iam]
- Type annotations for IAM service.boto3-stubs[imagebuilder]
- Type annotations for Imagebuilder service.boto3-stubs[importexport]
- Type annotations for ImportExport service.boto3-stubs[inspector]
- Type annotations for Inspector service.boto3-stubs[iot]
- Type annotations for IoT service.boto3-stubs[iot-data]
- Type annotations for IoTDataPlane service.boto3-stubs[iot-jobs-data]
- Type annotations for IoTJobsDataPlane service.boto3-stubs[iot1click-devices]
- Type annotations for IoT1ClickDevicesService service.boto3-stubs[iot1click-projects]
- Type annotations for IoT1ClickProjects service.boto3-stubs[iotanalytics]
- Type annotations for IoTAnalytics service.boto3-stubs[iotevents]
- Type annotations for IoTEvents service.boto3-stubs[iotevents-data]
- Type annotations for IoTEventsData service.boto3-stubs[iotsecuretunneling]
- Type annotations for IoTSecureTunneling service.boto3-stubs[iotthingsgraph]
- Type annotations for IoTThingsGraph service.boto3-stubs[kafka]
- Type annotations for Kafka service.boto3-stubs[kendra]
- Type annotations for Kendra service.boto3-stubs[kinesis]
- Type annotations for Kinesis service.boto3-stubs[kinesis-video-archived-media]
- Type annotations for KinesisVideoArchivedMedia service.boto3-stubs[kinesis-video-media]
- Type annotations for KinesisVideoMedia service.boto3-stubs[kinesis-video-signaling]
- Type annotations for KinesisVideoSignalingChannels service.boto3-stubs[kinesisanalytics]
- Type annotations for KinesisAnalytics service.boto3-stubs[kinesisanalyticsv2]
- Type annotations for KinesisAnalyticsV2 service.boto3-stubs[kinesisvideo]
- Type annotations for KinesisVideo service.boto3-stubs[kms]
- Type annotations for KMS service.boto3-stubs[lakeformation]
- Type annotations for LakeFormation service.boto3-stubs[lambda]
- Type annotations for Lambda service.boto3-stubs[lex-models]
- Type annotations for LexModelBuildingService service.boto3-stubs[lex-runtime]
- Type annotations for LexRuntimeService service.boto3-stubs[license-manager]
- Type annotations for LicenseManager service.boto3-stubs[lightsail]
- Type annotations for Lightsail service.boto3-stubs[logs]
- Type annotations for CloudWatchLogs service.boto3-stubs[machinelearning]
- Type annotations for MachineLearning service.boto3-stubs[macie]
- Type annotations for Macie service.boto3-stubs[managedblockchain]
- Type annotations for ManagedBlockchain service.boto3-stubs[marketplace-catalog]
- Type annotations for MarketplaceCatalog service.boto3-stubs[marketplace-entitlement]
- Type annotations for MarketplaceEntitlementService service.boto3-stubs[marketplacecommerceanalytics]
- Type annotations for MarketplaceCommerceAnalytics service.boto3-stubs[mediaconnect]
- Type annotations for MediaConnect service.boto3-stubs[mediaconvert]
- Type annotations for MediaConvert service.boto3-stubs[medialive]
- Type annotations for MediaLive service.boto3-stubs[mediapackage]
- Type annotations for MediaPackage service.boto3-stubs[mediapackage-vod]
- Type annotations for MediaPackageVod service.boto3-stubs[mediastore]
- Type annotations for MediaStore service.boto3-stubs[mediastore-data]
- Type annotations for MediaStoreData service.boto3-stubs[mediatailor]
- Type annotations for MediaTailor service.boto3-stubs[meteringmarketplace]
- Type annotations for MarketplaceMetering service.boto3-stubs[mgh]
- Type annotations for MigrationHub service.boto3-stubs[migrationhub-config]
- Type annotations for MigrationHubConfig service.boto3-stubs[mobile]
- Type annotations for Mobile service.boto3-stubs[mq]
- Type annotations for MQ service.boto3-stubs[mturk]
- Type annotations for MTurk service.boto3-stubs[neptune]
- Type annotations for Neptune service.boto3-stubs[networkmanager]
- Type annotations for NetworkManager service.boto3-stubs[opsworks]
- Type annotations for OpsWorks service.boto3-stubs[opsworkscm]
- Type annotations for OpsWorksCM service.boto3-stubs[organizations]
- Type annotations for Organizations service.boto3-stubs[outposts]
- Type annotations for Outposts service.boto3-stubs[personalize]
- Type annotations for Personalize service.boto3-stubs[personalize-events]
- Type annotations for PersonalizeEvents service.boto3-stubs[personalize-runtime]
- Type annotations for PersonalizeRuntime service.boto3-stubs[pi]
- Type annotations for PI service.boto3-stubs[pinpoint]
- Type annotations for Pinpoint service.boto3-stubs[pinpoint-email]
- Type annotations for PinpointEmail service.boto3-stubs[pinpoint-sms-voice]
- Type annotations for PinpointSMSVoice service.boto3-stubs[polly]
- Type annotations for Polly service.boto3-stubs[pricing]
- Type annotations for Pricing service.boto3-stubs[qldb]
- Type annotations for QLDB service.boto3-stubs[qldb-session]
- Type annotations for QLDBSession service.boto3-stubs[quicksight]
- Type annotations for QuickSight service.boto3-stubs[ram]
- Type annotations for RAM service.boto3-stubs[rds]
- Type annotations for RDS service.boto3-stubs[rds-data]
- Type annotations for RDSDataService service.boto3-stubs[redshift]
- Type annotations for Redshift service.boto3-stubs[rekognition]
- Type annotations for Rekognition service.boto3-stubs[resource-groups]
- Type annotations for ResourceGroups service.boto3-stubs[resourcegroupstaggingapi]
- Type annotations for ResourceGroupsTaggingAPI service.boto3-stubs[robomaker]
- Type annotations for RoboMaker service.boto3-stubs[route53]
- Type annotations for Route53 service.boto3-stubs[route53domains]
- Type annotations for Route53Domains service.boto3-stubs[route53resolver]
- Type annotations for Route53Resolver service.boto3-stubs[s3]
- Type annotations for S3 service.boto3-stubs[s3control]
- Type annotations for S3Control service.boto3-stubs[sagemaker]
- Type annotations for SageMaker service.boto3-stubs[sagemaker-a2i-runtime]
- Type annotations for AugmentedAIRuntime service.boto3-stubs[sagemaker-runtime]
- Type annotations for SageMakerRuntime service.boto3-stubs[savingsplans]
- Type annotations for SavingsPlans service.boto3-stubs[schemas]
- Type annotations for Schemas service.boto3-stubs[sdb]
- Type annotations for SimpleDB service.boto3-stubs[secretsmanager]
- Type annotations for SecretsManager service.boto3-stubs[securityhub]
- Type annotations for SecurityHub service.boto3-stubs[serverlessrepo]
- Type annotations for ServerlessApplicationRepository service.boto3-stubs[service-quotas]
- Type annotations for ServiceQuotas service.boto3-stubs[servicecatalog]
- Type annotations for ServiceCatalog service.boto3-stubs[servicediscovery]
- Type annotations for ServiceDiscovery service.boto3-stubs[ses]
- Type annotations for SES service.boto3-stubs[sesv2]
- Type annotations for SESV2 service.boto3-stubs[shield]
- Type annotations for Shield service.boto3-stubs[signer]
- Type annotations for Signer service.boto3-stubs[sms]
- Type annotations for SMS service.boto3-stubs[sms-voice]
- Type annotations for SMSVoice service.boto3-stubs[snowball]
- Type annotations for Snowball service.boto3-stubs[sns]
- Type annotations for SNS service.boto3-stubs[sqs]
- Type annotations for SQS service.boto3-stubs[ssm]
- Type annotations for SSM service.boto3-stubs[sso]
- Type annotations for SSO service.boto3-stubs[sso-oidc]
- Type annotations for SSOOIDC service.boto3-stubs[stepfunctions]
- Type annotations for SFN service.boto3-stubs[storagegateway]
- Type annotations for StorageGateway service.boto3-stubs[sts]
- Type annotations for STS service.boto3-stubs[support]
- Type annotations for Support service.boto3-stubs[swf]
- Type annotations for SWF service.boto3-stubs[textract]
- Type annotations for Textract service.boto3-stubs[transcribe]
- Type annotations for TranscribeService service.boto3-stubs[transfer]
- Type annotations for Transfer service.boto3-stubs[translate]
- Type annotations for Translate service.boto3-stubs[waf]
- Type annotations for WAF service.boto3-stubs[waf-regional]
- Type annotations for WAFRegional service.boto3-stubs[wafv2]
- Type annotations for WAFV2 service.boto3-stubs[workdocs]
- Type annotations for WorkDocs service.boto3-stubs[worklink]
- Type annotations for WorkLink service.boto3-stubs[workmail]
- Type annotations for WorkMail service.boto3-stubs[workmailmessageflow]
- Type annotations for WorkMailMessageFlow service.boto3-stubs[workspaces]
- Type annotations for WorkSpaces service.boto3-stubs[xray]
- Type annotations for XRay service.
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
Hashes for mypy_boto3_builder-0.9.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd94b4a4e01e0fc7f79a76312d96673c8722ec5e80a641ec239d8b4e8bb3439d |
|
MD5 | d9fe926d47ac05e9af8ab975e68dfba3 |
|
BLAKE2b-256 | f933294ef8768f7be81d87523ef82feef34a88a83d94d20b01eb488f418e3e7f |