{"id":2034,"library":"flexparser","title":"Flexparser for Typed Parsing","description":"Flexparser is a Python library that enables parsing of string-based data into complex Python objects using type hints. Inspired by Pydantic, it leverages `typing` module annotations to define target data structures. Currently at version 0.4, its release cadence is infrequent but maintained.","status":"active","version":"0.4","language":"en","source_language":"en","source_url":"https://github.com/hgrecco/flexparser","tags":["parsing","type hints","dataclasses","declarative","yaml-like","pydantic-inspired"],"install":[{"cmd":"pip install flexparser","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary function for parsing string input into a typed object.","symbol":"parse_string","correct":"from flexparser import parse_string"},{"note":"Used for parsing Python objects (e.g., dictionaries) into a specified typed object.","symbol":"parse_object","correct":"from flexparser import parse_object"}],"quickstart":{"code":"from flexparser import parse_string\nfrom typing import Dict, List, Union, Tuple\n\n# Define the target structure using type hints.\n# Flexparser will use these annotations at runtime to understand\n# how to parse the input string.\ndef parse_config_data(data_str: str) -> Dict[str, Union[str, int, float, bool, List[str], Tuple[int, int]]]:\n    \"\"\"\n    Parses a string into a dictionary based on the return type hints.\n    The function body itself is not executed for parsing;\n    only its annotations are used by flexparser.\n    \"\"\"\n    pass\n\nconfig_string = \"\"\"\nname: Alice\nage: 30\ncity: New York\ntags: python, parsing\nlocation: (10, 20)\nis_active: true\nscore: 98.5\n\"\"\"\n\n# Parse the string using the return annotation of 'parse_config_data'\nparsed_data = parse_string(config_string, target_type=parse_config_data.__annotations__['return'])\n\nprint(\"Parsed Data:\", parsed_data)\nprint(\"Type of name:\", type(parsed_data.get('name')))\nprint(\"Type of age:\", type(parsed_data.get('age')))\nprint(\"Type of tags:\", type(parsed_data.get('tags')))\nprint(\"Type of location:\", type(parsed_data.get('location')))\nprint(\"Type of is_active:\", type(parsed_data.get('is_active')))","lang":"python","description":"This quickstart demonstrates how to use `flexparser.parse_string` to parse a YAML-like string into a Python dictionary, leveraging type hints for schema definition. The `target_type` argument tells `flexparser` what structure to expect, which it infers from the return annotation of `parse_config_data`."},"warnings":[{"fix":"Refer to the GitHub repository for the latest API documentation and examples. Pin exact minor versions in your `requirements.txt` to prevent unexpected breaks (e.g., `flexparser==0.4`).","message":"As a pre-1.0 library, `flexparser`'s API is subject to change without prior notice across minor versions. Features might be renamed, modified, or removed.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Stick to standard Python types (e.g., `str`, `int`, `float`, `bool`, `List`, `Dict`, `Tuple`, `Union`) for best compatibility. For custom types, consult the source code or experiment with simple examples first to understand current capabilities.","message":"Flexparser relies heavily on runtime type introspection for parsing. Complex or highly nested custom types, or advanced `typing` features (e.g., `TypedDict`, `NewType`) might require explicit parser registration or might not be fully supported without specific extensions.","severity":"gotcha","affected_versions":"all"},{"fix":"Test parsing with incremental complexity. Use smaller input snippets to isolate issues. For critical data, consider adding preliminary input validation before parsing to catch common structural errors earlier.","message":"Error messages for malformed input might sometimes be generic or not pinpoint the exact line/token causing the issue, making debugging complex parsing failures challenging.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}