pydantic-filters
Define filters as Pydantic models, then translate them into queries with a driver. The package also provides reusable pagination and sorting models and a FastAPI integration.
Documentation: https://so-saf.github.io/pydantic-filters/
Requirements
- Python 3.10 or newer, including Python 3.14 and 3.15
- Pydantic 2
- SQLAlchemy 2 or newer when using the SQLAlchemy driver
- FastAPI 0.100 or newer when using the FastAPI plugin
Only Pydantic is a required dependency. Install integrations separately:
pip install pydantic-filters
pip install "pydantic-filters" "sqlalchemy>=2"
pip install "pydantic-filters" "fastapi>=0.100"
Quick start
import sqlalchemy as sa
import sqlalchemy.orm as so
from pydantic_filters import BaseFilter
from pydantic_filters.drivers.sqlalchemy import append_filter_to_statement
class Base(so.DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: so.Mapped[int] = so.mapped_column(primary_key=True)
name: so.Mapped[str]
age: so.Mapped[int]
class UserFilter(BaseFilter):
id: list[int]
name__ilike: str
age__ge: int
filter_ = UserFilter(name__ilike="kate", age__ge=18)
statement = append_filter_to_statement(
statement=sa.select(User),
model=User,
filter_=filter_,
)
The statement contains conditions equivalent to:
WHERE users.name ILIKE 'kate' AND users.age >= 18
Filter fields are not required by default, and fields that were not supplied are ignored by the driver. See the documentation for:
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_filters-0.4.0.tar.gz.
File metadata
- Download URL: pydantic_filters-0.4.0.tar.gz
- Upload date:
- Size: 287.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85715ad866e3c4233143717cb9f9a7d1a2ba1753b6bddb79a744e5b43b3b8149
|
|
| MD5 |
9c6de0f617192f99765bf44331fa87d2
|
|
| BLAKE2b-256 |
7b9b291e0cec0d4b33cef16c734a41926dacf498a7c56b1ac9701b1c067d3f09
|
File details
Details for the file pydantic_filters-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_filters-0.4.0-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ae2c04e1823f46502bb47d5724592f46e30895afbc58bd7abb11e30c934d14a
|
|
| MD5 |
86727b52df329ffd1574ff435a785d40
|
|
| BLAKE2b-256 |
8d2e041b3c15b0b856f55469dac3c2a6982f25d1ce98a94b30a8a97a2dd69256
|