{"id":23168524,"url":"https://github.com/elmkarami/sqlalchemy-filters-plus","last_synced_at":"2025-08-18T06:33:32.331Z","repository":{"id":37304462,"uuid":"352206322","full_name":"elmkarami/sqlalchemy-filters-plus","owner":"elmkarami","description":"Lightweight library for providing filtering mechanism for your APIs using SQLAlchemy","archived":false,"fork":false,"pushed_at":"2022-12-03T20:01:21.000Z","size":102,"stargazers_count":45,"open_issues_count":3,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-02T10:45:06.261Z","etag":null,"topics":["api","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elmkarami.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-28T00:14:14.000Z","updated_at":"2025-04-24T16:02:24.000Z","dependencies_parsed_at":"2023-01-22T18:16:15.728Z","dependency_job_id":null,"html_url":"https://github.com/elmkarami/sqlalchemy-filters-plus","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/elmkarami/sqlalchemy-filters-plus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmkarami%2Fsqlalchemy-filters-plus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmkarami%2Fsqlalchemy-filters-plus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmkarami%2Fsqlalchemy-filters-plus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmkarami%2Fsqlalchemy-filters-plus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elmkarami","download_url":"https://codeload.github.com/elmkarami/sqlalchemy-filters-plus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elmkarami%2Fsqlalchemy-filters-plus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270955037,"owners_count":24674815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","python","sqlalchemy"],"created_at":"2024-12-18T02:44:45.865Z","updated_at":"2025-08-18T06:33:30.924Z","avatar_url":"https://github.com/elmkarami.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"![example workflow](https://github.com/elmkarami/sqlalchemy-filters-plus/actions/workflows/release.yml/badge.svg)\n![example workflow](https://github.com/elmkarami/sqlalchemy-filters-plus/actions/workflows/main.yml/badge.svg)\n[![codecov](https://codecov.io/gh/elmkarami/sqlalchemy-filters-plus/branch/master/graph/badge.svg?token=I7ZC1WQYEQ)](https://codecov.io/gh/elmkarami/sqlalchemy-filters-plus)\n\nsqlalchemy-filters-plus is a light-weight extendable library for filtering queries with sqlalchemy.\n\nInstall\n-\n\n```bash\npip install sqlalchemy-filters-plus\n```\n\n\nUsage\n-----\n\nThis library provides an easy way to filter your SQLAlchemy queries,\nwhich can for example be used by your users as a filtering mechanism for your exposed models via an API.\n\nLet's define an example of models that will be used as a base query.\n\n```python\nfrom sqlalchemy import Column, Date, Integer, String, ForeignKey\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy.orm import relationship, backref\n\nBase = declarative_base()\n\n\nclass User(Base):\n    id = Column(Integer, primary_key=True)\n    email = Column(String)\n    age = Column(Integer)\n    birth_date = Column(Date, nullable=False)\n\n\nclass Article(Base):\n    id = Column(Integer, primary_key=True)\n    title = Column(String)\n    user_id = Column(Integer, ForeignKey(User.id), nullable=False)\n    user = relationship(\n        User,\n        uselist=False,\n        lazy=\"select\",\n        backref=backref(\"articles\", uselist=True, lazy=\"select\"),\n    )\n```\n\n\nDefine your first filter\n========================\n\nLet's then define our first Filter class for the Article model\n\n```python\nfrom sqlalchemy_filters import Filter, StringField\nfrom sqlalchemy_filters.operators import ContainsOperator\n\n\nclass ArticleFilter(Filter):\n    title = StringField(lookup_operator=ContainsOperator)\n    email = StringField(field_name=\"user.email\")\n\n    class Meta:\n        model = Article\n        session = my_sqlalchemy_session\n```\n\n\nThe example above defines a new filter class attached to the Article model, we declared two fields to filter with, \n``title`` with the lookup_operator ``ContainsOperator`` and an ``email`` field which points to the user's email, hence the `field_name=\"user.email\"` without any lookup_operator (default value is ``EqualsOperator``) that will be used to filter with on the database level. We will see other operators that can also be used.\n\nTo apply the filter class, we instantiate it and pass it the data(as a dictionary) to filter with.\n\n```python\nmy_filter = ArticleFilter(data={\"email\": \"some@email.com\", \"title\": \"python\"})\nquery = my_filter.apply()  # query is a SQLAlchemy Query object\n```\n    \n\n\n\n\nPlease read the full documentation here https://sqlalchemy-filters-plus.readthedocs.io/\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmkarami%2Fsqlalchemy-filters-plus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felmkarami%2Fsqlalchemy-filters-plus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felmkarami%2Fsqlalchemy-filters-plus/lists"}