Skip to main content

Phantom types for Python

Project description

Depiction of phantom types in the wild


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 →


$  python3 -m pip install phantom-types


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.

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

# But this will yield a static type checking error.

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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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