Registry / web-framework / wtforms-alchemy

wtforms-alchemy

JSON →
library0.19.1pypypi✓ verified 86d ago

Generates WTForms forms from SQLAlchemy models, reducing boilerplate for Flask and other web frameworks. Current version 0.19.1, with irregular releases.

pip install wtforms-alchemy
INSTALL
IMPORT
SIG · WTFORMS-ALCHEMY
W
wtforms-alchemy
web-frameworkpythonv0.19.1
Install
4.8s avg
Import
1195ms
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.19.1 · 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 1.232s · 47.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.8s · import 1.158s · 45MB
45MB installed
● package 45MB
Code
Verified usage

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

ModelForm
from wtforms_alchemy import ModelForm
ModelFormField
from wtforms_alchemy import ModelFormField
from wtforms_alchemy.fields import ModelFormField
wrong submodule, top-level import is correct
UniqueValidator
from wtforms_alchemy import UniqueValidator

Generate a WTForms form from a SQLAlchemy model.

from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from wtforms_alchemy import ModelForm Base = declarative_base() class User(Base): __tablename__ = 'user' id = Column(Integer, primary_key=True) name = Column(String(100), nullable=False) email = Column(String(100), nullable=False) engine = create_engine('sqlite:///') Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() class UserForm(ModelForm): class Meta: model = User include = ['name', 'email'] form = UserForm() print(form.name.label.text)
Debug
Known issues
breakingIn version 0.19.0, support for SQLAlchemy 1.x was dropped; SQLAlchemy 2.0+ is required.
fix
Upgrade SQLAlchemy to 2.0+ or pin wtforms-alchemy to <0.19.0.
affects: >=0.19.0
deprecatedThe 'inline_models' feature is deprecated and will be removed in a future version.
fix
Use ModelFormField for nested forms instead.
affects: >=0.18.0
gotchaAuto-generated field types depend on column type mapping; unhandled types raise ValueError. Ensure all model columns map to known WTForms fields.
fix
Register custom type mapping using 'type_mapping' in Meta class.
affects: all
gotchaUnique validation requires a SQLAlchemy session to be passed explicitly via Meta's 'session' attribute or set globally.
fix
Add 'session = session' to Meta class or call init with session=session.
affects: all
Errors
Common errors & fixes
wtforms_alchemy.exceptions.UnknownTypeException: Unknown column type: <class 'sqlalchemy.dialects.postgresql.ARRAY'>
The column type is not registered in the default type mapping.
fix
Add a type mapping in the Meta class: 'type_mapping = {ARRAY: StringField}' or similar.
AttributeError: 'ModelForm' object has no attribute 'validate_unique'
UniqueValidator is not automatically added; you need to enable it explicitly.
fix
Set 'validators = [UniqueValidator()]' on the field or use 'include_unique' in Meta.
ImportError: cannot import name 'ModelForm' from 'wtforms_alchemy'
Old versions may have different import paths; ensure version >=0.16.0 or install from PyPI.
fix
Upgrade to latest version with 'pip install --upgrade wtforms-alchemy'.
Upgrade
Version history
0.19.1latest on PyPI · released Aug 11, 2025
Audit
Dependencies
wtformsrequiredruntime dependency for form base classes and fields
sqlalchemyrequiredrequired for model introspection and ORM support
Agent activity
32 hits · last 30 days
node
26
Meta
2
OpenAI (training)
1
Resources
wtforms-alchemy — pip install wtforms-alchemy · libregistry