scim2-filter-parser (SFP) is a customizable Python library designed to parse and transpile SCIM 2.0 filter queries. It breaks down SCIM queries into tokens, constructs an Abstract Syntax Tree (AST), and can then convert this AST into other query languages, such as SQL WHERE clauses or Django Q objects. The library is currently at version 0.7.0 and is actively maintained.
pip install scim2-filter-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `scim2-filter-parser` to convert a SCIM filter string into a SQL WHERE clause and corresponding parameters. It highlights the use of `SQLQuery`, an `attribute_map` to link SCIM attributes to database columns, and optional `joins` for complex queries. The output provides a parameterized query suitable for execution with database connectors, emphasizing safe practices against SQL injection.
Always use the `SQLQuery.sql` output as the query string and `SQLQuery.params` as the separate sequence of parameters when executing with a database driver (e.g., `cursor.execute(sql_query, query_parameters)`).
Thoroughly review and test your `attribute_map` configuration to ensure SCIM attributes correctly map to your database tables and columns, including handling of complex attributes and multi-valued attributes.
For databases requiring different parameter placeholders, subclass `SQLQuery`:
`class CustomSQLQuery(SQLQuery):
placeholder = '?' # Or other required placeholder`For Django integration, import `from scim2_filter_parser.transpilers.django_q_object import get_query` and consult the GitHub README for usage examples with Django Q objects.
pip install scim2-filter-parser
Review and correct the SCIM filter string to ensure it strictly adheres to the SCIM 2.0 filter syntax specification.
Add `from scim2_filter_parser.transpiler import TranspilerType` to your script.
Pass a valid `TranspilerType` enum member, such as `TranspilerType.DJANGO_Q` or `TranspilerType.SQL`, to the `transpile` method.
No dependency data recorded yet.