Skip to main content

Mypy-friendly boto3 type annotations.

Project description

mypy_boto3

Mypy-friendly type annotations for boto3.

Installation

pip install mypy-boto3

Usage

  • Install mypy and optionally enable it in your IDE

  • Use mypy-boto3 to annotate your code to discover errors

    import 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.

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

This version

0.1.0

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-0.1.0.tar.gz (175.3 kB view hashes)

Uploaded Source

Built Distribution

mypy_boto3-0.1.0-py3-none-any.whl (396.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page