Skip to main content

Libraries

Libraries are files that contain reusable functions. For example std.cst is the default standard library that provides the basic res, cap, net, etc. components.

tip

For large schematics, it is often easier to organize code into separate libraries.

Importing libraries

The import keyword is used to import libraries into the current file and there are 3 ways that the import keyword is used.

Import with library name

import "<libraryName>"

All functions are imported into the current file. The <libraryName> must be included when calling library functions.

import "std"

vcc = std.supply("5V")
gnd = std.dgnd()

at vcc
wire down 100
add std.res(10k)
wire down 100
to gnd
5VR110kGND

Named imports

from "<libraryName>" import <func1>, <func2> ...

Imports only specific named functions. The imported library functions are called directly without including the <libraryName>.

from "std" import supply, dgnd, res

vcc = supply("5V")
gnd = dgnd()

at vcc
wire down 100
add res(10k)
wire down 100
to gnd
5VR110kGND

Wildcard imports

from "<libraryName>" import *

This imports all functions within the library into the current function. The imported library functions are called directly without including the <libraryName>.

from "std" import *

vcc = supply("5V")
gnd = dgnd()

at vcc
wire down 100
add res(10k)
wire down 100
to gnd
5VR110kGND
tip

Named imports are preferred as it is easier to determine what functions are imported into the current code.

Library caching

Circuitscript automatically caches compiled libraries to improve performance on subsequent builds. When a library is imported for the first time, it is compiled and the results are stored in .cst.cache/ directories within your project.

This caching system provides several benefits:

  • Faster build times: Libraries are pre-compiled and don't need to be reprocessed on every build
  • Transitive import handling: All nested imports are cached together
  • Automatic invalidation: Caches are automatically regenerated when library files are modified
tip

You can safely add .cst.cache/ to your .gitignore file as these cache directories are automatically regenerated when needed.

note

The cache stores pre-compiled library functions and their dependencies. If you update a library file, the cache is automatically invalidated and regenerated on the next build.

Library refdes annotations

Circuits within libraries are also annotated and the refdes information can also be updated into the library automatically. For more information, please see this page.