Skip to content

Examples#

Index > Lightsail > Examples

Auto-generated documentation for Lightsail type annotations stubs module mypy-boto3-lightsail.

Client#

Implicit type annotations#

Can be used with boto3-stubs[lightsail] package installed.

Write your Lightsail code as usual, type checking and code completion should work out of the box.

Client method usage example#

# LightsailClient usage example

from boto3.session import Session


session = Session()

client = session.client("lightsail")  # (1)
result = client.allocate_static_ip()  # (2)
  1. client: LightsailClient
  2. result: AllocateStaticIpResultTypeDef

Paginator usage example#

# GetActiveNamesPaginator usage example

from boto3.session import Session


session = Session()
client = session.client("lightsail")  # (1)

paginator = client.get_paginator("get_active_names")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
  1. client: LightsailClient
  2. paginator: GetActiveNamesPaginator
  3. item: GetActiveNamesResultTypeDef

Explicit type annotations#

With boto3-stubs-lite[lightsail] or a standalone mypy_boto3_lightsail package, you have to explicitly specify client: LightsailClient type annotation.

All other type annotations are optional, as types should be discovered automatically. However, these type annotations can be helpful in your functions and methods.

Client method usage example#

# LightsailClient usage example with type annotations

from boto3.session import Session

from mypy_boto3_lightsail.client import LightsailClient
from mypy_boto3_lightsail.type_defs import AllocateStaticIpResultTypeDef
from mypy_boto3_lightsail.type_defs import AllocateStaticIpRequestTypeDef


session = Session()

client: LightsailClient = session.client("lightsail")

kwargs: AllocateStaticIpRequestTypeDef = {...}
result: AllocateStaticIpResultTypeDef = client.allocate_static_ip(**kwargs)

Paginator usage example#

# GetActiveNamesPaginator usage example with type annotations

from boto3.session import Session

from mypy_boto3_lightsail.client import LightsailClient
from mypy_boto3_lightsail.paginator import GetActiveNamesPaginator
from mypy_boto3_lightsail.type_defs import GetActiveNamesResultTypeDef


session = Session()
client: LightsailClient = session.client("lightsail")

paginator: GetActiveNamesPaginator = client.get_paginator("get_active_names")
for item in paginator.paginate(...):
    item: GetActiveNamesResultTypeDef
    print(item)