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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: phantom-types-0.13.0.tar.gz
  • Upload date:
  • Size: 17.7 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.13.0.tar.gz
Algorithm Hash digest
SHA256 b3240f8200128208854a68d3cb707aeb1901dd5044b9f562c39003b93296c9c4
MD5 05bb5ebdbf75e9d849065bf7bd93a326
BLAKE2b-256 02a8e40ffc3f2f6bb1345230ecf490561ee3029245f9f5e3e1c36b800b812259

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phantom_types-0.13.0-py3-none-any.whl
  • Upload date:
  • Size: 22.2 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.13.0-py3-none-any.whl
Algorithm Hash digest
SHA256 abbc6b7bbbc0b3ec3206a44dcb3fcbe605aa41dd81bbbfbd42a0f9e94d44725f
MD5 5184b4d8b07949e70c8b383a86e69006
BLAKE2b-256 c60886f4fc9143866bd0def0718b29054d6b8def664e566a9dba47e7d283b93c

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