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

Uploaded Source

Built Distribution

phantom_types-0.12.0-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phantom-types-0.12.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 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.12.0.tar.gz
Algorithm Hash digest
SHA256 9c76f3884542d3a69dafb9a2ee551d9e7719f7250fcfcf2c2844ebcaaa8ac27e
MD5 74baf0a3d7d55dd5cca6e48e19645fd2
BLAKE2b-256 d76bd4472b401f076a7dc9d53f0b207f45f704cc305e1094e20acacf61ec7c78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phantom_types-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 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.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e675d048ea92de21711d14e1d2f1ca76438c265379cad2272b3b099e166697e0
MD5 e5203951cc7642fb6753feab836f26af
BLAKE2b-256 b364dc4a9b625059b04c02c5725310459aa79f77f445adb0a1df9befb3602486

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