SQLAlchemy filter converter
For what?
I made this package to use filters from query parameters in my applications.
Install
To install the package you need you run the following commands.
For pip:
pip install "sqlalchemy_filter_converter"
For poetry:
poetry add sqlalchemy_filter_converter
For PDM:
pdm add sqlalchemy_filter_converter
Filter Types
Converters for SQLAlchemy filters. Now available 3 converters:
- Simple filter converter (key-value with equals operator).
- Advanced filter converter (key-value with custom operators).
- Django filter converter (Django filters adapter with double underscore lookups).
Filters must be provided in a dict or list or dicts and will be applied sequentially.
Simple filters
Simple filters are simle. There are key - value dicts, which converts to SQLAlchemy
filters with == operator.
You can use one dict with all filters, or list of dicts. There is no difference.
from sqlalchemy_filter_converter import SimpleFilterConverter
filter_spec = [
{'field_name_1': 123, 'field_name_2': 'value'},
{'other_name_1': 'other_value', 'other_name_2': 123},
# ...
]
No other specific usages presents. it is simple.
Advanced filters
Advanced filters continues the idea of simple-filter, but add operator key.
{
"field": "my_field",
"value": 25,
"operator": ">",
}
or
[
{
"field": "my_id_field",
"value": [1,2,3,4,5],
"operator": "contains",
},
{
"field": "my_bool_field",
"value": False,
"operator": "is_not",
},
]
This is the list of operators that can be used:
=><>'<=isis_notbetweencontains
Django filters
Django filters implements django ORM adapter for filters. You can use filters like
my_field__iexact=25 or my_dt_field__date__ge=datetime.date(2023, 3, 12). See django
documentation for more information.
Now implements all field filters, except nester relationships.
This is the list of operators that can be used:
exactiexactcontainsicontainsingtgteltltestartswithistartswithendswithiendswithrangedateyeariso_yearmonthdayweekweek_dayiso_week_dayquartertimehourminutesecondisnullregexiregex
Release files for sqlalchemy_filter_converter 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sqlalchemy_filter_converter-1.4.0.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sqlalchemy_filter_converter-1.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.9 kB
Release files / sqlalchemy_filter_converter-1.4.0.tar.gz
| Download URL | sqlalchemy_filter_converter-1.4.0.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
274fdc7fb8ddde701e9694389cace9249be7ed9a302899c2265a143319f115a3
|
|
BLAKE2b-256 checksum How to use checksums |
e08809d4dd19a47f298cfa0e2f7b8f944c2d04ce6a4188ad434fafc81cd0a868
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.20.0.post1 CPython/3.12.7 Linux/6.11.5-arch1-1
|
Release files / sqlalchemy_filter_converter-1.4.0-py3-none-any.whl
| Download URL | sqlalchemy_filter_converter-1.4.0-py3-none-any.whl |
|---|---|
| Size | 17.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8b121b0959d0b664a4e48809ee169a840949866bf637554add9ff2496a05ef2
|
|
BLAKE2b-256 checksum How to use checksums |
8b9b0dec658c1cbcc9e105c4bac0c470f8e9d460a599660eca620a6420dbcb7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.20.0.post1 CPython/3.12.7 Linux/6.11.5-arch1-1
|