Skip to main content

pydantic-filters

Testing Coverage PyPI Python License

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:

Metadata

Release files for pydantic-filters 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-filters 0.4.0
File Size Uploaded Provenance Actions
pydantic_filters-0.4.0.tar.gz 287.8 kB Without provenance Details for pydantic_filters-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-filters 0.4.0
File Interpreter ABI Platform Actions
pydantic_filters-0.4.0-py3-none-any.whl Python 3 none any Details for pydantic_filters-0.4.0-py3-none-any.whl

Total release size: 308.7 kB

Release files / pydantic_filters-0.4.0.tar.gz

Download URL pydantic_filters-0.4.0.tar.gz
Size 287.8 kB
Tags Source
SHA-256 checksum
How to use checksums
85715ad866e3c4233143717cb9f9a7d1a2ba1753b6bddb79a744e5b43b3b8149
BLAKE2b-256 checksum
How to use checksums
7b9b291e0cec0d4b33cef16c734a41926dacf498a7c56b1ac9701b1c067d3f09
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / pydantic_filters-0.4.0-py3-none-any.whl

Download URL pydantic_filters-0.4.0-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ae2c04e1823f46502bb47d5724592f46e30895afbc58bd7abb11e30c934d14a
BLAKE2b-256 checksum
How to use checksums
8d2e041b3c15b0b856f55469dac3c2a6982f25d1ce98a94b30a8a97a2dd69256
Upload date
Uploaded using Trusted Publishing?
What is 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}

Security for pydantic-filters 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page