Registry / serialization / parse-type

parse-type

JSON →
library0.6.6pypypi✓ verified 25d ago

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.

pip install parse-type
INSTALL
IMPORT
SIG · PARSE-TYPE
P
parse-type
serializationpythonv0.6.6
Install
1.7s avg
Import
26ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 18.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.026s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TypeBuilder
from parse_type import TypeBuilder
from parse_type.parse import TypeBuilder
TypeBuilder is the main entry point for creating custom types, not directly from the embedded 'parse' module.
parse
from parse import parse
import parse_type.parse
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.

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.

from enum import Enum from parse import parse from parse_type import TypeBuilder # 1. Define an Enum to be used as a custom type class ColorEnum(Enum): red = 1 green = 2 blue = 3 # 2. Create a TypeBuilder instance, integrating the Enum # TypeBuilder can also create types from regex or functions. parse_types = TypeBuilder.with_enum(ColorEnum) # 3. Define a parse pattern using the custom type pattern = "The color is {color:Color}" text = "The color is blue" # 4. Use the parse function, passing the custom type definitions # The key 'Color' in the dict corresponds to the type name in the pattern. result = parse(pattern, text, dict(Color=parse_types.Color)) if result: print(f"Successfully parsed! Color: {result['color']}") print(f"Type of parsed color: {type(result['color'])}") assert result['color'] is ColorEnum.blue print("Assertion successful: Parsed value matches Enum member.") else: print("Parsing failed.")
Debug
Known issues
gotchaThe `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.
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.
affects: All versions
deprecatedAlthough `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.
fix
Ensure you are using `parse-type` with a modern, actively supported version of Python 3 (e.g., Python 3.8+).
affects: All versions supporting Python 2.7
gotchaReleases 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.
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.
affects: <0.6.3
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'parse'
The Python 'parse' library (which 'parse-type' extends) is not installed or cannot be found in the current Python environment.
fix
Ensure the 'parse' library is installed using pip: `pip install parse` or `pip3 install parse`.
AttributeError: 'module' object has no attribute 'parse'
This typically occurs when a user has a local file or another installed package named 'parse.py' that shadows the actual 'parse' library, or if they are trying to access a 'parse' method on an object that isn't the module itself.
fix
Rename any local 'parse.py' files to avoid conflicts, or ensure you are correctly importing and using the 'parse' module (e.g., `import parse` then `parse.parse(...)`).
ValueError: invalid literal for int() with base 10: 'some_string'
A custom type definition, particularly one using `parse_type.cfn` for integer conversion or a similar transformation, received input that could not be converted into an integer.
fix
Ensure the input string matches the expected format for the custom type's conversion function. If using `int`, the input string must represent a valid integer.
re.error: missing ), unterminated subpattern at position X
A regular expression pattern provided to `parse_type.regex` is syntactically incorrect, leading to an error in Python's underlying `re` module.
fix
Correct the syntax of the regular expression pattern used in your `parse_type.regex` definition to ensure it is valid.
Upgrade
Version history
0.6.6latest on PyPI · released Aug 11, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
parse-type — pip install parse-type · libregistry