The catalogue submodule
Catalogue utilities for loading and searching component library data.
This module provides the Catalogue class, which loads one or more JSON libraries and offers query helpers to find matching libraries and records. Loaded data is stored in-memory as dictionaries keyed by library name.
Main capabilities:
load built-in and user-provided catalogue directories,
list or filter libraries by keyword expressions,
search records with logical and comparison criteria,
evaluate case-sensitive or case-insensitive matching.
Query model:
logical operators:
AND,OR,NOTgrouping with parentheses:
(...)comparison operators for record fields:
=,!=,<,<=,>,>=wildcard support for library keyword matching via
*
Typical workflow:
Create
Catalogue()and load data (default behavior at init).Use
findLibraries(...)to narrow candidate libraries.Use
searchInLibrary(...)to retrieve matching records.
Examples:
cat = Catalogue()
libs = cat.findLibraries('pump AND APV')
records = cat.searchInLibrary(
libs,
'T = centrifugal AND impeller0 = 110 AND speed0 = 2900'
)
The parser is intentionally lightweight and expression-oriented, which keeps catalogue searches readable while still supporting practical filtering logic.
- class fluidsolve.catalogue.Catalogue(**kwargs: int)[source]
Bases:
objectSearch one or more catalogues loaded from JSON files.
- Parameters:
path (list, optional) – List of paths where catalogues are found. These are appended to the built-in catalogue path.
load (bool, optional) – Load the catalogue data at init or not.
- Returns:
None
- loadAllData(buildin: bool = True) None[source]
Load all catalogue libraries.
- Parameters:
buildin (bool, optional) – Also load the built-in catalogues.
- findLibraries(criteria: str = '', matchcase: bool = True) list[source]
Find library names that match the given criteria.
- Parameters:
criteria (str) – Logical criteria expression. If empty, all libraries are returned. Parentheses, AND, OR, NOT, and * wildcards are supported.
matchcase (bool) – Whether matching is case-sensitive.
- Returns:
Matching library names.
- Return type:
list
Examples
lib = cat.findLibraries() lib = cat.findLibraries(‘APV’) lib = cat.findLibraries(‘appendage AND (bend OR BS-90) OR (DIN11852 AND BS-90)’)
- searchInLibrary(lib: str | list, criteria: str, matchcase: bool = True) list[dict][source]
Find records in one or more libraries matching the criteria.
- Parameters:
lib (str | list) – Library name or list of library names.
criteria (str) – Logical criteria expression.
matchcase (bool) – Whether matching is case-sensitive.
- Returns:
Matching records.
- Return type:
list[dict]
Examples
items = cat.searchInLibrary(lib, ‘OD < 20’) items = cat.searchInLibrary(lib, ‘WT >= 2 AND DN < 80’)
- _parseExpression(tokens: list) dict[source]
Parse a criteria expression represented as tokens.
A token can be a string literal or a value. Strings with spaces must be enclosed in single or double quotes. A token group can also be in the form field op value (for example: WT >= 2.4). Supported operators are AND, OR, NOT, and parentheses.
This method is used for both library-level and record-level criteria parsing.
- Parameters:
tokens (list) – The input tokens.
- Returns:
Parsed expression tree.
- Return type:
dict
Examples
_parseExpression([‘appendage’, ‘AND’, ‘bend’]) {‘AND’: [‘appendage’, ‘bend’]}
_parseExpression([‘WT’, ‘>=’, ‘2’, ‘AND’, ‘DN’, ‘<’, ‘80’]) {‘AND’: [‘WT >= 2’, ‘DN < 80’]}
- _evalLibExpression(expr: str, values: list, matchcase: bool = True) bool[source]
Evaluate a parsed expression against library metadata values.
- Parameters:
expr (str) – Parsed expression tree.
values (list) – Keywords to test against the expression.
matchcase (bool, optional) – Whether matching is case-sensitive.
- Returns:
True when the expression matches.
- Return type:
bool
- _evalRecExpression(expr: Any, rec: Any, matchcase: Any = True) Any[source]
Evaluate a parsed expression against a single record.
- Parameters:
expr (Any) – Parsed expression tree.
rec (Any) – Record dictionary to evaluate.
matchcase (bool, optional) – Whether matching is case-sensitive.
- Returns:
True when the record matches the expression.
- Return type:
bool