Use boto3-stubs to enable code completion on boto3

If you're building an AWS-based program in Python, you'll almost certainly be indebted to the AWS SDK called boto3.

This boto3 has a lot of functions that can hit all AWS services, but I do not hear code completion because there is no type. Since the service name is received as a character string such as boto3.client (" s3 "), the type definition is BaseClient type, not the client type for each service. This is quite difficult because I usually develop it in an environment where complements are listened to hard.

I wondered if something could be done and searched for it, and found a package called ** boto3-stubs **. In this, the type of the client resource for each service such as s3 and ec2 is defined, so if you give this type, ...

image.png image.png

You will be able to complement it like this! This is good! !!

Installation

pip install boto3-stubs[essential]

The version is designed to be combined with boto3, so even if you are using a specific boto3, you can use it without problems if you specify the same version number. The packages are updated automatically, and it seems that boto3-stubs were also released on the day boto3 was updated.

The [essential] specification above will contain the classes "ec2, s3, rds, lambda, sqs, dynamo, cloudformation". This alone requires about 7MB, so it seems that it does not suddenly fit all. If you need anything else, you can specify it in the form of [essential, ecs].

How to use

import boto3
from mypy_boto3_s3 import S3Client, S3ServiceResource  # from boto3-stubs

s3: S3Client = boto3.client("s3")
s3_r: S3ServiceResource = boto3.resource("s3")

Now you can hear code completion on the s3, s3_r variables. I'll specify the type, so any editor that can do type-based completion, such as VSCode, can do it the same way.

Digression

--If you use boto3-stubs with mypy, there seems to be a mechanism that allows you to check the type without writing the type specification by hand. ――It seems that there is a movement to prepare stubs even in the boto3 project. In the future, there may be movement around here as well.

Recommended Posts

Use boto3-stubs to enable code completion on boto3
Notes on how to use pywinauto
Notes on how to use featuretools
How to use homebrew on Debian
Notes on how to use doctest
Use boto3 to mess with S3
How to use mecab, neologd-ipadic on colab
I want to use Linux on mac
How to use Google Assistant on Windows 10
Memorandum on how to use gremlin python
Install python on xserver to use pip
Use boto to upload / download files to s3.
Use linter to reduce code review costs
Use the retry processing mode added to Boto3
Easy way to use Python 2.7 on Cent OS 6
How to use Ruby's PyCall to enable pyenv Python
[Windows] Memo to use Keras on GPU [Tensorflow-GPU]
Preparing to use aws cli on Mac OS X
Install Debian 10 to use Remote Development on BeagleBone Black
Preparing to use Tensorflow (Anaconda) with Visual Studio Code
How to use C216 Audio Controller on Arch Linux
A memorandum on how to use keras.preprocessing.image in Keras
How to use TensorFlow on GPUs less than Titan
Preparing to use Ansible on an existing Linux server
Autoencoder with Chainer (Notes on how to use + trainer)
I want to use OpenJDK 11 on Ubuntu Linux 18.04 LTS / 18.10
How to use Django on Google App Engine / Python
[Tips] How to use iPhone as webcam on Linux
Good and bad code to compare on a minimap