ttutils


Namettutils JSON
Version 0.9 PyPI version JSON
download
home_pageNone
SummaryTools for routine tasks
upload_time2025-08-21 06:40:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseApache-2.0
keywords configuration utils
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Python utils and configuration
==============================

Configuration
-------------

Constants and valiables

.. code-block:: bash

    export CONFIG='/path/to/base_config.yaml;/path/to/config.toml'


.. code-block:: python

    from ttutils import Config

    CFG = Config()

    CFG.PUBLIC_URL  # get from config files
    CFG.ENV.CONFIG  # get from os env
    CFG.SECRET.KEY  # get from os env and clean


Logging configuration

.. code-block:: bash

    export CONFIG='/path/to/base_log_config.yaml;/path/to/logging.toml'


.. code-block:: python

    from ttutils import LoggingConfig

    CFG = LoggingConfig({
        'loggers': {
            'aiohttp.access': {  # local overriding
                'level': 'ERROR',
            }
        }
    })


Safe type convertors
--------------------

.. code-block:: python

    from ttutils import try_int, as_bool, to_string, safe_text, text_crop, int_list, int_set

    try_int('123') == 123
    try_int('asd') is None

    as_bool('t') is True
    as_bool(1) is True
    as_bool('false') is False

    to_string(AClass) == '<AClass>'
    to_string('text') == 'text'
    to_string(b'text') == 'text'

    to_bytes('text') == b'text'
    to_bytes(b'text') == b'text'
    to_bytes(1234567890) == b'I\x96\x02\xd2'

    safe_text('<b>text</b>') == '&lt;b&gt;text&lt;/b&gt;'
    safe_text('text') == 'text'

    text_crop('text', 5) == 'text'
    text_crop('sometext', 6) == 'some …'

    int_list(['1', '2', 'a', 'b', None]) == [1, 2]
    int_set(['1', '2', 'a', 'b', None]) == {1, 2}


Compress
--------

Integer, dict integers, list integers compression/decompression functions

.. code-block:: python

    from ttutils import compress

    compress.encode(11232423)  # 'GSiD'
    compress.decode('GSi')  # 175506

    compress.encode_list([12312, 34535, 12323])  # '30o-8rD-30z'
    compress.decode_list('30o-8rD-30z--30C')  # [12312, 34535, 12323, 12324, 12325, 12326]

    compress.encode_dict({12: [234, 453], 789: [12, 98, 99, 100, 101]})  # 'c-3G-75/cl-c-1y--1B'
    compress.decode_dict('c-3G-75/cl-c-1y--1B')  # {12: [234, 453], 789: [12, 98, 99, 100, 101]}


DateTime
--------

Datetime parse and serialize utils

.. code-block:: python

    from ttutils import (utcnow, utcnow_ms, utcnow_sec, parsedt, parsedt_ms,
        parsedt_sec, try_parsedt, isoformat, safe_isoformat)

    utcnow()      # datetime(2022, 2, 22, 14, 28, 10, 158164, tzinfo=datetime.timezone.utc)
    utcnow_ms()   # datetime(2022, 2, 22, 14, 28, 20, 824000, tzinfo=datetime.timezone.utc)
    utcnow_sec()  # datetime(2022, 2, 22, 14, 28, 24, tzinfo=datetime.timezone.utc)

    parsedt('2022-02-22T11:22:33.123456Z')      # datetime(2022, 2, 22, 11, 22, 33, 123456, tzinfo=datetime.timezone.utc)
    parsedt_ms('2022-02-22T11:22:33.123456Z')   # datetime(2022, 2, 22, 11, 22, 33, 123000, tzinfo=datetime.timezone.utc)
    parsedt_sec('2022-02-22T11:22:33.123456Z')  # datetime(2022, 2, 22, 11, 22, 33, tzinfo=datetime.timezone.utc)

    try_parsedt('2022-02-22T11:22:33.123456Z')  # datetime(2022, 2, 22, 11, 22, 33, 123456, tzinfo=datetime.timezone.utc)
    try_parsedt(None)  # None

    isoformat(utcnow())      # '2022-02-22T14:33:51.381164Z'
    try_isoformat(utcnow())  # '2022-02-22T14:33:51.381164Z'
    try_isoformat(None)      # None


Concurrency
-----------

Tools for asyncio

To limit the parallelism of an asynchronous function, install a decorator

.. code-block:: python

    from ttutils import concurrency_limit

    @concurrency_limit(2)
    async def my_task(...) -> None:
        ...  # there are only 2 concurrent executions

    # the queue length will be recorded in the log when the function is overloaded
    log = logging.getLogger('concurrency_logger')

    @concurrency_limit(2, logger=log)
    async def my_task(...) -> None:
        ...  # there are only 2 concurrent executions

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "ttutils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "configuration, utils",
    "author": null,
    "author_email": "Dmitriy Vlasov <support@tamtamteam.com>",
    "download_url": "https://files.pythonhosted.org/packages/3c/fb/7ef516b39999b78b2b2cf76bbb0b92dff2069ae13cec67e96060a92dd1d1/ttutils-0.9.tar.gz",
    "platform": null,
    "description": "Python utils and configuration\n==============================\n\nConfiguration\n-------------\n\nConstants and valiables\n\n.. code-block:: bash\n\n    export CONFIG='/path/to/base_config.yaml;/path/to/config.toml'\n\n\n.. code-block:: python\n\n    from ttutils import Config\n\n    CFG = Config()\n\n    CFG.PUBLIC_URL  # get from config files\n    CFG.ENV.CONFIG  # get from os env\n    CFG.SECRET.KEY  # get from os env and clean\n\n\nLogging configuration\n\n.. code-block:: bash\n\n    export CONFIG='/path/to/base_log_config.yaml;/path/to/logging.toml'\n\n\n.. code-block:: python\n\n    from ttutils import LoggingConfig\n\n    CFG = LoggingConfig({\n        'loggers': {\n            'aiohttp.access': {  # local overriding\n                'level': 'ERROR',\n            }\n        }\n    })\n\n\nSafe type convertors\n--------------------\n\n.. code-block:: python\n\n    from ttutils import try_int, as_bool, to_string, safe_text, text_crop, int_list, int_set\n\n    try_int('123') == 123\n    try_int('asd') is None\n\n    as_bool('t') is True\n    as_bool(1) is True\n    as_bool('false') is False\n\n    to_string(AClass) == '<AClass>'\n    to_string('text') == 'text'\n    to_string(b'text') == 'text'\n\n    to_bytes('text') == b'text'\n    to_bytes(b'text') == b'text'\n    to_bytes(1234567890) == b'I\\x96\\x02\\xd2'\n\n    safe_text('<b>text</b>') == '&lt;b&gt;text&lt;/b&gt;'\n    safe_text('text') == 'text'\n\n    text_crop('text', 5) == 'text'\n    text_crop('sometext', 6) == 'some \u2026'\n\n    int_list(['1', '2', 'a', 'b', None]) == [1, 2]\n    int_set(['1', '2', 'a', 'b', None]) == {1, 2}\n\n\nCompress\n--------\n\nInteger, dict integers, list integers compression/decompression functions\n\n.. code-block:: python\n\n    from ttutils import compress\n\n    compress.encode(11232423)  # 'GSiD'\n    compress.decode('GSi')  # 175506\n\n    compress.encode_list([12312, 34535, 12323])  # '30o-8rD-30z'\n    compress.decode_list('30o-8rD-30z--30C')  # [12312, 34535, 12323, 12324, 12325, 12326]\n\n    compress.encode_dict({12: [234, 453], 789: [12, 98, 99, 100, 101]})  # 'c-3G-75/cl-c-1y--1B'\n    compress.decode_dict('c-3G-75/cl-c-1y--1B')  # {12: [234, 453], 789: [12, 98, 99, 100, 101]}\n\n\nDateTime\n--------\n\nDatetime parse and serialize utils\n\n.. code-block:: python\n\n    from ttutils import (utcnow, utcnow_ms, utcnow_sec, parsedt, parsedt_ms,\n        parsedt_sec, try_parsedt, isoformat, safe_isoformat)\n\n    utcnow()      # datetime(2022, 2, 22, 14, 28, 10, 158164, tzinfo=datetime.timezone.utc)\n    utcnow_ms()   # datetime(2022, 2, 22, 14, 28, 20, 824000, tzinfo=datetime.timezone.utc)\n    utcnow_sec()  # datetime(2022, 2, 22, 14, 28, 24, tzinfo=datetime.timezone.utc)\n\n    parsedt('2022-02-22T11:22:33.123456Z')      # datetime(2022, 2, 22, 11, 22, 33, 123456, tzinfo=datetime.timezone.utc)\n    parsedt_ms('2022-02-22T11:22:33.123456Z')   # datetime(2022, 2, 22, 11, 22, 33, 123000, tzinfo=datetime.timezone.utc)\n    parsedt_sec('2022-02-22T11:22:33.123456Z')  # datetime(2022, 2, 22, 11, 22, 33, tzinfo=datetime.timezone.utc)\n\n    try_parsedt('2022-02-22T11:22:33.123456Z')  # datetime(2022, 2, 22, 11, 22, 33, 123456, tzinfo=datetime.timezone.utc)\n    try_parsedt(None)  # None\n\n    isoformat(utcnow())      # '2022-02-22T14:33:51.381164Z'\n    try_isoformat(utcnow())  # '2022-02-22T14:33:51.381164Z'\n    try_isoformat(None)      # None\n\n\nConcurrency\n-----------\n\nTools for asyncio\n\nTo limit the parallelism of an asynchronous function, install a decorator\n\n.. code-block:: python\n\n    from ttutils import concurrency_limit\n\n    @concurrency_limit(2)\n    async def my_task(...) -> None:\n        ...  # there are only 2 concurrent executions\n\n    # the queue length will be recorded in the log when the function is overloaded\n    log = logging.getLogger('concurrency_logger')\n\n    @concurrency_limit(2, logger=log)\n    async def my_task(...) -> None:\n        ...  # there are only 2 concurrent executions\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Tools for routine tasks",
    "version": "0.9",
    "project_urls": null,
    "split_keywords": [
        "configuration",
        " utils"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "c3b27c55adb388aee0b79f24baf169fded08c52b095846c2adfd3c4f99d117c1",
                "md5": "01aad4aeefdd301567d974adbc876393",
                "sha256": "edafe217aa67ae3e2f64608b60d99cb97c62e583bdf040970c720a77f07bcb3d"
            },
            "downloads": -1,
            "filename": "ttutils-0.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "01aad4aeefdd301567d974adbc876393",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 13438,
            "upload_time": "2025-08-21T06:40:39",
            "upload_time_iso_8601": "2025-08-21T06:40:39.303663Z",
            "url": "https://files.pythonhosted.org/packages/c3/b2/7c55adb388aee0b79f24baf169fded08c52b095846c2adfd3c4f99d117c1/ttutils-0.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "3cfb7ef516b39999b78b2b2cf76bbb0b92dff2069ae13cec67e96060a92dd1d1",
                "md5": "36ae60b6ba396cfa4d51265233c8fce0",
                "sha256": "fc7abf02cbd244eabb440a71ad50edcf51a88f63f096c10f57e87e22d2cb2b9f"
            },
            "downloads": -1,
            "filename": "ttutils-0.9.tar.gz",
            "has_sig": false,
            "md5_digest": "36ae60b6ba396cfa4d51265233c8fce0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 18469,
            "upload_time": "2025-08-21T06:40:40",
            "upload_time_iso_8601": "2025-08-21T06:40:40.293679Z",
            "url": "https://files.pythonhosted.org/packages/3c/fb/7ef516b39999b78b2b2cf76bbb0b92dff2069ae13cec67e96060a92dd1d1/ttutils-0.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-21 06:40:40",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "ttutils"
}
        
Elapsed time: 1.36125s