{"id":10360,"library":"wtforms-components","title":"WTForms Components","description":"WTForms-Components is a library that extends WTForms with additional fields, validators, and widgets, aiming to simplify common form-related tasks. It is currently at version 0.11.0 and is maintained with occasional releases driven by community contributions and WTForms compatibility.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/kvesteri/wtforms-components","tags":["WTForms","forms","validation","fields","widgets","form-extension"],"install":[{"cmd":"pip install wtforms-components","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Provides the base form and field classes that this library extends.","package":"WTForms","optional":false}],"imports":[{"note":"Common fields/validators are directly exposed under the top-level 'wtforms_components' namespace.","wrong":"from wtforms_components.validators import Email","symbol":"Email","correct":"from wtforms_components import Email"},{"note":"Common fields/validators are directly exposed under the top-level 'wtforms_components' namespace.","wrong":"from wtforms_components.fields import DateField","symbol":"DateField","correct":"from wtforms_components import DateField"},{"note":"Common fields/validators are directly exposed under the top-level 'wtforms_components' namespace.","wrong":"from wtforms_components.validators import Unique","symbol":"Unique","correct":"from wtforms_components import Unique"}],"quickstart":{"code":"from wtforms import Form\nfrom wtforms_components import Email, DateField\nfrom wtforms.validators import DataRequired\n\nclass UserProfileForm(Form):\n    email = Email(validators=[DataRequired()])\n    birth_date = DateField(validators=[DataRequired()])\n\n# Example usage (run with a dictionary or request.form)\nform_data = {\n    'email': 'user@example.com',\n    'birth_date': '1990-05-15'\n}\n\nform = UserProfileForm(data=form_data)\n\nif form.validate():\n    print(\"Form is valid!\")\n    print(f\"Email: {form.email.data}\")\n    print(f\"Birth Date: {form.birth_date.data}\")\nelse:\n    print(\"Form errors:\")\n    for field, errors in form.errors.items():\n        for error in errors:\n            print(f\"  {field}: {error}\")","lang":"python","description":"This quickstart demonstrates defining a simple form using WTForms-Components' custom Email and DateField types with basic validation. It shows how to instantiate the form with data and validate it."},"warnings":[{"fix":"Always use `import wtforms_components` or `from wtforms_components import ...` in your Python code, even though you install `pip install wtforms-components`.","message":"The PyPI package name is `wtforms-components` (with a hyphen), but the Python package name for importing is `wtforms_components` (with an underscore). Importing `wtforms-components` will result in a `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult WTForms-Components GitHub issues for known compatibility problems with newer WTForms versions. If issues arise, consider pinning an older WTForms version (e.g., `WTForms<3.0`) or contributing compatibility fixes.","message":"While the library declares `WTForms>=2.0`, specific functionalities might be primarily tested against older WTForms 2.x versions. Users on WTForms 3.x or 4.x should thoroughly test custom fields, widgets, and complex validators for full compatibility, especially if encountering unexpected `TypeError` or `AttributeError`.","severity":"gotcha","affected_versions":"0.10.0 to 0.11.0"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Change your import statement from `import wtforms-components` to `import wtforms_components` (or `from wtforms_components import ...`).","cause":"The user attempted to import the package using its PyPI name (`wtforms-components`) instead of its Python module name (`wtforms_components`).","error":"ModuleNotFoundError: No module named 'wtforms-components'"},{"fix":"Import the symbol directly from the top-level package, e.g., `from wtforms_components import Unique`.","cause":"Many commonly used fields and validators from `wtforms-components` are directly exposed under the top-level `wtforms_components` namespace, not nested within submodules like `wtforms_components.validators` or `wtforms_components.fields`.","error":"ImportError: cannot import name 'Unique' from 'wtforms_components.validators' (or similar for 'Email', 'DateField')"},{"fix":"When using `Unique`, ensure you pass the SQLAlchemy/ORM model and the field to check uniqueness for. Example: `email = Email(validators=[Unique(User, User.email)])`.","cause":"The `Unique` validator (and similar database-interacting validators) requires specific arguments like a database model and field to check uniqueness against, which were not provided or were provided incorrectly.","error":"TypeError: __init__() missing 1 required positional argument: 'model' (or 'query' for Unique validator)"}]}