python debugger tool with easy integration into any program
Project description
debuglib-py
python debugger tool with easy integration into any program
To install the development version use:
pip3 install git+https://github.com/utility-libraries/debuglib-py.git@dev#egg=debuglib[all]
Installation
pip install debuglib
pip install debuglib[all] # recommended
extra | description | client/server |
---|---|---|
debuglib[dev] |
better exceptions printing | client |
debuglib[orjson] |
for faster packing/unpacking | client/server |
debuglib[cli] |
required to run the CLI Debugger | server |
debuglib[all] |
installs all of the ones above | - |
Note: It's recommended to install all for the best debugging experience
Why are there extras?
There are two reasons why some dependencies are marked as extra.
1. Separation between script/program and debugger
Some 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 extras
2. To not overload the environment
The more dependencies your project has the likelier it is that version-conflicts arise or that your project gets to big.
debuglib
tries to avoid that by requiring as few dependencies as possible but offers support for various packages for a better debugging experience.
Examples
Note: 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: logging
code.py
import logging
from debuglib.logging import BlockingDebugHandler
logging.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))
except ValueError as error:
logging.error("failed to convert to integer", exc_info=error)
$ debuglib listen # and start code.py in another terminal
New Connection from 127.0.0.1 (localhost)
23:48:42.183558 | 127.0.0.1 | INFO | Hello World
23:48:42.184598 | 127.0.0.1 | ERROR | failed to convert to integer
--------------------------------------------------------------------------------
File "/home/<user>/code.py", line 12, in <module>
print(int(num))
└ 'Hi'
ValueError: invalid literal for int() with base 10: 'Hi'
================================================================================
Connection closed from 127.0.0.1 (localhost)
2: function monitoring
code.py
from debuglib.decorator import Decorator as DebugDecorator
# 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 connection
debugger = DebugDecorator()
@debugger.monitor()
def my_function(name: str = "World"):
print(f"Hello {name}")
my_function()
my_function("debuglib")
my_function(name="debuglib")
$ debuglib listen # and start code.py in another terminal
Listening on localhost:35353
New Connection from 127.0.0.1:43998 (localhost)
15:09:23.947665 | 127.0.0.1:43998 | INF | __main__.my_function() returned None after 6μs+803ns
15:09:23.947693 | 127.0.0.1:43998 | INF | __main__.my_function('debuglib') returned None after 2μs+234ns
15:09:23.947714 | 127.0.0.1:43998 | INF | __main__.my_function(name='debuglib') returned None after 2μs+405ns
Connection closed from 127.0.0.1:43998 (localhost)
crash-hook
in case your program crashes, and you want to know the reason, you can install the custom excepthook
with the shortcut
import debuglib.hook.install # noqa
...
or the alternative/manual installation
import debuglib.hook
...
debuglib.hook.hook()
$ debuglib listen # and start code.py in another terminal
New Connection from 127.0.0.1:41302 (localhost)
15:09:23.528303 | 127.0.0.1:41302 | ERR | sys.excepthook
File "/home/<user>/script.py", line 6, in <module>
raise RuntimeError("testing error")
RuntimeError: testing error
--------------------------------------------------------------------------------
Connection closed from 127.0.0.1:41302 (localhost)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file debuglib-0.1.0.tar.gz
.
File metadata
- Download URL: debuglib-0.1.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c70cd8e97784a1b1fc82e11fbc58b5753c8d072365376c80defb869d2e4541c6 |
|
MD5 | b6f2a67a1693b0bce383fc10aacad180 |
|
BLAKE2b-256 | b245a3af08fcbd7d37f0dd42a4daddf3a3d3953650c902ad726182c3f438489e |
File details
Details for the file debuglib-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: debuglib-0.1.0-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcaa376f74ea3fed26437a4a1755b029356cef341d5aa14b5a98ac468a0cd0b6 |
|
MD5 | 7517ec1c2f06939a1d3228799120c83e |
|
BLAKE2b-256 | 2fa10ed8e1c91babfbd958aeb696a25ca237bd5777569825a0952c208d9518d3 |