{"id":1616,"library":"parse-type","title":"Parse-Type","description":"Parse-Type is a Python library that simplifies the creation of custom type definitions for the `parse` module. It extends `parse`'s capabilities by allowing users to easily integrate enums, regular expressions, and custom functions as parsable types. The current version is 0.6.6. Releases are primarily driven by updates to the underlying `parse` module and general maintenance, leading to an irregular but consistent cadence.","status":"active","version":"0.6.6","language":"en","source_language":"en","source_url":"https://github.com/jenisys/parse_type","tags":["parsing","types","parse","regex","pattern-matching"],"install":[{"cmd":"pip install parse-type","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"TypeBuilder is the main entry point for creating custom types, not directly from the embedded 'parse' module.","wrong":"from parse_type.parse import TypeBuilder","symbol":"TypeBuilder","correct":"from parse_type import TypeBuilder"},{"note":"While parse-type embeds its own parse module, the standard way to import the parse function is from the top-level 'parse' package. If parse-type is your only parse provider, this will typically resolve to its embedded version.","wrong":"import parse_type.parse","symbol":"parse","correct":"from parse import parse"}],"quickstart":{"code":"from enum import Enum\nfrom parse import parse\nfrom parse_type import TypeBuilder\n\n# 1. Define an Enum to be used as a custom type\nclass ColorEnum(Enum):\n    red = 1\n    green = 2\n    blue = 3\n\n# 2. Create a TypeBuilder instance, integrating the Enum\n#    TypeBuilder can also create types from regex or functions.\nparse_types = TypeBuilder.with_enum(ColorEnum)\n\n# 3. Define a parse pattern using the custom type\npattern = \"The color is {color:Color}\"\ntext = \"The color is blue\"\n\n# 4. Use the parse function, passing the custom type definitions\n#    The key 'Color' in the dict corresponds to the type name in the pattern.\nresult = parse(pattern, text, dict(Color=parse_types.Color))\n\nif result:\n    print(f\"Successfully parsed! Color: {result['color']}\")\n    print(f\"Type of parsed color: {type(result['color'])}\")\n    assert result['color'] is ColorEnum.blue\n    print(\"Assertion successful: Parsed value matches Enum member.\")\nelse:\n    print(\"Parsing failed.\")","lang":"python","description":"This quickstart demonstrates how to define a custom type using an Enum and integrate it into a `parse` pattern. It uses `TypeBuilder.with_enum` to prepare the custom type, then passes it to the `parse` function."},"warnings":[{"fix":"Be aware that `parse-type` internally manages its `parse` dependency. It's generally safest to rely on `parse-type`'s embedded version or explicitly import `parse_type.parse` if you need to guarantee which `parse` implementation you are using in specific scenarios. Keep `parse-type` updated to get the latest compatible `parse` module behavior.","message":"The `parse-type` library embeds its own copy of the `parse` module (e.g., `parse_type.parse`). This can lead to confusion or potential version conflicts if you also have the `parse` library installed externally from PyPI. While `parse-type` aims for compatibility, explicit imports of `parse` might pick up the external version instead of the embedded one.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure you are using `parse-type` with a modern, actively supported version of Python 3 (e.g., Python 3.8+).","message":"Although `parse-type` specifies Python 2.7 support in its `requires_python` metadata, Python 2.7 is end-of-life and no longer receives security updates. Using `parse-type` with Python 2.7 is strongly discouraged.","severity":"deprecated","affected_versions":"All versions supporting Python 2.7"},{"fix":"Always use the latest stable version of `parse-type` to ensure you benefit from the most up-to-date and stable `parse` module behavior that the library bundles and is tested against.","message":"Releases of `parse-type` have included fixes related to upstream behavior changes in the `parse` module (e.g., `parse v1.19.1` breaking some behavior). This highlights that the interaction with `parse` can be subtle.","severity":"gotcha","affected_versions":"<0.6.3"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}