Tools ===== There are two main tools of interest in circuits. These are: - :py:func:`circuits.tools.inspect` - :py:func:`circuits.tools.graph` These can be found in the :py:mod:`circuits.tools` module. Introspecting your Application ------------------------------ The :py:func:`~circuits.tools.inspect` function is used to help introspect your application by displaying all the channels and events handlers defined through the system including any additional meta data about them. Example: .. code:: pycon >>> from circuits import Component >>> class App(Component): ... def foo(self): ... pass ... >>> app = App() >>> from circuits.tools import inspect >>> print(inspect(app)) Components: 0 Event Handlers: 3 unregister; 1 foo; 1 prepare_unregister_complete; 1 ][prepare_unregister_complete] (App._on_prepare_unregister_complete)> Displaying a Visual Representation of your Application ------------------------------------------------------ The :py:func:`~circuits.tools.graph` function is used to help visualize the different components in your application and how they interact with one another and how they are registered in the system. In order to get a image from this you must have the following packages installed: - `networkx `_ - `pygraphviz `_ - `matplotlib `_ You can install the required dependencies via:: pip install matplotlib networkx pygraphviz Example: .. code:: pycon >>> from circuits import Component, Debugger >>> from circuits.net.events import write >>> from circuits.net.sockets import TCPServer >>> >>> class EchoServer(Component): ... def init(self, host="0.0.0.0", port=8000): ... TCPServer((host, port)).register(self) ... Debugger().register(self) ... def read(self, sock, data): ... self.fire(write(sock, data)) ... >>> server = EchoServer() >>> >>> from circuits.tools import graph >>> print(graph(server)) * * * An output image will be saved to your current working directory and by called ``.png`` where **** is the name of the top-level component in your application of the value you pass to the ``name=`` keyword argument of ``~circuits.tools.graph``. Example output of `telnet Example `_: .. image:: ../examples/Telnet.png And its DOT Graph: .. graphviz:: ../examples/Telnet.dot