CircuitryLib is a Python library for creating, modelling various сircuit engineering system including output to LaTeX and graphical representations (digital logic circuits for now).
Switch branches/tags
Nothing to show
Clone or download


A Python library for creating and modelling various сircuit engineering systems (digital logic circuits for now).

Author: The Profitware Group / Sergey Sobko

The code is mainly written as a part of my very special coursework at Moscow Institute of Electronics and Mathematics (MIEM HSE).


This library provides interface for creating and modelling various сircuit engineering systems (digital logic circuits for now). It provides output to LaTeX, graphical representations, graphs and MATLAB code that generates Simulink models. It works with Python version 2.7. Other versions are not tested yet.


From source:

Install the dependencies:

Alternatively use pip:

$ pip install -r requirements.txt

Getting the code

The code is hosted at GitHub.

Check out the latest development version anonymously with:

 $ git clone git://
 $ cd circuitrylib


The library provides classes for circuitry elements: basic digital logic gates and devices like multiplexers and adders. It also supports output to LaTeX. Graphical output is planned.

Web interface named CircuitryLib-web may be found here.

Implemented devices:

  • devices.simple.DeviceNot - NOT logic gate (inverter)
  • devices.simple.DeviceAnd - AND logic gate (logical conjunction)
  • devices.simple.DeviceOr - OR logic gate (logical disjunction)
  • devices.mux.DeviceMux - MUX (multiplexer)
  • devices.mux.DeviceMuxStrict - Strict multiplexer (sum of data minterms)
  • devices.mux.DeviceDemux - DEMUX (demultiplexer)
  • devices.adder.DeviceAdd - Adder
  • devices.adder.DeviceInc - Increment
  • devices.adder.DeviceDec - Decrement
  • devices.adder.Device12Comp - Ones' complement to two's complement
  • devices.adder.Device21Comp - Two's complement to ones' complement
  • devices.adder.DeviceNeg - Two's complement negation
  • devices.cmp.DeviceEq - Equality device
  • devices.cmp.DeviceCmp - Digital comparator device

Implemented adapters

  • adapters.console.ConsoleTruthTableAdapter - Simple text truth table output
  • adapters.console.TwosComplementConsoleTruthTableAdapter - Twos' complement truth table
  • adapters.graph.GraphAdapter - Graphs. Default method returns graphical representation
  • adapters.latex.LatexTruthTableAdapter - LaTeX truth table
  • adapters.latex.mux.DeviceMuxLatexTruthTableAdapter - LaTeX truth table for MUX and DEMUX devices
  • adapters.matlab.MatlabAdapter - MATLAB code generation
  • adapters.matlab.extended.ExtendedMatlabAdapter - MATLAB code generation w/ constant sources and sinks
  • adapters.visual.symbol.ElectronicSymbolAdapter - Electronic symbol graphical representation

Multiplexer example:

First import necessary modules:

>>> from circuitry.devices.mux import DeviceMux
>>> from circuitry.adapters.latex.mux import DeviceMuxLatexTruthTableAdapter
>>> from circuitry.adapters.matlab.extended import ExtendedMatlabAdapter
>>> from circuitry.adapters.visual.symbol import ElectronicSymbolAdapter

To create multiplexer device with two strobe signal slots, three address signal slots, eight data signal slots and one straight output signal slot:

>>> device_mux = DeviceMux(strobe_signals='v:2',
                           strobe_signals_subs=dict(v0=1, v1=0),

To create truth table for multiplexer and output it to LaTeX:

>>> device_mux_latex_truth_table = DeviceMuxLatexTruthTableAdapter(device_mux)
>>> print (r'\begin{tabular}{%(latex_columns)s}\\\hline\\%(latex_columns_names)s\\' +
           r'\hline\\%(latex_table)s\hline\\\end{tabular}') % \
        {'latex_columns': device_mux_latex_truth_table.latex_columns,
         'latex_columns_names': device_mux_latex_truth_table.latex_columns_names,
         'latex_table': device_mux_latex_truth_table.latex_table}

To show electronic symbol for multiplexer:

>>> ElectronicSymbolAdapter(device_mux)

To produce MATLAB code that generates Simulink model:

>>> mux_schematics = ExtendedMatlabAdapter(device_mux)
>>> print '\n'.join(mux_schematics.matlab_code())

Adder example:

To create adder device with one strobe signal slot, augend of 4 slots, addend of 4 slots and output of 6 slots (4 bits + OF + OF for two's complement):

>>> from circuitry.devices.adder import DeviceAdd
>>> device_adder = DeviceAdd(strobe_signals='v:1',


Patches and bug reports are welcome, just please keep the style consistent with the original source.

To be implemented in further releases:

  • Library of elements.
  • Analog devices.
  • Timing and simulation.
  • Graphical output.
  • Documentation and tests.