{"id":46539,"library":"strawberry-sqlalchemy-mapper","title":"Strawberry SQLAlchemy Mapper","description":"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.","status":"active","version":"0.8.0","language":"python","source_language":"en","source_url":"https://github.com/strawberry-graphql/strawberry-sqlalchemy","tags":["strawberry","graphql","sqlalchemy","orm","type-generation"],"install":[{"cmd":"pip install strawberry-sqlalchemy-mapper","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core GraphQL framework","package":"strawberry-graphql","optional":false},{"reason":"ORM models","package":"sqlalchemy","optional":false}],"imports":[{"note":"Wrong package; pip installs strawberry-sqlalchemy-mapper, not strawberry-sqlalchemy.","wrong":"from strawberry_sqlalchemy import StrawberrySQLAlchemyMapper","symbol":"strawberry_sqlalchemy_mapper","correct":"from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper"}],"quickstart":{"code":"import os\nfrom sqlalchemy import create_engine, Column, Integer, String\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper\n\nDATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite:///:memory:')\nengine = create_engine(DATABASE_URL)\nBase = declarative_base()\n\nclass User(Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    name = Column(String)\n\nmapper = StrawberrySQLAlchemyMapper()\n@mapper.type(User)\nclass UserType:\n    pass\n\n@mapper.input(User)\nclass UserInput:\n    pass\n\nimport strawberry\n@strawberry.type\nclass Query:\n    @strawberry.field\n    def user(self, id: int) -> UserType:\n        return session.query(User).filter(User.id == id).first()\n\nschema = strawberry.Schema(query=Query, types=mapper.types())","lang":"python","description":"Declare SQLAlchemy models, then use mapper.type() and mapper.input() to generate GraphQL types."},"warnings":[{"fix":"Update to use decorators on classes: @mapper.type(Model) class Type: pass","message":"Version 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.","severity":"breaking","affected_versions":"<0.7.0"},{"fix":"Pass `types=mapper.types()` to `strawberry.Schema`.","message":"You must include mapper.types() in the schema's types list, otherwise your generated types are not registered and GraphQL queries fail.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Disable auto_convert with `@mapper.type(Model, auto_convert=False)` and define fields manually.","message":"If you use `auto_convert=True` (default True), all columns are included; to exclude columns, you must explicitly define the type class with fields.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Replace `from strawberry_sqlalchemy_mapper import strawberry` with `import strawberry`.","message":"The `strawberry_sqlalchemy_mapper.strawberry.type` import is deprecated; always use `strawberry.type` from strawberry directly.","severity":"deprecated","affected_versions":">=0.7.0"}],"env_vars":null,"search_vec":"'0.8.0':16 '3.8':19 '4.0':20 'autogener':7 'cadenc':22 'current':14 'generat':38 'graphql':9,30,33 'irregular':24 'librari':5 'maintain':25 'mapper':3 'model':13 'organ':31 'orm':35 'python':18 'releas':21 'sqlalchemi':2,12,34 'strawberri':1,8,29,32 'strawberry-graphql':28 'support':17 'type':10,37 'type-gener':36 'version':15","created_at":"2026-06-07T13:00:24.876269+00:00","updated_at":"2026-06-07T13:00:24.876269+00:00","problems":[{"fix":"Run `pip install strawberry-sqlalchemy-mapper` and import `from strawberry_sqlalchemy_mapper import StrawberrySQLAlchemyMapper`.","cause":"Wrong package name; pip installs 'strawberry-sqlalchemy-mapper' but import uses 'strawberry_sqlalchemy_mapper'.","error":"ModuleNotFoundError: No module named 'strawberry_sqlalchemy'"},{"fix":"Add `types=mapper.types()` to `strawberry.Schema(..., types=mapper.types())`.","cause":"Missing `mapper.types()` in schema registration; the type decorator was applied but types not added to schema.","error":"AttributeError: type object 'UserType' has no attribute '_strawberry_type'"},{"fix":"Use `@mapper.type(User)` decorator on a class, not `mapper.type(User)`.","cause":"Using old style: `mapper = StrawberrySQLAlchemyMapper()` then `mapper.type(User)` as a function call instead of decorator.","error":"TypeError: 'StrawberrySQLAlchemyMapper' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://strawberry.rocks/","github":"https://github.com/strawberry-graphql/strawberry-sqlalchemy","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}