Registry / devops / strawberry-sqlalchemy-mapper

strawberry-sqlalchemy-mapper

JSON →
library0.8.0pypypi✓ verified 83d ago

A library for autogenerating Strawberry GraphQL types from SQLAlchemy models. Current version 0.8.0, supports Python >=3.8 <4.0. Release cadence is irregular; maintained by the strawberry-graphql organization.

pip install strawberry-sqlalchemy-mapper
INSTALL
IMPORT
SIG · STRAWBERRY-SQLALCH
S
strawberry-sqlalchemy-mapper
devopspythonv0.8.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

strawberry_sqlalchemy_mapper
from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper
from strawberry_sqlalchemy import StrawberrySQLAlchemyMapper
Wrong package; pip installs strawberry-sqlalchemy-mapper, not strawberry-sqlalchemy.

Declare SQLAlchemy models, then use mapper.type() and mapper.input() to generate GraphQL types.

import os from sqlalchemy import create_engine, Column, Integer, String from sqlalchemy.ext.declarative import declarative_base from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite:///:memory:') engine = create_engine(DATABASE_URL) Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String) mapper = StrawberrySQLAlchemyMapper() @mapper.type(User) class UserType: pass @mapper.input(User) class UserInput: pass import strawberry @strawberry.type class Query: @strawberry.field def user(self, id: int) -> UserType: return session.query(User).filter(User.id == id).first() schema = strawberry.Schema(query=Query, types=mapper.types())
Debug
Known issues
breakingVersion 0.7.0 introduced breaking changes: mapper now requires @mapper.type() and @mapper.input() decorators; the old pattern of strawberry_sqlalchemy_mapper.type() is removed.
fix
Update to use decorators on classes: @mapper.type(Model) class Type: pass
affects: <0.7.0
gotchaYou must include mapper.types() in the schema's types list, otherwise your generated types are not registered and GraphQL queries fail.
fix
Pass `types=mapper.types()` to `strawberry.Schema`.
affects: >=0.7.0
gotchaIf you use `auto_convert=True` (default True), all columns are included; to exclude columns, you must explicitly define the type class with fields.
fix
Disable auto_convert with `@mapper.type(Model, auto_convert=False)` and define fields manually.
affects: >=0.7.0
deprecatedThe `strawberry_sqlalchemy_mapper.strawberry.type` import is deprecated; always use `strawberry.type` from strawberry directly.
fix
Replace `from strawberry_sqlalchemy_mapper import strawberry` with `import strawberry`.
affects: >=0.7.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'strawberry_sqlalchemy'
Wrong package name; pip installs 'strawberry-sqlalchemy-mapper' but import uses 'strawberry_sqlalchemy_mapper'.
fix
Run `pip install strawberry-sqlalchemy-mapper` and import `from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper`.
AttributeError: type object 'UserType' has no attribute '_strawberry_type'
Missing `mapper.types()` in schema registration; the type decorator was applied but types not added to schema.
fix
Add `types=mapper.types()` to `strawberry.Schema(..., types=mapper.types())`.
TypeError: 'StrawberrySQLAlchemyMapper' object is not callable
Using old style: `mapper = StrawberrySQLAlchemyMapper()` then `mapper.type(User)` as a function call instead of decorator.
fix
Use `@mapper.type(User)` decorator on a class, not `mapper.type(User)`.
Upgrade
Version history
0.8.0latest on PyPI · released Dec 1, 2025
Audit
Dependencies
strawberry-graphqlrequiredCore GraphQL framework
sqlalchemyrequiredORM models
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
strawberry-sqlalchemy-mapper — pip install strawberry-sqlalchemy-mapper · libregistry