skidl.schlib module

Handles schematic libraries for various ECAD tools.

This module provides classes and functions for loading, managing, and accessing schematic component libraries from different ECAD tools.

class skidl.schlib.SchLib(filename=None, tool=None, lib_section=None, use_cache=True, use_pickle=True, **attribs)[source]

Bases: object

A class for storing parts from a schematic component library file.

This class loads and stores electronic components from library files. It provides methods to search, access, and manage the components in the library.

filename

The name of the file from which the parts were read.

Type:

str

parts

The list of parts (composed of Part objects) in the library.

Type:

list

_cache

Class variable that caches libraries for faster loading.

Type:

dict

Parameters:
  • filename (str, optional) – The name of the library file.

  • tool (str, optional) – The format of the library file (e.g., KICAD).

  • lib_section (str, optional) – The section of the library to access (for SPICE, only).

  • use_cache (bool, optional) – If true, use a cache of libraries to speed up loading.

  • use_pickle (bool, optional) – If true, pickle the library for faster loading next time.

Keyword Arguments:

attribs – Key/value pairs of attributes to add to the library.

add_parts(*parts)[source]

Add one or more parts to a library.

Parameters:

*parts – One or more Part objects to add to the library.

Returns:

The library with parts added.

Return type:

SchLib

Notes

Parts with the same name are not allowed in the library. A pointer to the library is placed in each added part.

export(libname, file_=None, tool=None, addtl_part_attrs=None)[source]

Export a library into a file.

Parameters:
  • libname (str) – A string containing the name of the library.

  • file (str or file object, optional) – The file the library will be exported to. It can either be a file object or a string or None. If None, the file will be the same as the library name with the library suffix appended.

  • tool (str, optional) – The CAD tool library format to be used. Currently, this can only be SKIDL.

  • addtl_part_attrs (list, optional) – List of additional part attribute names to include in export.

get_parts(use_backup_lib=True, **criteria)[source]

Return parts from a library that match all the given criteria.

Parameters:

use_backup_lib (bool, optional) – If True and no matches found in this library, search the backup library. Defaults to True.

Keyword Arguments:

criteria – One or more keyword-argument pairs. The keyword specifies the attribute name while the argument contains the desired value of the attribute.

Returns:

A list of Parts that match all the criteria.

Return type:

list

get_parts_by_name(name, be_thorough=True, allow_multiples=False, allow_failure=False, partial_parse=False)[source]

Return a Part with the given name or alias from the part list.

Parameters:
  • name (str) – The part name or alias to search for in the library.

  • be_thorough (bool, optional) – Do thorough search, not just simple string matching. Defaults to True.

  • allow_multiples (bool, optional) – If true, return a list of parts matching the name. If false, return only the first matching part and issue a warning if there were more than one. Defaults to False.

  • allow_failure (bool, optional) – Return None if no matches found. Issue no errors/warnings. Defaults to False.

  • partial_parse (bool, optional) – If true, don’t fully parse any parts that are found. Defaults to False.

Returns:

A list of Parts that match the name, or a single Part if only one match,

or None if no matches and allow_failure is True.

Return type:

Part or list

Raises:

ValueError – If no parts are found and allow_failure is False.

get_parts_quick(name)[source]

Do a quick search for a part name or alias.

Parameters:

name (str) – Part name or alias to search for.

Returns:

List of parts matching the name or alias.

Return type:

list

classmethod reset()[source]

Clear the cache of processed library files.

This clears the class’s internal cache of loaded libraries, which may be useful when reloading libraries or freeing memory.