CTX
----
[](https://gitlab.com/molcay/pyctx/commits/master)
[](https://gitlab.com/molcay/pyctx/commits/master)
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:
```python
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:
```json
{
"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
}
}
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pyctx",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "code_execution, context, ctx, log, request, request_context, timer",
"author": null,
"author_email": "\"M. Olcay TERCANLI\" <molcay@mail.com>",
"download_url": "https://files.pythonhosted.org/packages/9d/03/a31d641a20b9d8c440f953f1df1a755021c9b8aaaa584a37702ed45a2f0f/pyctx-0.1.10.tar.gz",
"platform": null,
"description": "CTX\n----\n\n[](https://gitlab.com/molcay/pyctx/commits/master)\n[](https://gitlab.com/molcay/pyctx/commits/master)\n\nContext package to use data between function calls, use timers and log it.\n\nFor 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:\n\n```python\nfrom pyctx.context import Context\n\nctx = Context('APP')\nx = 100\ny = (x + 1) * (x - 1)\nctx.log.set_data('isEven', y % 2)\nctx.log.set_data('y', y)\nctx.log.start_timer('timer1')\nimport time\n\ntime.sleep(1)\nctx.log.stop_timer('timer1')\nwith ctx.log.timeit('timer2_context_manager'):\n time.sleep(5)\n\nctx.finalize()\n```\n\n- As a return value of the `ctx.finalize()`, you will get python dictionary.\nYou can use any json serialization to convert the dictionary to string.\nHere is the above result:\n\n```json\n{\n \"type\": \"APP\",\n \"ctxId\": \"0fdecfe0-067e-4bdd-9920-3b7ed46d8a98\",\n \"startTime\": \"2019-08-06 09:42:31.222184\",\n \"endTime\": \"2019-08-06 09:42:37.236861\",\n \"data\": {\n \"isEven\": 1,\n \"y\": 9999\n },\n \"timers\": {\n \"timer1\": 1.00633,\n \"timer2_context_manager\": 5.002412\n }\n}\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Context package to use data between function calls, use timers and log it.",
"version": "0.1.10",
"project_urls": {
"Homepage": "https://github.com/molcay/pyctx",
"Issues": "https://github.com/molcay/pyctx/issues"
},
"split_keywords": [
"code_execution",
" context",
" ctx",
" log",
" request",
" request_context",
" timer"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c88ca5c7fac1bdaf45d2ec8b836a1972e77205b10f9182f69ccd8cdfeb603cb9",
"md5": "dc27b21d3597a8e1294e5e1310d3ec1c",
"sha256": "544d04051628b42477eb6b2cf50d69a280388d45cead413c1458d203620272d7"
},
"downloads": -1,
"filename": "pyctx-0.1.10-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dc27b21d3597a8e1294e5e1310d3ec1c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5721,
"upload_time": "2025-01-16T17:53:57",
"upload_time_iso_8601": "2025-01-16T17:53:57.718935Z",
"url": "https://files.pythonhosted.org/packages/c8/8c/a5c7fac1bdaf45d2ec8b836a1972e77205b10f9182f69ccd8cdfeb603cb9/pyctx-0.1.10-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "9d03a31d641a20b9d8c440f953f1df1a755021c9b8aaaa584a37702ed45a2f0f",
"md5": "d6734b1fdfe8aec762bb1db2d9b2d7fd",
"sha256": "4f093190331fac7111852b4867672671b176a0a479d1e018f85ab1639387d74d"
},
"downloads": -1,
"filename": "pyctx-0.1.10.tar.gz",
"has_sig": false,
"md5_digest": "d6734b1fdfe8aec762bb1db2d9b2d7fd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 17419,
"upload_time": "2025-01-16T17:53:58",
"upload_time_iso_8601": "2025-01-16T17:53:58.835253Z",
"url": "https://files.pythonhosted.org/packages/9d/03/a31d641a20b9d8c440f953f1df1a755021c9b8aaaa584a37702ed45a2f0f/pyctx-0.1.10.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-16 17:53:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "molcay",
"github_project": "pyctx",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"lcname": "pyctx"
}