Metadata-Version: 2.1
Name: falcontyping
Version: 0.3.3
Summary: Add type hints support to Falcon with Pydantic and Marshmallow integration
Home-page: https://github.com/abdelrahman-t/falcontyping
Author: Abdurrahman Talaat <abdurrahman.talaat@gmail.com>
Author-email: abdurrahman.talaat@gmail.com
License: UNKNOWN
Project-URL: Documentation, https://github.com/abdelrahman-t/falcontyping
Keywords: falcon,typing,hints,mypy,pydantic,marshmallow
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3.7
Requires-Python: >=3.7.0
Description-Content-Type: text/markdown
Requires-Dist: falcon
Requires-Dist: wrapt

# Falcon typing

![PyPI - Python Version](https://img.shields.io/pypi/pyversions/falcontyping)
![PyPI](https://img.shields.io/pypi/v/falcontyping)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

### Use type hints to specify request parameters with Marshmallow and Pydantic support.
**Uses [typedjson](https://github.com/mitsuse/typedjson-python)

### Example
```python
"""API."""
from typing import Optional, Union

from pydantic import BaseModel as PydanticModel
from falcontyping import TypedAPI, TypedResource


class UserV1(PydanticModel):

    username: str

class UserV2(PydanticModel):

    username: str
    balance: float


class UsersResource(TypedResource):

    def on_post(self, request, response, user: Union[UserV2, UserV1]) -> Union[UserV2, UserV1]:
        if isinstance(user, UserV2):
            return UserV2(username=user.username, balance=user.balance)

        else:
            return UserV1(username=user.username)

class UserDetailsResource(TypedResource):

    def on_get(self, request, response, user_id: int) -> Optional[Union[UserV2, UserV1]]:
        if user_id == 2:
            return UserV2(username='user', balance=0.0)

        if user_id == 1:
            return UserV1(username='user')

        return None

API = TypedAPI()
API.add_route('/users', UserResource())
API.add_route('/users/{user_id}', UserDetailsResource())
```

### How to install
`pip install falcontyping`


