使用 mypy-boto3-builder 7.11.8 生成的 boto3.SNS 1.24.68 服务的类型注释
项目描述
mypy-boto3-sns
boto3.SNS 1.24.68服务的类型注释 兼容VSCode、 PyCharm、 Emacs、 Sublime Text、 mypy、 pyright和其他工具。
由 mypy-boto3-builder 7.11.8 生成。
更多信息可以在 boto3-stubs页面和 mypy-boto3-sns 文档中找到。
了解它如何帮助查找和修复潜在错误:
如何安装
VSCode 扩展
将
AWS Boto3
扩展添加到您的 VSCode 并运行AWS boto3: Quick Start
命令。
单击Modify
并选择boto3 common
和SNS
。
来自带有 pip 的 PyPI
安装boto3-stubs
服务SNS
。
# install with boto3 type annotations
python -m pip install 'boto3-stubs[sns]'
# Lite version does not provide session.client/resource overloads
# it is more RAM-friendly, but requires explicit type annotations
python -m pip install 'boto3-stubs-lite[sns]'
# standalone installation
python -m pip install mypy-boto3-sns
如何卸载
python -m pip uninstall -y mypy-boto3-sns
用法
VSCode
- 安装 Python 扩展
- 安装 Pylance 扩展
- 设置
Pylance
为您的 Python 语言服务器 boto3-stubs[sns]
在您的环境中安装:
python -m pip install 'boto3-stubs[sns]'
类型检查和代码完成现在都应该可以工作了。不需要显式类型注释,boto3
像往常一样编写代码。
PyCharm
boto3-stubs-lite[sns]
在您的环境中安装:
python -m pip install 'boto3-stubs-lite[sns]'`
类型检查和代码完成现在都应该可以工作了。需要显式类型注释。
使用boto3-stubs
包代替隐式类型发现。
Emacs
- 安装
boto3-stubs
您在环境中使用的服务:
python -m pip install 'boto3-stubs[sns]'
- 安装use-package、 lsp、 company和 flycheck包
- 安装lsp-pyright包
(use-package lsp-pyright
:ensure t
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp))) ; or lsp-deferred
:init (when (executable-find "python3")
(setq lsp-pyright-python-executable-cmd "python3"))
)
- 确保 emacs 使用您安装的环境
boto3-stubs
类型检查现在应该可以工作了。不需要显式类型注释,boto3
像往常一样编写代码。
崇高的文本
- 安装
boto3-stubs[sns]
您在环境中使用的服务:
python -m pip install 'boto3-stubs[sns]'
- 安装LSP-pyright包
类型检查现在应该可以工作了。不需要显式类型注释,boto3
像往常一样编写代码。
其他 IDE
未经测试,但只要您的 IDE 支持mypy
or pyright
,一切都应该工作。
我的
- 安装
mypy
:python -m pip install mypy
boto3-stubs[sns]
在您的环境中安装:
python -m pip install 'boto3-stubs[sns]'`
类型检查现在应该可以工作了。不需要显式类型注释,boto3
像往常一样编写代码。
版权
- 安装
pyright
:npm i -g pyright
boto3-stubs[sns]
在您的环境中安装:
python -m pip install 'boto3-stubs[sns]'
或者,您可以安装boto3-stubs
到typings
文件夹。
类型检查现在应该可以工作了。不需要显式类型注释,boto3
像往常一样编写代码。
显式类型注释
客户端注释
SNSClient
为boto3.client("sns")
.
from boto3.session import Session
from mypy_boto3_sns import SNSClient
client: SNSClient = Session().client("sns")
# now client usage is checked by mypy and IDE should provide code completion
分页器注释
mypy_boto3_sns.paginator
模块包含所有分页器的类型注释。
from boto3.session import Session
from mypy_boto3_sns import SNSClient
from mypy_boto3_sns.paginator import (
ListEndpointsByPlatformApplicationPaginator,
ListOriginationNumbersPaginator,
ListPhoneNumbersOptedOutPaginator,
ListPlatformApplicationsPaginator,
ListSMSSandboxPhoneNumbersPaginator,
ListSubscriptionsPaginator,
ListSubscriptionsByTopicPaginator,
ListTopicsPaginator,
)
client: SNSClient = Session().client("sns")
# Explicit type annotations are optional here
# Types should be correctly discovered by mypy and IDEs
list_endpoints_by_platform_application_paginator: ListEndpointsByPlatformApplicationPaginator = (
client.get_paginator("list_endpoints_by_platform_application")
)
list_origination_numbers_paginator: ListOriginationNumbersPaginator = client.get_paginator(
"list_origination_numbers"
)
list_phone_numbers_opted_out_paginator: ListPhoneNumbersOptedOutPaginator = client.get_paginator(
"list_phone_numbers_opted_out"
)
list_platform_applications_paginator: ListPlatformApplicationsPaginator = client.get_paginator(
"list_platform_applications"
)
list_sms_sandbox_phone_numbers_paginator: ListSMSSandboxPhoneNumbersPaginator = (
client.get_paginator("list_sms_sandbox_phone_numbers")
)
list_subscriptions_paginator: ListSubscriptionsPaginator = client.get_paginator(
"list_subscriptions"
)
list_subscriptions_by_topic_paginator: ListSubscriptionsByTopicPaginator = client.get_paginator(
"list_subscriptions_by_topic"
)
list_topics_paginator: ListTopicsPaginator = client.get_paginator("list_topics")
服务资源注释
SNSServiceResource
为boto3.resource("sns")
.
from boto3.session import Session
from mypy_boto3_sns import SNSServiceResource
resource: SNSServiceResource = Session().resource("sns")
# now resource usage is checked by mypy and IDE should provide code completion
其他资源注释
mypy_boto3_sns.service_resource
模块包含所有资源的类型注释。
from boto3.session import Session
from mypy_boto3_sns import SNSServiceResource
from mypy_boto3_sns.service_resource import (
PlatformApplication,
PlatformEndpoint,
Subscription,
Topic,
)
resource: SNSServiceResource = Session().resource("sns")
# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
my_platform_application: PlatformApplication = resource.PlatformApplication(...)
my_platform_endpoint: PlatformEndpoint = resource.PlatformEndpoint(...)
my_subscription: Subscription = resource.Subscription(...)
my_topic: Topic = resource.Topic(...)
集合注释
mypy_boto3_sns.service_resource
模块包含所有
SNSServiceResource
集合的类型注释。
from boto3.session import Session
from mypy_boto3_sns import SNSServiceResource
from mypy_boto3_sns.service_resource import (
ServiceResourcePlatformApplicationsCollection,
ServiceResourceSubscriptionsCollection,
ServiceResourceTopicsCollection,
)
resource: SNSServiceResource = Session().resource("sns")
# Explicit type annotations are optional here
# Type should be correctly discovered by mypy and IDEs
platform_applications: sns_resources.ServiceResourcePlatformApplicationsCollection = (
resource.platform_applications
)
subscriptions: sns_resources.ServiceResourceSubscriptionsCollection = resource.subscriptions
topics: sns_resources.ServiceResourceTopicsCollection = resource.topics
字面量
mypy_boto3_sns.literals
模块包含从形状中提取的文字,可在用户代码中用于类型检查。
from mypy_boto3_sns.literals import (
LanguageCodeStringType,
ListEndpointsByPlatformApplicationPaginatorName,
ListOriginationNumbersPaginatorName,
ListPhoneNumbersOptedOutPaginatorName,
ListPlatformApplicationsPaginatorName,
ListSMSSandboxPhoneNumbersPaginatorName,
ListSubscriptionsByTopicPaginatorName,
ListSubscriptionsPaginatorName,
ListTopicsPaginatorName,
NumberCapabilityType,
RouteTypeType,
SMSSandboxPhoneNumberVerificationStatusType,
SNSServiceName,
ServiceName,
ResourceServiceName,
PaginatorName,
RegionName,
)
def check_value(value: LanguageCodeStringType) -> bool:
...
打字字典
mypy_boto3_sns.type_defs
模块包含组装到类型化字典的结构和形状,以进行额外的类型检查。
from mypy_boto3_sns.type_defs import (
AddPermissionInputRequestTypeDef,
AddPermissionInputTopicAddPermissionTypeDef,
BatchResultErrorEntryTypeDef,
CheckIfPhoneNumberIsOptedOutInputRequestTypeDef,
ResponseMetadataTypeDef,
ConfirmSubscriptionInputRequestTypeDef,
ConfirmSubscriptionInputTopicConfirmSubscriptionTypeDef,
CreatePlatformApplicationInputRequestTypeDef,
CreatePlatformApplicationInputServiceResourceCreatePlatformApplicationTypeDef,
CreatePlatformEndpointInputPlatformApplicationCreatePlatformEndpointTypeDef,
CreatePlatformEndpointInputRequestTypeDef,
CreateSMSSandboxPhoneNumberInputRequestTypeDef,
TagTypeDef,
DeleteEndpointInputRequestTypeDef,
DeletePlatformApplicationInputRequestTypeDef,
DeleteSMSSandboxPhoneNumberInputRequestTypeDef,
DeleteTopicInputRequestTypeDef,
EndpointTypeDef,
GetDataProtectionPolicyInputRequestTypeDef,
GetEndpointAttributesInputRequestTypeDef,
GetPlatformApplicationAttributesInputRequestTypeDef,
GetSMSAttributesInputRequestTypeDef,
GetSubscriptionAttributesInputRequestTypeDef,
GetTopicAttributesInputRequestTypeDef,
PaginatorConfigTypeDef,
ListEndpointsByPlatformApplicationInputRequestTypeDef,
ListOriginationNumbersRequestRequestTypeDef,
PhoneNumberInformationTypeDef,
ListPhoneNumbersOptedOutInputRequestTypeDef,
ListPlatformApplicationsInputRequestTypeDef,
PlatformApplicationTypeDef,
ListSMSSandboxPhoneNumbersInputRequestTypeDef,
SMSSandboxPhoneNumberTypeDef,
ListSubscriptionsByTopicInputRequestTypeDef,
SubscriptionTypeDef,
ListSubscriptionsInputRequestTypeDef,
ListTagsForResourceRequestRequestTypeDef,
ListTopicsInputRequestTypeDef,
TopicTypeDef,
MessageAttributeValueTypeDef,
OptInPhoneNumberInputRequestTypeDef,
PublishBatchResultEntryTypeDef,
PutDataProtectionPolicyInputRequestTypeDef,
RemovePermissionInputRequestTypeDef,
RemovePermissionInputTopicRemovePermissionTypeDef,
ServiceResourcePlatformApplicationRequestTypeDef,
ServiceResourcePlatformEndpointRequestTypeDef,
ServiceResourceSubscriptionRequestTypeDef,
ServiceResourceTopicRequestTypeDef,
SetEndpointAttributesInputPlatformEndpointSetAttributesTypeDef,
SetEndpointAttributesInputRequestTypeDef,
SetPlatformApplicationAttributesInputPlatformApplicationSetAttributesTypeDef,
SetPlatformApplicationAttributesInputRequestTypeDef,
SetSMSAttributesInputRequestTypeDef,
SetSubscriptionAttributesInputRequestTypeDef,
SetSubscriptionAttributesInputSubscriptionSetAttributesTypeDef,
SetTopicAttributesInputRequestTypeDef,
SetTopicAttributesInputTopicSetAttributesTypeDef,
SubscribeInputRequestTypeDef,
SubscribeInputTopicSubscribeTypeDef,
UnsubscribeInputRequestTypeDef,
UntagResourceRequestRequestTypeDef,
VerifySMSSandboxPhoneNumberInputRequestTypeDef,
CheckIfPhoneNumberIsOptedOutResponseTypeDef,
ConfirmSubscriptionResponseTypeDef,
CreateEndpointResponseTypeDef,
CreatePlatformApplicationResponseTypeDef,
CreateTopicResponseTypeDef,
EmptyResponseMetadataTypeDef,
GetDataProtectionPolicyResponseTypeDef,
GetEndpointAttributesResponseTypeDef,
GetPlatformApplicationAttributesResponseTypeDef,
GetSMSAttributesResponseTypeDef,
GetSMSSandboxAccountStatusResultTypeDef,
GetSubscriptionAttributesResponseTypeDef,
GetTopicAttributesResponseTypeDef,
ListPhoneNumbersOptedOutResponseTypeDef,
PublishResponseTypeDef,
SubscribeResponseTypeDef,
CreateTopicInputRequestTypeDef,
CreateTopicInputServiceResourceCreateTopicTypeDef,
ListTagsForResourceResponseTypeDef,
TagResourceRequestRequestTypeDef,
ListEndpointsByPlatformApplicationResponseTypeDef,
ListEndpointsByPlatformApplicationInputListEndpointsByPlatformApplicationPaginateTypeDef,
ListOriginationNumbersRequestListOriginationNumbersPaginateTypeDef,
ListPhoneNumbersOptedOutInputListPhoneNumbersOptedOutPaginateTypeDef,
ListPlatformApplicationsInputListPlatformApplicationsPaginateTypeDef,
ListSMSSandboxPhoneNumbersInputListSMSSandboxPhoneNumbersPaginateTypeDef,
ListSubscriptionsByTopicInputListSubscriptionsByTopicPaginateTypeDef,
ListSubscriptionsInputListSubscriptionsPaginateTypeDef,
ListTopicsInputListTopicsPaginateTypeDef,
ListOriginationNumbersResultTypeDef,
ListPlatformApplicationsResponseTypeDef,
ListSMSSandboxPhoneNumbersResultTypeDef,
ListSubscriptionsByTopicResponseTypeDef,
ListSubscriptionsResponseTypeDef,
ListTopicsResponseTypeDef,
PublishBatchRequestEntryTypeDef,
PublishInputPlatformEndpointPublishTypeDef,
PublishInputRequestTypeDef,
PublishInputTopicPublishTypeDef,
PublishBatchResponseTypeDef,
PublishBatchInputRequestTypeDef,
)
def get_structure() -> AddPermissionInputRequestTypeDef:
return {...}
这个怎么运作
全自动
的mypy-boto3-builder为每个服务仔细生成类型注解,耐心等待boto3
更新。它为您提供插入式注释,并确保:
- 涵盖所有可用
boto3
服务。 - 每个
boto3
服务的每个公共类和方法都会从文档中提取有效的类型注释(botocore
如果类型不正确,请归咎于文档)。 - 类型注释包括最新的文档。
- 每种方法都提供了文档链接。
- 为了可读性,代码由black和 isort处理。
什么是新的
实现的功能
- 全类型注释
boto3
和botocore
库aiobotocore
mypy
,pyright
,VSCode
,PyCharm
,Sublime Text
和Emacs
兼容性Client
,ServiceResource
,Resource
,Waiter
Paginator
为每个服务键入注释TypeDefs
为每个服务生成Literals
为每个服务生成- 自动发现类型
boto3.client
和boto3.session
调用 - 自动发现类型
session.client
和session.session
调用 - 自动发现类型
client.get_waiter
和client.get_paginator
调用 - 自动发现类型
ServiceResource
和Resource
集合 - 自动发现
aiobotocore.Session.create_client
呼叫类型
最新变化
生成器更改日志可以在 Releases中找到。
版本控制
mypy-boto3-sns
版本与相关boto3
版本相同,遵循
PEP 440格式。
谢谢
- Allie Fitter for boto3-type-annotations,这个包是基于他的工作
- 一个很棒的格式化工具的黑人开发者
- 蒂莫西·埃德蒙·克罗斯利 (Timothy Edmund Crosley ) 的 isort及其灵活度
- mypy开发人员为我们做了所有肮脏的工作
- pyright团队为类型化 Python 的新时代
文档
所有服务类型注释都可以在 boto3 文档中找到
支持和贡献
这个包是自动生成的。请在mypy-boto3-builder存储库中报告任何错误或请求新功能 。