{"id":22401,"library":"sqlalchemy-filters","title":"sqlalchemy-filters","description":"A library to filter SQLAlchemy queries using a JSON-like filter specification. Current version: 0.13.0, supports SQLAlchemy 1.4, Python 3.7+. Release cadence is irregular.","status":"active","version":"0.13.0","language":"python","source_language":"en","source_url":"https://github.com/juliotrigo/sqlalchemy-filters","tags":["sqlalchemy","filter","query","filtering"],"install":[{"cmd":"pip install sqlalchemy-filters","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency for query filtering.","package":"sqlalchemy","optional":false}],"imports":[{"note":"","wrong":"","symbol":"apply_filters","correct":"from sqlalchemy_filters import apply_filters"},{"note":"","wrong":"","symbol":"apply_sort","correct":"from sqlalchemy_filters import apply_sort"}],"quickstart":{"code":"from sqlalchemy import create_engine, Column, Integer, String\nfrom sqlalchemy.orm import declarative_base, sessionmaker\nfrom sqlalchemy_filters import apply_filters, apply_sort\n\nBase = declarative_base()\nclass Book(Base):\n    __tablename__ = 'book'\n    id = Column(Integer, primary_key=True)\n    title = Column(String)\n    price = Column(Integer)\n\nengine = create_engine('sqlite:///:memory:', echo=False)\nBase.metadata.create_all(engine)\nSession = sessionmaker(bind=engine)\nsession = Session()\nsession.add_all([Book(title='A', price=10), Book(title='B', price=20)])\nsession.commit()\n\nfilter_spec = [{'field': 'price', 'op': 'gt', 'value': 15}]\nquery = session.query(Book)\nfiltered_query = apply_filters(query, filter_spec)\nresults = filtered_query.all()\nprint([(b.title, b.price) for b in results])","lang":"python","description":"Filters a SQLAlchemy query with a simple filter specification."},"warnings":[{"fix":"Upgrade to Python 3.7+ and sqlalchemy-filters >=0.13.0.","message":"Python 2.7, 3.5, 3.6 support dropped in v0.13.0.","severity":"deprecated","affected_versions":"<=0.12.0"},{"fix":"Use 'eq', 'ne', 'gt', 'lt', 'ge', 'le', 'like', 'ilike', 'in', 'not_in', 'any', 'not_any'.","message":"Filter operators '==', '!=' were renamed to 'eq', 'ne' in early versions. Check operator names.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Pass `auto_join=False` to `apply_filters` to prevent automatic joins.","message":"Auto-join behavior: filters on related models automatically join the related table; use the 'auto_join' parameter to disable.","severity":"gotcha","affected_versions":">=0.7.0"},{"fix":"Ensure hybrid attributes are properly defined with expressions.","message":"Sorting on hybrid attributes requires the attribute to be defined on the model.","severity":"gotcha","affected_versions":">=0.12.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `from sqlalchemy_filters import apply_filters`.","cause":"Incorrect import (e.g., `import sqlalchemy_filters` and then using `sqlalchemy_filters.apply_filters` but the function is not exposed at top level).","error":"AttributeError: module 'sqlalchemy_filters' has no attribute 'apply_filters'"},{"fix":"Check that the field exists on the model and the operator is one of: eq, ne, gt, lt, ge, le, like, ilike, in, not_in, any, not_any.","cause":"The filter specification uses an invalid operator or field name.","error":"sqlalchemy.exc.ArgumentError: filter expression is not a valid SQL expression"},{"fix":"Disable auto-join with `auto_join=False` or explicitly add the join in the query.","cause":"Auto-join tries to join a table that is already in the query, or the filtering causes a self-referential join.","error":"sqlalchemy.exc.InvalidRequestError: Can't join table/selectable 'some_table' to itself"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}