Skip to main content

Fits JSON values into Python type-anotated objects

Project description

TypeFit

Read the Docs Build Status LGTM Grade

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

Uploaded Source

Built Distribution

typefit-0.4.1-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typefit-0.4.1.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.10.0-11-amd64

File hashes

Hashes for typefit-0.4.1.tar.gz
Algorithm Hash digest
SHA256 d009f51ad611efd22b3211987b374e5a2f4d8287a789ccecf4fa09c6b1f8bf2b
MD5 7afa931c268a0bcf3fe6fd884bf61b19
BLAKE2b-256 167f029a3bff19626930977ce78009f4f0b3ffbd259070dd78346d721bd67d43

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typefit-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.10.0-11-amd64

File hashes

Hashes for typefit-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 524c1f237a49f9459442ecd59796dbf63531c84844bfbd2c1f2375bf71712ca5
MD5 01feb1b2c15b72a86c28721e65a92fb6
BLAKE2b-256 0aff9ba9773babc61942bed033652916755966c4fd61f14e90d19e3eee543a18

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