Mypy-friendly boto3 type annotations for ec2 service.
Project description
mypy_boto3
Mypy-friendly type annotations for boto3.
Installation
# install only `mypy_boto3.s3` for S3 service annotations
pip install mypy-boto3[s3]
# or install multiple services
pip install mypy-boto3[s3][ec2]
# or install S3 service with docs
pip install mypy-boto3[s3-with-docs]
# or install all services
pip install mypy-boto3[all]
# or even install all boto3 services annotations
# WARNING: this will eat ~70 MB of space
pip install mypy-boto3[all-with-docs]
Usage
-
Install mypy and optionally enable it in your IDE
-
Install boto3
-
Use
mypy-boto3
to annotate your code to discover errorsimport boto3 from mypy_boto3.s3 import Client, ServiceResource client: Client = boto3.client("s3") # IDE autocomplete suggests function name and arguemnts here client.create_bucket(Bucket="bucket") # (mypy) error: Missing positional argument "Key" in call to "get_object" of "Client" client.get_object(Bucket="bucket") # (mypy) error: Argument "Key" to "get_object" of "Client" has incompatible type "None"; expected "str" client.get_object(Bucket="bucket", Key=None) # explicitly set type to S3 ServiceResource resource: ServiceResource = 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" bucket.upload_file(Filename="my.txt", key="my-txt")
How it works
There is also a package mypy-boto3-builder
that builds interface files from boto3
documentation.
Differences from boto3-type-annotations
- Fully type annotated
mypy
compatibility- Generated types for return values and arguments
- Added ServiceResource sub-collections
- Support service-specific sub-modules (in progress)
- CLI interface for
builder
- Modules documentation
What's next
- Add
TypedDict
types for arguments and return types to check keys and values - Allow installation of sub-modules
- Always include docs and support them in generated documentation
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
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
mypy-boto3-ec2-0.1.2.tar.gz
(16.9 kB
view details)
Built Distribution
File details
Details for the file mypy-boto3-ec2-0.1.2.tar.gz
.
File metadata
- Download URL: mypy-boto3-ec2-0.1.2.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af7096cc48bd686ae8feada503577f32ae9f8164cd0d658faa0385dfbcaff7b |
|
MD5 | 6998c7508ea9793393661a2fbc0859c9 |
|
BLAKE2b-256 | dbd0f1299cc5ba837ecbd04548d5ca874ab4a89ed459a9cb53cfd888696843a6 |
File details
Details for the file mypy_boto3_ec2-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: mypy_boto3_ec2-0.1.2-py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9b75f0dfe081cd0198fea07ba758eec957cb09c644bcc7193a9d8b800044fa0 |
|
MD5 | dd691a284588059da002138b62cad967 |
|
BLAKE2b-256 | 0e08d1e4acccb758f394dd097d441e56e686def7c23781ec3fc21fd55e223b4c |