Package: debuglib
debuglib-pypython debugger tool with easy integration into any programTo install the development version use:pip3 install git+https://github.com/utility-libraries/debuglib-py.git@dev#egg=debuglib[all]Installationpipinstalldebuglib
pipinstalldebuglib[all]# recommendedextradescriptionclient/serverdebuglib[dev]better exceptions printingclientdebuglib[orjson]for faster packing/unpackingclient/serverdebuglib[cli]required to run the CLI Debuggerserverdebuglib[all]installs all of the ones above-Note: It's recommended to install all for the best debugging experienceWhy are there extras?There are two reasons why some dependencies are marked as extra.1. Separation between script/program and debuggerSome dependencies are only used for the client/script and some are only used by the debugger (CLI).
In case you have different environments for both the dependencies work over extras2. To not overload the environmentThe more dependencies your project has the likelier it is that version-conflicts arise or that your project gets to big.debuglibtries to avoid that by requiring as few dependencies as possible but offers support for various packages for a better debugging experience.ExamplesNote: there is no need for a server to run/exist.
That way you don't have to change anything when going into production
but would still have the option to monitor when errors occur.1: loggingcode.pyimportloggingfromdebuglib.loggingimportBlockingDebugHandlerlogging.basicConfig(level=logging.DEBUG,handlers=[BlockingDebugHandler()],# the following is also possible for tiny performance boost# handlers=[logging.NullHandler() if prod else BlockingDebugHandler()],)logging.info("Hello World")try:num="Hi"print(int(num))exceptValueErroraserror:logging.error("failed to convert to integer",exc_info=error)$debugliblisten# and start code.py in another terminalNewConnectionfrom127.0.0.1(localhost)23:48:42.183558|127.0.0.1|INFO|HelloWorld23:48:42.184598|127.0.0.1|ERROR|failedtoconverttointeger
--------------------------------------------------------------------------------File"/home/<user>/code.py",line12,in<module>print(int(num))└'Hi'ValueError:invalidliteralforint()withbase10:'Hi'================================================================================Connectionclosedfrom127.0.0.1(localhost)2: function monitoringcode.pyfromdebuglib.decoratorimportDecoratorasDebugDecorator# from debuglib.decorator import monitor  # shorthand if you only use it once# better performance than the single `monitor` decorator as everything# registered with debugger.monitor() shares the same connectiondebugger=DebugDecorator()@debugger.monitor()defmy_function(name:str="World"):print(f"Hello{name}")my_function()my_function("debuglib")my_function(name="debuglib")$debugliblisten# and start code.py in another terminalListeningonlocalhost:35353
NewConnectionfrom127.0.0.1:43998(localhost)15:09:23.947665|127.0.0.1:43998|INF|__main__.my_function()returnedNoneafter6μs+803ns15:09:23.947693|127.0.0.1:43998|INF|__main__.my_function('debuglib')returnedNoneafter2μs+234ns15:09:23.947714|127.0.0.1:43998|INF|__main__.my_function(name='debuglib')returnedNoneafter2μs+405ns
Connectionclosedfrom127.0.0.1:43998(localhost)crash-hookin case your program crashes, and you want to know the reason, you can install the custom excepthookwith the shortcutimportdebuglib.hook.install# noqa...or the alternative/manual installationimportdebuglib.hook...debuglib.hook.hook()$debugliblisten# and start code.py in another terminalNewConnectionfrom127.0.0.1:41302(localhost)15:09:23.528303|127.0.0.1:41302|ERR|sys.excepthookFile"/home/<user>/script.py",line6,in<module>raiseRuntimeError("testing error")RuntimeError:testingerror
--------------------------------------------------------------------------------
Connectionclosedfrom127.0.0.1:41302(localhost)