Skip to main content

Phantom types for Python

Project description

Depiction of phantom types in the wild

phantom-types

CI Build Status Documentation Build Status Test coverage report

Phantom types for Python will help you make illegal states unrepresentable and avoid shotgun parsing by enabling you to practice "Parse, don't validate".

This project is in early development and fundamental changes should be expected. Semantic versioning will be followed after version 1.0, but before that breaking changes might occur between minor versions.

Checkout the complete documentation on Read the Docs →

Installation

$  python3 -m pip install phantom-types

Example

from phantom import Phantom
from phantom.predicates.collection import contained


class Name(str, Phantom, predicate=contained({"Jane", "Joe"})):
    ...


def greet(name: Name):
    print(f"Hello {name}!")


# This is valid.
greet(Name.parse("Jane"))

# And so is this.
joe = "Joe"
assert isinstance(joe, Name)
greet(joe)

# But this will yield a static type checking error.
greet("bird")

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

phantom-types-0.13.1.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

phantom_types-0.13.1-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

Details for the file phantom-types-0.13.1.tar.gz.

File metadata

  • Download URL: phantom-types-0.13.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for phantom-types-0.13.1.tar.gz
Algorithm Hash digest
SHA256 aea13e36d0439cf5c1250b0cd94bafb1c9f45eda09e743fa5f702bd0196d5ea4
MD5 1e34cacb7716ee37ca3067bacf94f766
BLAKE2b-256 a70a4322f752671996a4425d4e4edcbf67b44a2fb374d58bd686897c7d6a982b

See more details on using hashes here.

File details

Details for the file phantom_types-0.13.1-py3-none-any.whl.

File metadata

  • Download URL: phantom_types-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 22.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for phantom_types-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 03f3865b550943b70c63d9c4aa63b2d9dea124918fd9061058e3aa91f8279cb8
MD5 d70e3003e7f44957f8c954bd47e2353c
BLAKE2b-256 7f48033106a5868a30438fc84332f2bff881f3bcf2afda31ab85fb7b228308d5

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