# boto3-stubs
[![PyPI - boto3-stubs](https://img.shields.io/pypi/v/boto3-stubs.svg?color=blue)](https://pypi.org/project/boto3-stubs)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/boto3-stubs.svg?color=blue)](https://pypi.org/project/boto3-stubs)
[![Docs](https://img.shields.io/readthedocs/mypy-boto3-builder.svg?color=blue)](https://mypy-boto3-builder.readthedocs.io/)
Type annotations for
[boto3 1.12.17](https://boto3.amazonaws.com/v1/documentation/api/1.12.17/index.html)
compatible with [mypy](https://github.com/python/mypy), [VSCode](https://code.visualstudio.com/),
[PyCharm](https://www.jetbrains.com/pycharm/) and other tools.
Generated by [mypy-boto3-buider 1.0.4](https://github.com/vemel/mypy_boto3_builder).
- [boto3-stubs](#boto3-stubs)
- [Installation](#installation)
- [Basic](#basic)
- [Build services index manually](#build-services-index-manually)
- [How to uninstall](#how-to-uninstall)
- [Usage](#usage)
- [Basic](#basic-1)
- [Setup your IDE](#setup-your-ide)
- [VSCode](#vscode)
- [PyCharm](#pycharm)
- [Other IDEs](#other-ides)
- [Explicit type annotations](#explicit-type-annotations)
- [Pylint compatibility](#pylint-compatibility)
- [How it works](#how-it-works)
- [What's new](#whats-new)
- [Implemented features](#implemented-features)
- [Latest changes](#latest-changes)
- [Versioning](#versioning)
- [Thank you](#thank-you)
- [Submodules](#submodules)
## Installation
### Basic
Make sure you have [mypy](https://github.com/python/mypy) installed and activated in your IDE.
Install `boto3-stubs`, to add type annotations for `boto3` package.
```bash
# install type annotations just for boto3
python -m pip install boto3-stubs
# 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]'
```
Use `boto3` with `mypy_boto3` in your project and enjoy type checking.
```python
import boto3
from mypy_boto3 import dynamodb
# Enjoy auto-complete from now
client: dynamodb.DynamoDBClient = boto3.client("dynamodb")
# argument hints and correct return type is provided by boto3-stubs
client.query("my_table")
```
### 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 or notice that services stubs do not work,
you can build services index manually.
```bash
# Use this command when you add or remove service packages
python -m mypy_boto3
```
If you generate `requirements.txt` from `Pipfile.lock`, you also should build
index manually because package installation order is not the same.
```bash
# Add boto3-stubs with services
pipenv install 'boto3-stubs[s3,ec2]'
# Generate requirements.txt file
pipenv lock --requirements > requirements.txt
...
# Install pacakges to your new environment
pip intall requirements.txt
# Generate index
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:
```bash
# 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.
```bash
rm -r `python -m site --user-site`/mypy_boto3
```
## Usage
### Basic
- Install [mypy](https://github.com/python/mypy) and optionally enable it in your IDE
- Install [boto3](https://github.com/boto/boto3)
- VSCode: Use explicit types for `boto3.client`, `boto3.session.client`,
`client.get_waiter` and `client.get_paginator` calls to enjoy code auto-complete and
correct type hints
```python
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](https://github.com/microsoft/vscode-python)
- Install [mypy](https://github.com/python/mypy)
- Activate `mypy` checking in settings: `"python.linting.mypyEnabled": true`
- Install `boto3-stubs` with `boto3` services you use
- Use [explicit type annotations](#explicit-type-annotations) because
function overload [is not fully supported](https://github.com/microsoft/python-language-server/issues/1648)
in `Python` extension.
### PyCharm
- Install [mypy plugin](https://plugins.jetbrains.com/plugin/11086-mypy/)
- Install [mypy](https://github.com/python/mypy)
- Set path to `mypy` in `mypy plugin` settings
- Install `boto3-stubs` with `boto3` services you use
- Use [explicit type annotations](#explicit-type-annotations) for
`session.client` and `session.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](https://github.com/python/mypy)
- Set path to `mypy` in `mypy plugin` settings
- Install `boto3-stubs` with `boto3` services you use
You need [explicit type annotations](#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.
```python
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 `pyl
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:boto3-stubs-1.12.17.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
boto3-stubs-1.12.17.0.tar.gz (34个子文件)
boto3-stubs-1.12.17.0
PKG-INFO 61KB
setup.cfg 38B
setup.py 15KB
boto3-stubs
exceptions.pyi 1KB
py.typed 0B
compat.pyi 277B
dynamodb
conditions.pyi 5KB
table.pyi 1KB
types.pyi 1KB
__init__.pyi 0B
transform.pyi 2KB
resources
collection.pyi 2KB
model.pyi 4KB
params.pyi 612B
base.pyi 1KB
action.pyi 1KB
factory.pyi 580B
response.pyi 2KB
__init__.pyi 0B
ec2
create_tags.pyi 477B
delete_tags.pyi 280B
__init__.pyi 0B
__init__.py 0B
session.pyi 3KB
utils.pyi 845B
version.py 57B
__init__.pyi 1KB
README.md 50KB
boto3_stubs.egg-info
PKG-INFO 61KB
requires.txt 10KB
not-zip-safe 1B
SOURCES.txt 945B
top_level.txt 12B
dependency_links.txt 1B
共 34 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功