{"categories":[{"label":"Quality Assurance","url":"https://skillfed.io/packages/category/software-development-quality-assurance/4"}],"enrichment":{"capability":"Phantom types enable you to create type-safe wrappers around base types (like strings or integers) with runtime predicates, allowing static type checkers and runtime validators to enforce constraints without shotgun parsing.","skillfed_tags":["type-safety","validation","pydantic-compatible"],"use_cases":["Enforce string constraints (e.g., non-empty, from a fixed set) at the type level so functions can assume preconditions without defensive checks.","Combine with pydantic models to validate and document API request/response schemas with phantom type predicates.","Use with beartype or typeguard to add runtime pre- and post-condition checking to functions without explicit guard clauses.","Parse and validate user input once at the boundary, then pass phantom-typed values through your codebase with static proof of validity.","Generate JSONSchema from pydantic models that include phantom types, automatically documenting constraints in API specs."],"what_it_does":"Phantom types let you attach runtime predicates to Python types so that illegal states become unrepresentable at both the type-checking and runtime levels. Instead of validating data after parsing (shotgun parsing), you create a phantom type\u2014a subclass of a base type like `str` with a predicate\u2014and parse data into that type upfront. The type checker then treats the result as proven to satisfy the predicate, and runtime validators like typeguard or beartype can enforce the same constraint at call boundaries.\n\nThe package integrates with pydantic for schema generation and validation, works with static type checkers like mypy, and supports optional extras for datetime, phone number, and hypothesis-based testing. It requires Python 3.9+ and depends on typeguard, typing-extensions, and numerary at runtime.","worth_installing":"Yes, if you want to move validation earlier in your pipeline and leverage static type checking to prevent invalid states. The package is stable (Production/Stable classifier), has low install friction, and works well with pydantic and runtime type checkers. The 656-day gap since last release is a minor concern for long-term maintenance, but the repository remains active and there are no known vulnerabilities. Install it if your codebase values type safety and parse-don't-validate patterns."},"id":"phantom-types","links":{"html":"https://skillfed.io/packages/phantom-types","md":"https://skillfed.io/packages/phantom-types.md","pypi":"https://pypi.org/project/phantom-types/"},"maintenance":{"status":"aging"},"meta":{"latest_release":"2024-10-27","license_spdx":null,"license_treatment":"permissive","name":"phantom-types","python_support":"supports_current","summary":"Phantom types for Python"},"popularity":{"monthly_downloads":79453,"position":14356,"tier":"top_15000"},"security":{"n_vulnerabilities":0},"version":"3.0.2"}
