Skip to main content

SQLAlchemy support for AIP-160 style filters

Project description

AIP-160 Filter Helper for SQLAlchemy

Usage

  from sqlalchemy import select
  from utils.aip160_filter import apply_filter

Basic filtering

 query = select(MyModel)
 filtered = apply_filter(query, MyModel, 'status = "active"')

Multiple conditions

  filtered = apply_filter(query, MyModel, 'status = "active" AND priority > 3')

OR conditions

  filtered = apply_filter(query, MyModel, 'status = "active" OR status = "pending"')

NOT operator

  filtered = apply_filter(query, MyModel, 'NOT status = "inactive"')

Wildcard pattern matching

  filtered = apply_filter(query, MyModel, 'name = "Widget*"')

Presence check (field is not null)

  filtered = apply_filter(query, MyModel, 'category:*')

Complex nested expressions

  filtered = apply_filter(
      query, MyModel,
      '(status = "active" OR status = "pending") AND priority >= 3'
  )

Restrict filterable fields for security

  filtered = apply_filter(
      query, MyModel, 'status = "active"',
      allowed_fields={"status", "priority"}  # Only these fields can be filtered
  )

Supported Features

Feature Example Notes
Equality status = "active" String, int, float, bool, UUID
Not equals status != "inactive"
Comparisons priority > 3, score <= 4.5 <, >, <=, >=
AND a = 1 AND b = 2 Explicit
Implicit AND a = 1 b = 2 Adjacent terms
OR a = 1 OR a = 2 Higher precedence than AND per AIP-160
NOT NOT status = "active" Also -status = "active"
Parentheses (a OR b) AND c
Wildcards name = "*.txt" Converted to SQL LIKE
Presence field:* Field is not null
Has value field:value Field equals value

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_aip160-0.1.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqlalchemy_aip160-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_aip160-0.1.3.tar.gz.

File metadata

  • Download URL: sqlalchemy_aip160-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","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

Hashes for sqlalchemy_aip160-0.1.3.tar.gz
Algorithm Hash digest
SHA256 1a32d31bad556a37ed4b913166f9ebea4b46447503acd99673eabe1f3d28fa27
MD5 55aeaa5f9ba446d7ed732e664bd4d1d6
BLAKE2b-256 64fa63f3ecaaba3f510afc5bb65d307b80b65102309d2848704aca377a04437c

See more details on using hashes here.

File details

Details for the file sqlalchemy_aip160-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sqlalchemy_aip160-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","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

Hashes for sqlalchemy_aip160-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 58aa7155eb2712c8293c172cc2570d26f89bdb30023be607a65ac9f2d870a7a1
MD5 af5dd956c2aa253289b3229a603e1d45
BLAKE2b-256 e2e975c7fc29b82f39e262cd18a2c6da4628d0468f46174ecfbf06d1e8b0352f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page