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
}
}
Metadata
Release files for pyctx 0.1.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyctx-0.1.10.tar.gz | 17.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyctx-0.1.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.1 kB
Release files / pyctx-0.1.10.tar.gz
| Download URL | pyctx-0.1.10.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f093190331fac7111852b4867672671b176a0a479d1e018f85ab1639387d74d
|
|
BLAKE2b-256 checksum How to use checksums |
9d03a31d641a20b9d8c440f953f1df1a755021c9b8aaaa584a37702ed45a2f0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.20
|
Release files / pyctx-0.1.10-py3-none-any.whl
| Download URL | pyctx-0.1.10-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
544d04051628b42477eb6b2cf50d69a280388d45cead413c1458d203620272d7
|
|
BLAKE2b-256 checksum How to use checksums |
c88ca5c7fac1bdaf45d2ec8b836a1972e77205b10f9182f69ccd8cdfeb603cb9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.20
|