{"id":28279,"library":"spring-data-sqlachemy","title":"Spring Data SQLAlchemy","description":"Spring Data SQLAlchemy (v0.1.4) brings Spring Data-style repository patterns to Python's SQLAlchemy. It provides automatic query generation from method names, dynamic queries with Example/QueryByExample, and integration with SQLAlchemy async sessions. Designed for projects requiring a familiar Spring Data DSL while using SQLAlchemy ORM.","status":"active","version":"0.1.4","language":"python","source_language":"en","source_url":"https://github.com/kobibleu/spring-data-sqlalchemy","tags":["spring-data","sqlalchemy","repository-pattern","orm","query-by-example"],"install":[{"cmd":"pip install spring-data-sqlachemy","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core ORM dependency","package":"sqlalchemy","optional":false}],"imports":[{"note":"In v0.1.4, the public export is at the package level, not in submodules.","wrong":"from spring_data_sqlalchemy.repository import SpringDataRepository","symbol":"SpringDataRepository","correct":"from spring_data_sqlalchemy import SpringDataRepository"},{"note":"Correct import for the QueryByExample builder.","symbol":"QueryByExample","correct":"from spring_data_sqlalchemy.query import QueryByExample"},{"note":"Example (matcher) is in the query module, not top-level.","wrong":"from spring_data_sqlalchemy import Example","symbol":"Example","correct":"from spring_data_sqlalchemy.query import Example"}],"quickstart":{"code":"from spring_data_sqlalchemy import SpringDataRepository\nfrom sqlalchemy import create_engine, Column, Integer, String\nfrom sqlalchemy.ext.declarative import declarative_base\n\nBase = declarative_base()\n\nclass User(Base):\n    __tablename__ = 'users'\n    id = Column(Integer, primary_key=True)\n    name = Column(String)\n    email = Column(String)\n\nengine = create_engine('sqlite:///:memory:')\nBase.metadata.create_all(engine)\n\nclass UserRepository(SpringDataRepository[User]):\n    entity = User\n\nrepo = UserRepository(session_factory=engine.connect)\nuser = User(name='Alice', email='alice@example.com')\nrepo.save(user)\nprint(user.id)  # 1","lang":"python","description":"Minimal example: define a SQLAlchemy model, create a repository, save an entity."},"warnings":[{"fix":"Use session_factory=engine.connect (or lambda: Session(engine)).","message":"Session factory must be a callable returning a Session, not a Session instance. Passing a Session object will cause 'session is already closed' errors.","severity":"gotcha","affected_versions":"0.1.x"},{"fix":"Ensure your entity has a single primary key or override the find method.","message":"QueryByExample with composite keys may raise AttributeError if the entity's __table__.primary_key.columns contains multiple columns.","severity":"breaking","affected_versions":"0.1.4"},{"fix":"Use QueryByExample for complex queries; avoid relying on method name parsing for production.","message":"The dynamic finder methods (e.g., findByName_ignoreCase) are experimental and may change signature or behavior in future releases.","severity":"deprecated","affected_versions":"0.1.x"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Ensure you installed the correct package: pip install spring-data-sqlachemy (note the typo 'sqlachemy' in the package name).","cause":"Incorrect import: using an older or renamed version of the module.","error":"TypeError: __init__() got an unexpected keyword argument 'session_factory'"},{"fix":"Pass a callable: repo = UserRepository(session_factory=lambda: Session(engine)).","cause":"Misusing session_factory with an existing Session instead of a factory callable.","error":"sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back by a nested session"},{"fix":"Make sure the entity inherits from declarative_base() and has a mapped table.","cause":"Using a non-SQLAlchemy model class as the entity.","error":"AttributeError: 'User' object has no attribute '_sa_instance_state'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}