skidl.part_query module

Functions for finding/displaying parts and footprints.

This module provides utilities to search for electronic parts and footprints across libraries, and to display their details. It includes support for regular expression searches and filtering on different properties.

class skidl.part_query.PartSearchDB(db_dir=None, db_name=None, tool=None)[source]

Bases: object

Manage a parts search SQLite database.

The DB contains two tables:
  • libraries(lib_file TEXT PRIMARY KEY, mtime REAL)

  • parts(id INTEGER PRIMARY KEY, part_name TEXT, lib_file TEXT, search_text TEXT)

The DB path is taken from skidl.config.part_search_db_dir. If that attribute is not present, defaults to the current directory.

add_lib(lib_path, tool=None)[source]

Parse the library file and insert parts into parts table. Update library mtime. lib_path should be an absolute path (or something SchLib can use). If the library is already in the database, then update it and all its parts.

add_libs(*lib_files)[source]

Add or replace libraries listed in lib_files (iterable of filenames). Each lib is added or updated in the libraries table and its parts are added or updated in the parts table.

close()[source]

Close the database connection.

load_from_lib_search_paths()[source]

Load all libraries from the current skidl.lib_search_paths for the current tool.

rmv_lib(lib_file)[source]

Remove a single library file and its parts from the database.

rmv_libs(*lib_files)[source]

Remove libraries listed in lib_files (iterable of filenames). Each lib and its parts are removed from the database.

search(query, limit=None)[source]

Search parts for the given query string. Supports quoted phrases and ‘|’ as OR.

Returns a list of (part_name, lib_file) tuples for matches.

update_libs()[source]

For every library recorded in the DB, compare filesystem mtime; if different, update.

skidl.part_query.search(terms, tool=None, fmt=None, file=None)

Print a list of parts with the regex terms within their name, alias, description or keywords.

Searches through all available libraries for parts matching the given terms and prints the results to the console.

Parameters:
  • terms (str) – Search terms separated by spaces (AND) or | (OR) to match against part attributes.

  • tool (str, optional) – The ECAD tool format for the libraries to search. Defaults to the currently configured tool.

  • fmt (str, optional) – A format string for displaying each part. Defaults to “{lib_name}: {part_name} ({description})”.

  • file (file-like object, optional) – The output stream to write results to. Defaults to sys.stdout.

Returns:

Results are printed to the console.

Return type:

None

skidl.part_query.search_footprints(terms, tool=None)[source]

Print a list of footprints with the regex term within their description/tags.

Searches through all available footprint libraries for footprints matching the given terms and prints the results to the console.

Parameters:
  • terms (str) – Space-separated search terms to match against footprint attributes.

  • tool (str, optional) – The ECAD tool format for the libraries to search. Defaults to the currently configured tool.

Returns:

Results are printed to the console.

Return type:

None

skidl.part_query.search_footprints_iter(terms, tool=None)[source]

Return an iterator over footprints that match the regex terms.

This generator function yields information about libraries being searched and footprints found that match the search terms.

Parameters:
  • terms (str) – Space-separated search terms to match against footprint attributes.

  • tool (str, optional) – The ECAD tool format for the footprint libraries to search. Defaults to the currently configured tool.

Yields:

tuple

Either progress information as (“LIB”, lib_name, index, total)

or footprint information as (“MODULE”, lib_name, module_text, module_name).

skidl.part_query.search_parts(terms, tool=None, fmt=None, file=None)[source]

Print a list of parts with the regex terms within their name, alias, description or keywords.

Searches through all available libraries for parts matching the given terms and prints the results to the console.

Parameters:
  • terms (str) – Search terms separated by spaces (AND) or | (OR) to match against part attributes.

  • tool (str, optional) – The ECAD tool format for the libraries to search. Defaults to the currently configured tool.

  • fmt (str, optional) – A format string for displaying each part. Defaults to “{lib_name}: {part_name} ({description})”.

  • file (file-like object, optional) – The output stream to write results to. Defaults to sys.stdout.

Returns:

Results are printed to the console.

Return type:

None

skidl.part_query.show(lib, part_name, tool=None)

Print the I/O pins for a given part in a library.

Creates a template Part object that can be inspected to see its pins and properties.

Parameters:
  • lib – Either a SchLib object or the name of a library.

  • part_name (str) – The name of the part in the library.

  • tool (str, optional) – The ECAD tool format for the library. Defaults to the currently configured tool.

Returns:

A template Part object if found, otherwise None.

Return type:

Part

skidl.part_query.show_footprint(lib, module_name, tool=None)[source]
skidl.part_query.show_part(lib, part_name, tool=None)[source]

Print the I/O pins for a given part in a library.

Creates a template Part object that can be inspected to see its pins and properties.

Parameters:
  • lib – Either a SchLib object or the name of a library.

  • part_name (str) – The name of the part in the library.

  • tool (str, optional) – The ECAD tool format for the library. Defaults to the currently configured tool.

Returns:

A template Part object if found, otherwise None.

Return type:

Part