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.4.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

typefit-0.5.4-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file typefit-0.5.4.tar.gz.

File metadata

  • Download URL: typefit-0.5.4.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

File hashes

Hashes for typefit-0.5.4.tar.gz
Algorithm Hash digest
SHA256 31708fd042ade5931c61af3e136a0abb6d5e0325ba3d4ad8e10be84b23943790
MD5 a1dd7d096207d98a7f79dc2647103966
BLAKE2b-256 f8967af6b96f6ab1cd4aa0c2062453e448f5b6926acfe37048c577c4788c5133

See more details on using hashes here.

File details

Details for the file typefit-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: typefit-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 26.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.0 Linux/5.15.0-1041-azure

File hashes

Hashes for typefit-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 748f08663af38e66298955a7bb6025c1095beb594ee5171619c684a4c1487b15
MD5 6427fd0acf0dfa6a953d88853b69b335
BLAKE2b-256 3f4e01b081760c7cd835bad7e71fea5e042b8e532d6388164cb0299ed24b864b

See more details on using hashes here.

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