# Examples

> [Index](../README.md) > [{{ service_name.class_name }}](./README.md) > Examples

{% include "common/header_note.md.jinja2" with context %}

## Client

### Implicit type annotations

Can be used with `{{ package.data.pypi_name }}[{{ package.service_name.extras_name }}]` package installed.

Write your `{{ package.service_name.class_name }}` code as usual,
type checking and code completion should work out of the box.

{% set method = package.client.get_example_method() -%}
{% if method %}
```python
# {{ package.client.name }} usage example

from {{ package.library_name }}.session import Session


session = Session()

client = session.client("{{ package.service_name.boto3_name }}")  # (1)
result = client.{{ method.name }}()  # (2)
```

1. client: [{{ package.client.name }}]({{ get_md_doc_link('client') }})
2. result: {% with type_annotation=method.return_type %}{% include "common/type_hint.md.jinja2" with context -%}{% endwith %}
{% endif %}

{% set paginator = package.paginators[0] if package.paginators else None -%}
{% if paginator %}
```python
# {{ paginator.name }} usage example

from {{ package.library_name }}.session import Session


session = Session()
client = session.client("{{ package.service_name.boto3_name }}")  # (1)

paginator = client.get_paginator("{{ paginator.operation_name }}")  # (2)
for item in paginator.paginate(...):
    print(item)  # (3)
```

1. client: [{{ package.client.name }}]({{ get_md_doc_link('client') }})
2. paginator: [{{ paginator.name }}]({{ get_md_doc_link('paginators', paginator.name) }})
3. item: {% with type_annotation=paginator.methods[0].return_type.children[0] %}{% include "common/type_hint.md.jinja2" with context -%}{% endwith %}
{% endif %}

{% set waiter = package.waiters[0] if package.waiters else None -%}
{% if waiter %}
```python
# {{ waiter.name }} usage example

from {{ package.library_name }}.session import Session


session = Session()
client = session.client("{{ package.service_name.boto3_name }}")  # (1)

waiter = client.get_waiter("{{ waiter.attribute_name }}")  # (2)
waiter.wait()
```

1. client: [{{ package.client.name }}]({{ get_md_doc_link('client') }})
2. waiter: [{{ waiter.name }}]({{ get_md_doc_link('waiters', waiter.name) }})
{% endif %}

### Explicit type annotations

With `{{ package.data.pypi_lite_name }}[{{ package.service_name.extras_name }}]`
or a standalone `{{ package.name }}` package, you have to explicitly specify `client: {{ package.client.name }}` 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.

{% if method %}
```python
# {{ package.client.name }} usage example with type annotations

from {{ package.library_name }}.session import Session

from {{ package.name }}.client import {{ package.client.name }}
from {{ package.name }}.type_defs import {{ method.return_type.name }}
from {{ package.name }}.type_defs import {{ method.request_type_annotation.name }}


session = Session()

client: {{ package.client.name }} = session.client("{{ package.service_name.boto3_name }}")

kwargs: {{ method.request_type_annotation.name }} = {...}
result: {{ method.return_type.name }} = client.{{ method.name }}(**kwargs)
```
{% endif %}

{% if paginator %}
```python
# {{ paginator.name }} usage example with type annotations

from {{ package.library_name }}.session import Session

from {{ package.name }}.client import {{ package.client.name }}
from {{ package.name }}.paginator import {{ paginator.name }}
from {{ package.name }}.type_defs import {{ paginator.methods[0].return_type.children[0].name }}


session = Session()
client: {{ package.client.name }} = session.client("{{ package.service_name.boto3_name }}")

paginator: {{ paginator.name }} = client.get_paginator("{{ paginator.operation_name }}")
for item in paginator.paginate(...):
    item: {{ paginator.methods[0].return_type.children[0].name }}
    print(item)
```
{% endif %}

{% if waiter %}
```python
# {{ waiter.name }} usage example with type annotations

from {{ package.library_name }}.session import Session

from {{ package.name }}.client import {{ package.client.name }}
from {{ package.name }}.waiter import {{ waiter.name }}

session = Session()
client: {{ package.client.name }} = session.client("{{ package.service_name.boto3_name }}")

waiter: {{ waiter.name }} = client.get_waiter("{{ waiter.attribute_name }}")
waiter.wait()
```
{% endif %}

{% if package.service_resource %}
## Service Resource

### Implicit type annotations

Can be used with `{{ package.data.pypi_name }}[{{ package.service_name.extras_name }}]` package installed.

{% set method = package.service_resource.methods[0] if package.service_resource.methods else None -%}
{% set collection = package.service_resource.collections[0] if package.service_resource.collections else None -%}


{% if method %}
```python
# {{ package.service_resource.name }} usage example

from {{ package.library_name }}.session import Session


session = Session()

resource = session.resource("{{ package.service_name.boto3_name }}")  # (1)
result = resource.{{ method.name }}()  # (2)
```

1. resource: [{{ package.service_resource.name }}]({{ get_md_doc_link('service_resource') }})
2. result: {% with type_annotation=method.return_type %}{% include "common/type_hint.md.jinja2" with context -%}{% endwith %}
{% endif %}

{% if collection %}
```python
# {{ collection.name }} usage example

from {{ package.library_name }}.session import Session


session = Session()
resource = session.resource("{{ package.service_name.boto3_name }}")  # (1)

collection = resource.{{ collection.attribute_name }}  # (2)
for item in collection:
    print(item)  # (3)
```

1. resource: [{{ package.service_resource.name }}]({{ get_md_doc_link('service_resource') }})
2. collection: [{{ package.service_resource.name }}]({{ get_md_doc_link('service_resource', collection.name) }})
3. item: {{ collection.object_class_name }}
{% endif %}

### Explicit type annotations

With `{{ package.data.pypi_lite_name }}[{{ package.service_name.extras_name }}]`
or a standalone `{{ package.name }}` package, you have to explicitly specify
`resource: {{ package.service_resource.name }}` 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.


{% if method %}
```python
# {{ package.service_resource.name }} usage example with type annotations

from {{ package.library_name }}.session import Session

from {{ package.name }}.service_resource import {{ package.service_resource.name }}
from {{ package.name }}.service_resource import {{ method.name }}


session = Session()

resource: {{ package.service_resource.name }} = session.resource("{{ package.service_name.boto3_name }}")
result: {{ method.name }} = resource.{{ method.name }}()
```
{% endif %}

{% if collection %}
```python
# {{ collection.name }} usage example with type annotations

from {{ package.library_name }}.session import Session

from {{ package.name }}.service_resource import {{ package.service_resource.name }}
from {{ package.name }}.service_resource import {{ collection.name }}
from {{ package.name }}.service_resource import {{ collection.object_class_name }}


session = Session()

resource: {{ package.service_resource.name }} = session.resource("{{ package.service_name.boto3_name }}")

collection: {{ collection.name }} = resource.{{ collection.attribute_name }}
for item in collection:
    item: {{ collection.object_class_name }}
    print(item)
```
{% endif %}
{% endif %}
