dttb
DateTime TraceBack
A lightweight Python package that attaches timestamps to exception tracebacks, making it easier to debug and correlate errors with logs.
❌ Before:
Traceback (most recent call last):
...
Error: something wrong
✅ After:
[2026-01-28 14:30:15.123456+08:00]
Traceback (most recent call last):
...
Error: something wrong
Installation
- Python >= 3.8
uv
uv add dttb
pip
pip install dttb
Usage
Applying
demo1.py
import dttb
dttb.apply()
1 / 0
[2026-01-15 22:37:09.882049]
Traceback (most recent call last):
File "demo1.py", line 5, in <module>
1 / 0
ZeroDivisionError: division by zero
Resetting
demo2.py
import dttb
dttb.apply()
dttb.reset()
1 / 0
Traceback (most recent call last):
File "demo2.py", line 4, in <module>
1 / 0
ZeroDivisionError: division by zero
With logging
demo3.py
import dttb
import logging
dttb_logger = logging.getLogger("dttb")
dttb_logger.propagate = False
dttb_logger.setLevel(logging.ERROR)
file_handler = logging.FileHandler("logging.log")
file_handler.setFormatter(logging.Formatter("%(asctime)s | %(levelname)s | %(message)s"))
dttb_logger.addHandler(file_handler)
dttb.apply()
1 / 0
[2026-01-19 23:29:35.817684]
Traceback (most recent call last):
File "demo3.py", line 13, in <module>
1 / 0
ZeroDivisionError: division by zero
logging.log
2026-01-19 23:29:35,817 | ERROR | An uncaught exception logged by dttb:
[2026-01-19 23:29:35.817684]
Traceback (most recent call last):
File "demo3.py", line 13, in <module>
1 / 0
ZeroDivisionError: division by zero
With threading
demo4.py
import dttb
import threading
import time
dttb.apply()
def func(seconds):
time.sleep(seconds)
seconds / 0
thread1 = threading.Thread(target=func, kwargs={"seconds": 1})
thread2 = threading.Thread(target=func, kwargs={"seconds": 2})
thread1.start()
thread2.start()
thread1.join()
thread2.join()
func(seconds=3)
[2026-01-15 23:00:03.048290]
Exception in thread Thread-1:
Traceback (most recent call last):
...
File "demo4.py", line 10, in func
seconds / 0
ZeroDivisionError: division by zero
[2026-01-15 23:00:04.048362]
Exception in thread Thread-2:
Traceback (most recent call last):
...
File "demo4.py", line 10, in func
seconds / 0
ZeroDivisionError: division by zero
[2026-01-15 23:00:07.055083]
Traceback (most recent call last):
File "demo4.py", line 20, in <module>
func(seconds=3)
File "demo4.py", line 10, in func
seconds / 0
ZeroDivisionError: division by zero
Specifying Timezone
demo5.py
import datetime as dt
import dttb
dttb.apply(tz=dt.timezone.utc)
1 / 0
[2026-01-21 02:40:53.353001+00:00]
Traceback (most recent call last):
File "demo5.py", line 6, in <module>
1 / 0
ZeroDivisionError: division by zero
Setting Callback
demo6.py
import dttb
def callback(args: dttb.CallbackArgs) -> None:
print(f"[callback] {args.now = }")
print(f"[callback] {args.exc_type = }")
print(f"[callback] {args.exc_value = }")
print(f"[callback] {args.thread = } (None indicates the 'MainThread')")
dttb.apply(callback=callback)
1 / 0
[2026-01-29 10:31:29.469555]
Traceback (most recent call last):
File "demo6.py", line 13, in <module>
1 / 0
ZeroDivisionError: division by zero
[callback] args.now = datetime.datetime(2026, 1, 29, 10, 31, 29, 469555)
[callback] args.exc_type = <class 'ZeroDivisionError'>
[callback] args.exc_value = ZeroDivisionError('division by zero')
[callback] args.thread = None (None indicates the 'MainThread')
Metadata
Release files for dttb 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dttb-0.3.2.tar.gz | 4.5 kB | Without provenance | Details for dttb-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dttb-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for dttb-0.3.2-py3-none-any.whl |
Total release size: 9.9 kB
Release files / dttb-0.3.2.tar.gz
| Download URL | dttb-0.3.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6fb9681f47044981ce71cec9a4922bdc86099a68cf98321dbd6c923805b67eb
|
|
BLAKE2b-256 checksum How to use checksums |
18197ba501cb4100dd914dca272c90f59c205989b024d270bd0bcb0359c73fec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / dttb-0.3.2-py3-none-any.whl
| Download URL | dttb-0.3.2-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7a240b6d70fc080eb1803c737b12836e6a333ea183e5d0d41afee6dd5dfb40b9
|
|
BLAKE2b-256 checksum How to use checksums |
8903c6471a42a70d8eacdd1ad58946e5d329c425144861174154f18874257199
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.27 {"installer":{"name":"uv","version":"0.9.27","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for dttb 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.