traceme


Nametraceme JSON
Version 0.6.0 PyPI version JSON
download
home_pageNone
SummaryPython debug and tracer library
upload_time2024-05-25 16:20:58
maintainerNone
docs_urlNone
authorDag Brattli
requires_python<4.0,>=3.10
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # traceme

Is a `structlog` helper library that helps you to debug and trace your
code. It aims to replace `print` debugging with a more powerful and
permanent solution.

## Installation

```bash
pip install traceme
```

## Usage

```python
import math
from collections.abc import Callable

import structlog

import traceme


logger = structlog.get_logger()

@traceme.info(exit=True)
def add(a: int, b: int, cont: Callable[[int], None]) -> None:
    cont(a + b)


@traceme.info(exit=True)
def square(a: int, cont: Callable[[int], None]) -> None:
    cont(a * a)


@traceme.info(exit=True)
def sqrt(a: int, cont: Callable[[int], None]) -> None:
    cont(int(math.sqrt(a)))


@traceme.info(exit=True)
def pythagoras(a: int, b: int, cont: Callable[[int], None]) -> None:
    square(
        a,
        lambda a2: square(
            b,
            lambda b2: add(
                a2,
                b2,
                lambda a2b2: sqrt(
                    a2b2,
                    cont,
                ),
            ),
        ),
    )


if __name__ == "__main__":
    traceme.configure()

    pythagoras(3, 4, lambda result: logger.info("The result is", result=result))
```

This will output:

```bash
❯ poetry run python tests/test_pythagoras.py
```

<img width="977" alt="Screenshot 2024-05-25 at 12 02 27" src="https://github.com/dbrattli/traceme/assets/849479/9a435fe0-fd73-4c62-b55b-e84983402b86">


Switching `traceme` to `Environment.PRODUCTION` will remove all the indentation.

```python
traceme.configure(Environment.PRODUCTION)
```

```json
{"event": "pythagoras", "timestamp": "2024-05-25T09:49:09.802510Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.802929Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.802991Z", "level": "info"}
{"event": "add", "timestamp": "2024-05-25T09:49:09.803050Z", "level": "debug"}
{"event": "sqrt", "timestamp": "2024-05-25T09:49:09.803101Z", "level": "info"}
{"result": 5, "event": "The result is", "timestamp": "2024-05-25T09:49:09.803147Z", "level": "debug"}
{"event": "sqrt", "timestamp": "2024-05-25T09:49:09.803200Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.803248Z", "level": "info"}
{"event": "square", "timestamp": "2024-05-25T09:49:09.803291Z", "level": "info"}
{"event": "pythagoras", "timestamp": "2024-05-25T09:49:09.803335Z", "level": "info"}
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "traceme",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "Dag Brattli",
    "author_email": "dag@brattli.net",
    "download_url": "https://files.pythonhosted.org/packages/ed/79/816ff26828bbdbfc71238327032d8ae78f29226c2e1be65ab09874451c62/traceme-0.6.0.tar.gz",
    "platform": null,
    "description": "# traceme\n\nIs a `structlog` helper library that helps you to debug and trace your\ncode. It aims to replace `print` debugging with a more powerful and\npermanent solution.\n\n## Installation\n\n```bash\npip install traceme\n```\n\n## Usage\n\n```python\nimport math\nfrom collections.abc import Callable\n\nimport structlog\n\nimport traceme\n\n\nlogger = structlog.get_logger()\n\n@traceme.info(exit=True)\ndef add(a: int, b: int, cont: Callable[[int], None]) -> None:\n    cont(a + b)\n\n\n@traceme.info(exit=True)\ndef square(a: int, cont: Callable[[int], None]) -> None:\n    cont(a * a)\n\n\n@traceme.info(exit=True)\ndef sqrt(a: int, cont: Callable[[int], None]) -> None:\n    cont(int(math.sqrt(a)))\n\n\n@traceme.info(exit=True)\ndef pythagoras(a: int, b: int, cont: Callable[[int], None]) -> None:\n    square(\n        a,\n        lambda a2: square(\n            b,\n            lambda b2: add(\n                a2,\n                b2,\n                lambda a2b2: sqrt(\n                    a2b2,\n                    cont,\n                ),\n            ),\n        ),\n    )\n\n\nif __name__ == \"__main__\":\n    traceme.configure()\n\n    pythagoras(3, 4, lambda result: logger.info(\"The result is\", result=result))\n```\n\nThis will output:\n\n```bash\n\u276f poetry run python tests/test_pythagoras.py\n```\n\n<img width=\"977\" alt=\"Screenshot 2024-05-25 at 12 02 27\" src=\"https://github.com/dbrattli/traceme/assets/849479/9a435fe0-fd73-4c62-b55b-e84983402b86\">\n\n\nSwitching `traceme` to `Environment.PRODUCTION` will remove all the indentation.\n\n```python\ntraceme.configure(Environment.PRODUCTION)\n```\n\n```json\n{\"event\": \"pythagoras\", \"timestamp\": \"2024-05-25T09:49:09.802510Z\", \"level\": \"info\"}\n{\"event\": \"square\", \"timestamp\": \"2024-05-25T09:49:09.802929Z\", \"level\": \"info\"}\n{\"event\": \"square\", \"timestamp\": \"2024-05-25T09:49:09.802991Z\", \"level\": \"info\"}\n{\"event\": \"add\", \"timestamp\": \"2024-05-25T09:49:09.803050Z\", \"level\": \"debug\"}\n{\"event\": \"sqrt\", \"timestamp\": \"2024-05-25T09:49:09.803101Z\", \"level\": \"info\"}\n{\"result\": 5, \"event\": \"The result is\", \"timestamp\": \"2024-05-25T09:49:09.803147Z\", \"level\": \"debug\"}\n{\"event\": \"sqrt\", \"timestamp\": \"2024-05-25T09:49:09.803200Z\", \"level\": \"info\"}\n{\"event\": \"square\", \"timestamp\": \"2024-05-25T09:49:09.803248Z\", \"level\": \"info\"}\n{\"event\": \"square\", \"timestamp\": \"2024-05-25T09:49:09.803291Z\", \"level\": \"info\"}\n{\"event\": \"pythagoras\", \"timestamp\": \"2024-05-25T09:49:09.803335Z\", \"level\": \"info\"}\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python debug and tracer library",
    "version": "0.6.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fd523cea560f9b5d6b6ec9f14f20fd2d76c94053678ef80f7e94f0acf77634ff",
                "md5": "bd5af2c0880eae8fb9829f8c3241052e",
                "sha256": "1fb8ee6a24e037ccd7f4f41ac62c3d3e01bee0e47f7827306d2d21105fc885a1"
            },
            "downloads": -1,
            "filename": "traceme-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bd5af2c0880eae8fb9829f8c3241052e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 5890,
            "upload_time": "2024-05-25T16:20:56",
            "upload_time_iso_8601": "2024-05-25T16:20:56.260179Z",
            "url": "https://files.pythonhosted.org/packages/fd/52/3cea560f9b5d6b6ec9f14f20fd2d76c94053678ef80f7e94f0acf77634ff/traceme-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ed79816ff26828bbdbfc71238327032d8ae78f29226c2e1be65ab09874451c62",
                "md5": "c77c95abf6bea967b3ddd91364dadc3e",
                "sha256": "d3a9f4155d6c4100748d603b39f55891db1cb5bf857c32d7adeca8547600b3c8"
            },
            "downloads": -1,
            "filename": "traceme-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "c77c95abf6bea967b3ddd91364dadc3e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 5301,
            "upload_time": "2024-05-25T16:20:58",
            "upload_time_iso_8601": "2024-05-25T16:20:58.085626Z",
            "url": "https://files.pythonhosted.org/packages/ed/79/816ff26828bbdbfc71238327032d8ae78f29226c2e1be65ab09874451c62/traceme-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-25 16:20:58",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "traceme"
}
        
Elapsed time: 0.31903s