semvec/pypi-packages huggingface dataset:
aiohttp-utils 3.2.1
Handy utilities for aiohttp.web applications.
License: MIT
Keywords: aiohttp_utils aiohttp utilities aiohttp.web

*************
aiohttp-utils
*************

.. image:: https://badgen.net/pypi/v/aiohttp-utils
    :target: https://pypi.org/project/aiohttp-utils/
    :alt: Latest version

.. image:: https://badgen.net/travis/sloria/aiohttp-utils
    :target: https://travis-ci.org/sloria/aiohttp-utils
    :alt: Travis-CI

**aiohttp-utils** provides handy utilities for building `aiohttp.web <https://aiohttp.readthedocs.io/>`_ applications.


* Method-based handlers ("resources")
* Routing utilities
* Content negotiation with JSON rendering by default

**Everything is optional**. You can use as much (or as little) of this toolkit as you need.

.. code-block:: python

    from aiohttp import web
    from aiohttp_utils import Response, routing, negotiation

    app = web.Application(router=routing.ResourceRouter())

    # Method-based handlers
    class HelloResource:

        async def get(self, request):
            name = request.GET.get('name', 'World')
            return Response({
                'message': 'Hello ' + name
            })


    app.router.add_resource_object('/', HelloResource())

    # Content negotiation
    negotiation.setup(
        app, renderers={
            'application/json': negotiation.render_json
        }
    )

Install
=======
::

    $ pip install aiohttp-utils

Documentation
=============

Full documentation is available at https://aiohttp-utils.readthedocs.io/.

Project Links
=============

- Docs: https://aiohttp-utils.readthedocs.io/
- Changelog: https://aiohttp-utils.readthedocs.io/en/latest/changelog.html
- PyPI: https://pypi.python.org/pypi/aiohttp-utils
- Issues: https://github.com/sloria/aiohttp-utils/issues

License
=======

MIT licensed. See the bundled `LICENSE <https://github.com/sloria/aiohttp-utils/blob/master/LICENSE>`_ file for more details.
typediterable 0.0.1
A Simple python package to apply typing to iterables.
License: MIT

# typediterable

`typediterable` is a simple python package for the actual typing of each element of an iterable with type hint notation.

## Install

```
pip install git+ssh://git@github.com/osoken/typediterable.git
```

## Features and Examples

### Actual Typing with Type Hint Notation

The following example shows how the main component `typediterable.TypedIterable` works:

```py
from dataclasses import dataclass
from typediterable import TypedIterable

@dataclass
class User:
    id: int
    name: str

raw_data = [{"id": 0, "name": "Alice"}, {"id": 1, "name": "Bob"}]
for d in TypedIterable[User](raw_data):
    assert isinstance(d, User)
```

It is equivalent to write:

```py
from dataclasses import dataclass
from typediterable import TypedIterable

@dataclass
class User:
    id: int
    name: str

raw_data = [{"id": 0, "name": "Alice"}, {"id": 1, "name": "Bob"}]
for d in (User(**d) for d in raw_data):
    assert isinstance(d, User)
```

### Error Handling

`typediterable.TypedIterable` also has the error handling feature.

```py
from dataclasses import dataclass
from typediterable import TypedIterable
from collections.abc import Mapping
from typing import Union

@dataclass
class User:
    id: int
    name: str

def error_handler(d: Mapping[str, Union[int, str]], i: int, e: Exception) -> None:
    print(f"{i}th element `{d}` is invalid due to the following error: {e}")

raw_data = [{"id": 0, "name": "Alice"}, {"name": "lack of id"}, {"id": 1, "name": "Bob"}]
for d in TypedIterable[User](raw_data, on_error=error_handler):
    assert isinstance(d, User)
```

The above example prints the following string:

```
1th element `{'name': 'lack of id'}` is invalid due to the following error: User.__init__() missing 1 required positional argument: 'id'
```

and it doesn't stop iterating.
The example is equivalent to write:

```py
from dataclasses import dataclass
from typediterable import TypedIterable
from collections.abc import Mapping
from typing import Union

@dataclass
class User:
    id: int
    name: str

raw_data = [{"id": 0, "name": "Alice"}, {"name": "lack of id"}, {"id": 1, "name": "Bob"}]
for i, raw_d in enumerate(raw_data):
    try:
        d = User(**raw_d)
    except Exception as e:
        print(f"{i}th element `{raw_d}` is invalid due to the following error: {e}")
    assert isinstance(d, User)
```

### Automatic Unpacking Arguments

`typediterable.TypedIterable` checks the signature and automatically unpacks the arguments.
For functions which takes multiple positional arguments or multiple keyword arguments, such as `dataclass` and `pydantic.BaseModel`, it unpacks just like the above example.
If the function is single-argument, no unpacking is done.

```py
from typediterable import TypedIterable

raw_data = ["1", "2", "3", "4"]
for d in TypedIterable[int](raw_data):
    assert isinstance(d, int)
```