{"id":18004687,"url":"https://github.com/polyvertex/coloration","last_synced_at":"2025-04-04T10:17:31.944Z","repository":{"id":62269943,"uuid":"559271114","full_name":"polyvertex/coloration","owner":"polyvertex","description":"Python library for terminal and logs coloring","archived":false,"fork":false,"pushed_at":"2022-11-04T07:17:33.000Z","size":62,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T17:07:45.160Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/polyvertex.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-29T15:39:43.000Z","updated_at":"2022-10-31T18:43:35.000Z","dependencies_parsed_at":"2023-01-23T02:16:07.867Z","dependency_job_id":null,"html_url":"https://github.com/polyvertex/coloration","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvertex%2Fcoloration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvertex%2Fcoloration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvertex%2Fcoloration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/polyvertex%2Fcoloration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/polyvertex","download_url":"https://codeload.github.com/polyvertex/coloration/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247157272,"owners_count":20893221,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T00:15:26.417Z","updated_at":"2025-04-04T10:17:31.919Z","avatar_url":"https://github.com/polyvertex.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"==========\ncoloration\n==========\n\nYet another Python library for terminal and logs coloring and styling using ANSI\nescape sequences (`ECMA-48`_).\n\nStandalone library, no extra dependency required.\n\nMain features:\n\n* file-like wrapper\n* ``logging.Handler`` class for automatically formatted and colored logs\n* regex-based highlighting\n* default behavior depends on whether output is written on a TTY\n* text and binary streams both supported everywhere possible\n\nExtra features:\n\n* pre-defined ANSI codes for colors and styling\n* auto-resetting of coloring and styling\n* auto-stripping of ANSI escape sequences before writing\n* Windows: easy enabling of VT100 emulation if needed\n* `NO_COLOR \u003chttps://no-color.org/\u003e`_ honored by default and overridable\n\n\nDemo\n====\n\n.. code-block::\n\n    python demos/hello.py\n\n\nYou should get a result similar to this:\n\n.. figure:: demos/hello.png\n    :align: center\n\n\nBy default, output format differs if you redirect output to a file::\n\n    Hello World! \\o/\n\n    2021-01-21 08:03:39.045 [1048] DEBUG Debug messages are suffixed with source info  \u003chello:56\u003e\n    2021-01-21 08:03:39.045 [1048] INFO Some informational message  \u003chello:57\u003e\n    2021-01-21 08:03:39.045 [1048] NOTICE A NOTICE has a slightly higher priority than an INFO message  \u003chello:58\u003e\n    2021-01-21 08:03:39.045 [1048] WARNING This is some test WARNING  \u003c- auto highlighted keyword  \u003chello:59\u003e\n    2021-01-21 08:03:39.045 [1048] ERROR And an ERROR message  \u003chello:60\u003e\n    2021-01-21 08:03:39.045 [1048] INFO This demo took 0.1 second to run  \u003chello:61\u003e\n\n\nCheck out ``demos/`` directory.\n\n\nUsage\n=====\n\n*coloration* can be installed from PyPI::\n\n    python -m pip install -U coloration\n\n\nHello World\n-----------\n\n.. code-block:: python\n\n    import coloration as color\n\n    # Wrap std streams and enable VT100 emulation if on Windows and if needed\n    color.init()\n\n    # coloration.cprint() works pretty much like print(), except it deals with\n    # coloration's AnsiCode objects and it resets attributes when done (colors\n    # and styling)\n    color.cprint(color.GREEN, \"Hello\", color.YELLOW, \"World!\")\n    color.cprint(\"This message is not colored\")\n\n\nColored Logging\n---------------\n\n.. code-block:: python\n\n    import coloration\n    import coloration.logging as logging\n\n    coloration.init()\n\n    logging.basicConfig(handlers=[logging.ColorationStreamHandler()])\n\n    logger = logging.getLogger()\n\n    logger.setLevel(logging.DEBUG)\n\n    logger.debug(\"Debug messages are suffixed with source info\")\n    logger.info(\"Some informational message\")\n    logger.notice(\"A NOTICE has a slightly higher priority than an INFO message\")\n    logger.warning(\"This is some test WARNING  \u003c- auto highlighted keyword\")\n    logger.error(\"And an ERROR message\")\n\n\nHighlighting\n------------\n\n.. code-block:: python\n\n    import coloration\n\n    coloration.init()\n\n    hl = coloration.DefaultHighlighter()\n\n    text = \"\"\"\n        Some keywords like False, True, None, DEBUG, INFO, NOTICE, WARNING, ERROR\n        and OK are automatically highlighted with default highlighter, as well as\n        UUIDs like 51605be1-b026-4bfe-8934-478092d04376, numbers like 123.4, IPv4\n        addresses like 192.168.0.1 (IPv6 addresses supported), HTTP verbs like GET\n        and POST, log marks like [i] and [+], and Python-like keyword-value pairs\n        like some_var=True.\n    \"\"\".rstrip()\n\n    text = hl(text)\n\n    print(text, end=\"\")\n\n\nLicense\n=======\n\nThis project is distributed under the terms of the MIT license.\nSee the `LICENSE.txt \u003cLICENSE.txt\u003e`_ file for details.\n\n\n.. _ECMA-48: https://www.ecma-international.org/publications-and-standards/standards/ecma-48/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvertex%2Fcoloration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpolyvertex%2Fcoloration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpolyvertex%2Fcoloration/lists"}