Skip to main content

Phantom types for Python

Project description

phantom-types

CI

Phantom types for Python that will help you make illegal states unrepresentable and avoid shotgun parsing by practicing "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.9.1.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

phantom_types-0.9.1-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: phantom-types-0.9.1.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for phantom-types-0.9.1.tar.gz
Algorithm Hash digest
SHA256 83834b29d0b0ed18ce2b69830fad204b9479ebadc75e7ac4c7d33011e3b8d768
MD5 efd7fb0a559fdb9f5d8697f88474d851
BLAKE2b-256 518877c52210755a3c80a900f84bc2b949cb800eca5b2bb5d5bf3a347842a928

See more details on using hashes here.

File details

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

File metadata

  • Download URL: phantom_types-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 33.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for phantom_types-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9cc01385d8b027cac6df84f328dab84eea82f265f6e598f04fe3e9ff29d364da
MD5 04325d7ecfeb0954fe8f12f01e87fa54
BLAKE2b-256 67cea47a7aef61308d10848e1c7ea8d170974db78346073c31243136906376ce

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