Skip to main content

Falcon typing

PyPI - Python Version PyPI codecov Build Status License: MIT

Use type hints to specify request parameters with Marshmallow and Pydantic support.

**Uses typedjson

Example

"""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

Metadata

Release files for falcontyping 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for falcontyping 0.7.0
File Size Uploaded
falcontyping-0.7.0.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for falcontyping 0.7.0
File Interpreter ABI Platform
falcontyping-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.4 kB

Release files / falcontyping-0.7.0.tar.gz

Download URL falcontyping-0.7.0.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ae81c0b3f67651dabefff99e3e438d433a383480c5b0051190aa19be4e201212
BLAKE2b-256 checksum
How to use checksums
0fe47e394d243b3f64bc836a4f43c8bab25fb3a37765cc68fc6901a322391446
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release files / falcontyping-0.7.0-py3-none-any.whl

Download URL falcontyping-0.7.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
152b7794e2091e5560a0b4db4957af17ec9610dd6c96a8698cdd3e75248f4154
BLAKE2b-256 checksum
How to use checksums
f3541e9b8fc69928b227342ace7cee703b2f9ee5a866edb00f5d5a7c7d37b198
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page