Skip to main content

Fits JSON values into Python type-anotated objects

Project description

TypeFit

Read the Docs Build Status

Typing annotations make Python awesome, however it's complicated to keep your data annotated when it comes from external sources like APIs. The goal of Typefit is to help you map that external data into type-annotated native Python objects.

from typefit import api
from typing import NamedTuple, Text


class Item(NamedTuple):
    id: int
    title: Text


class HackerNews(api.SyncClient):
    BASE_URL = "https://hacker-news.firebaseio.com/v0/"

    @api.get("item/{item_id}.json")
    def get_item(self, item_id: int) -> Item:
        pass

story = HackerNews().get_item(42)
print(story.title)
# An alternative to VC: "Selling In"

This is the full example of a Hacker News API client. Its functionality is limited but in 14 lines counting white space you can build a type-safe client for Hacker News. You'll find a full example attached if you're interested.

Documentation

Documentation is there

Licence

This library is provided under the terms of the WTFPL.

If you find it useful, you can have a look at the contributors page to know who helped.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typefit-0.5.5.tar.gz (23.0 kB view hashes)

Uploaded Source

Built Distribution

typefit-0.5.5-py3-none-any.whl (26.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page