{"id":10271,"library":"stringparser","title":"stringparser Library","description":"stringparser is a Python library that provides an easy-to-use interface for pattern matching and information extraction from strings, built on top of the 'parsy' library. It simplifies the process of defining structured patterns to parse text into Python dictionaries. The current version is 0.7, and releases are generally made on an as-needed basis rather than a fixed cadence.","status":"active","version":"0.7","language":"en","source_language":"en","source_url":"https://github.com/hgrecco/stringparser","tags":["parsing","string","pattern-matching","text-extraction","data-extraction"],"install":[{"cmd":"pip install stringparser","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core parsing engine used internally by stringparser.","package":"parsy","optional":false}],"imports":[{"symbol":"StringParser","correct":"from stringparser import StringParser"},{"note":"Used for defining more complex or reusable patterns.","symbol":"Pattern","correct":"from stringparser import Pattern"}],"quickstart":{"code":"from stringparser import StringParser\n\n# Define a parser using a pattern string\nparser = StringParser(\"Hello {name:s}! Your age is {age:d}.\")\n\n# Parse a matching string\nresult = parser.parse(\"Hello Alice! Your age is 30.\")\nprint(result)\n# Expected output: {'name': 'Alice', 'age': 30}\n\n# Example with a different pattern and input\ndate_parser = StringParser(\"{day:d}/{month:d}/{year:d}\")\ndate_result = date_parser.parse(\"25/12/2023\")\nprint(date_result)\n# Expected output: {'day': 25, 'month': 12, 'year': 2023}","lang":"python","description":"This quickstart demonstrates how to create a `StringParser` instance with a pattern string and use it to extract data from input strings. The pattern uses `{key:type}` syntax for named capture groups and type conversion."},"warnings":[{"fix":"Refer to the stringparser documentation for its specific pattern syntax, which uses '{name:type}' for capturing and type conversion.","message":"stringparser patterns are NOT regular expressions. While they define matching rules, they use a distinct syntax based on 'parsy' for structured parsing, not regex.","severity":"gotcha","affected_versions":"All versions (0.1+)"},{"fix":"Pin your dependency to a specific minor version (e.g., `stringparser==0.7`) and review the project's changelog or GitHub releases for any breaking changes before upgrading.","message":"As a 0.x version library, stringparser's API stability is not strictly guaranteed. Minor versions (e.g., 0.7 to 0.8) may introduce backward-incompatible changes.","severity":"gotcha","affected_versions":"All 0.x versions"},{"fix":"Ensure your input data strictly adheres to the defined pattern. For more flexible parsing, you might need to combine multiple patterns or handle `ParsingError` explicitly.","message":"Input strings must match the defined pattern exactly. If a portion of the input does not conform to the pattern, a `ParsingError` will be raised, unlike regex which might partially match or return None.","severity":"gotcha","affected_versions":"All versions (0.1+)"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Carefully compare your input string with the pattern. Ensure all literal characters match and all capture groups (`{key:type}`) are correctly formatted and present in the input.","cause":"The input string provided to `parser.parse()` did not match the pattern defined in `StringParser` or `Pattern` object.","error":"stringparser.ParsingError: Expected '...', got '...' at ..."},{"fix":"Initialize `StringParser` only with a valid string representing the pattern or an instance of `stringparser.Pattern`.","cause":"You attempted to initialize `StringParser` with an unsupported object type (e.g., a list, integer, or `None`) instead of a pattern string or a `Pattern` object.","error":"TypeError: argument of type 'list' is not iterable (or similar TypeError with non-string/Pattern objects)"},{"fix":"Use the `parse()` method on your `StringParser` instance to attempt to parse the entire input string according to the defined pattern. `stringparser` is not a regex wrapper.","cause":"Misconception that `stringparser` objects have `re`-like methods (`match`, `search`) for regex-style operations.","error":"AttributeError: 'StringParser' object has no attribute 'match' (or 'search')"}]}