CTX
Context package to use data between function calls, use timers and log it.
For example; you want to have some decision points in your code, or you want to measure the time spent on a specific calculation or I/O operation:
from pyctx.context import Context
ctx = Context('APP')
x = 100
y = (x + 1) * (x - 1)
ctx.log.set_data('isEven', y % 2)
ctx.log.set_data('y', y)
ctx.log.start_timer('timer1')
import time
time.sleep(1)
ctx.log.stop_timer('timer1')
with ctx.log.timeit('timer2_context_manager'):
time.sleep(5)
ctx.finalize()
- As a return value of the
ctx.finalize(), you will get python dictionary. You can use any json serialization to convert the dictionary to string. Here is the above result:
{
"type": "APP",
"ctxId": "0fdecfe0-067e-4bdd-9920-3b7ed46d8a98",
"startTime": "2019-08-06 09:42:31.222184",
"endTime": "2019-08-06 09:42:37.236861",
"data": {
"isEven": 1,
"y": 9999
},
"timers": {
"timer1": 1.00633,
"timer2_context_manager": 5.002412
}
}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyctx-0.1.10.tar.gz
(17.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyctx-0.1.10.tar.gz.
File metadata
- Download URL: pyctx-0.1.10.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.5.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f093190331fac7111852b4867672671b176a0a479d1e018f85ab1639387d74d
|
|
| MD5 |
d6734b1fdfe8aec762bb1db2d9b2d7fd
|
|
| BLAKE2b-256 |
9d03a31d641a20b9d8c440f953f1df1a755021c9b8aaaa584a37702ed45a2f0f
|
File details
Details for the file pyctx-0.1.10-py3-none-any.whl.
File metadata
- Download URL: pyctx-0.1.10-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.5.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
544d04051628b42477eb6b2cf50d69a280388d45cead413c1458d203620272d7
|
|
| MD5 |
dc27b21d3597a8e1294e5e1310d3ec1c
|
|
| BLAKE2b-256 |
c88ca5c7fac1bdaf45d2ec8b836a1972e77205b10f9182f69ccd8cdfeb603cb9
|