{"id":10028,"library":"peppercorn","title":"Peppercorn","description":"Peppercorn is a Python library designed to transform flat key-value pairs (common in web form posts, e.g., from `request.form`) into structured nested dictionaries and lists, and vice-versa. It handles dot-notation and array indexing in keys to reconstitute complex data structures. The current version is 0.6, and it appears to be in maintenance mode with infrequent updates.","status":"maintenance","version":"0.6","language":"en","source_language":"en","source_url":"https://github.com/mmerickel/peppercorn","tags":["web","forms","data-parsing","serialization","deserialization"],"install":[{"cmd":"pip install peppercorn","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"parse","correct":"from peppercorn import parse"},{"symbol":"flatten","correct":"from peppercorn import flatten"}],"quickstart":{"code":"import peppercorn\n\n# Example form data, typically from request.form\nform_data = {\n    'items.0.name': 'Foo',\n    'items.0.value': '123',\n    'items.1.name': 'Bar',\n    'items.1.value': '456',\n    'user.name': 'Alice',\n    'user.id': 'abc'\n}\n\n# Parse flat data into a nested structure\nparsed_data = peppercorn.parse(form_data)\nprint(\"Parsed Data:\", parsed_data)\n# Expected: {'items': [{'name': 'Foo', 'value': '123'}, {'name': 'Bar', 'value': '456'}], 'user': {'name': 'Alice', 'id': 'abc'}}\n\n# Flatten a nested structure back into flat form data\n# (Often for use in template rendering or re-submitting)\nflat_data = peppercorn.flatten(parsed_data)\nprint(\"Flattened Data:\", flat_data)\n# Expected: {'items.0.name': 'Foo', 'items.0.value': '123', 'items.1.name': 'Bar', 'items.1.value': '456', 'user.name': 'Alice', 'user.id': 'abc'}","lang":"python","description":"Demonstrates parsing a flat dictionary (representing form data) into a nested structure and then flattening it back."},"warnings":[{"fix":"Ensure input keys adhere to `peppercorn`'s expected format (dot-separated for dicts, integer-indexed for lists).","message":"The `parse` function expects input keys to strictly follow dot-notation for nested dictionaries and integer indices for lists (e.g., `parent.child.0.grandchild`). Keys that do not conform will be treated as literal flat strings, potentially leading to unexpected non-nested output.","severity":"gotcha","affected_versions":"0.1 - 0.6"},{"fix":"Perform explicit type conversions on the parsed data after `peppercorn.parse` if non-string types are required for business logic.","message":"Peppercorn primarily handles structure reconstitution. It does not perform type conversions (e.g., converting '123' to an integer, or 'true' to a boolean). All values in the resulting structure will remain strings.","severity":"gotcha","affected_versions":"0.1 - 0.6"},{"fix":"Evaluate if the current feature set meets long-term needs. For new projects, explore modern form handling libraries if active development is a requirement.","message":"The library appears to be in maintenance mode, with no new releases since January 2021. While stable for its niche, new feature development or active bug fixes are unlikely. Consider alternatives for projects requiring active development or support for modern web frameworks' advanced form handling.","severity":"gotcha","affected_versions":"0.6"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Use `peppercorn.parse` (lowercase) for the parsing function.","cause":"Attempting to call `peppercorn.Parse` (PascalCase) instead of `peppercorn.parse` (lowercase). Python function names are typically snake_case.","error":"AttributeError: module 'peppercorn' has no attribute 'Parse'"},{"fix":"Inspect your input dictionary keys. Ensure nested objects use dot-notation and list items use integer indices following the dot (e.g., `items.0.name`).","cause":"The input keys to `peppercorn.parse` did not strictly follow the dot-notation (`parent.child`) or array-indexing (`list.0.item`) conventions, causing `peppercorn` to treat them as literal flat keys.","error":"My parsed data is flat, but I expected a nested dictionary/list!"},{"fix":"Verify that your input keys for list elements use valid integer indices, like `items.0.field`, `items.1.field`, etc., ensuring `peppercorn` correctly identifies and creates a list.","cause":"This error often occurs when `peppercorn.parse` creates a dictionary where you expected a list, because the input keys for what should have been list elements were malformed (e.g., `items.first.name` instead of `items.0.name`).","error":"TypeError: 'dict' object is not subscriptable (when trying to access a list element)"}]}