Name | ttutils JSON |
Version |
0.7
JSON |
| download |
home_page | None |
Summary | Tools for routine tasks |
upload_time | 2024-10-03 15:19:10 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | Apache-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>') == '<b>text</b>'
safe_text('text') == 'text'
text_crop('text', 5) == 'text'
text_crop('sometext', 5) == 'som …'
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
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/79/49/c75151ce1e4192b628443459310869e5fad30bbb093929e9ebe4a3f3baf5/ttutils-0.7.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>') == '<b>text</b>'\n safe_text('text') == 'text'\n\n text_crop('text', 5) == 'text'\n text_crop('sometext', 5) == 'som \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",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Tools for routine tasks",
"version": "0.7",
"project_urls": null,
"split_keywords": [
"configuration",
" utils"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "83e01e648080409df7f6ec69b753a9d1f500153ebc5721ddcbe36a4e7f656f01",
"md5": "0e84d1969e7f68d38c43cb12797237c0",
"sha256": "14c913b649ebca68ea7396310e9f293d260046c4cb6b44f2f5d2b221b7bf4fb7"
},
"downloads": -1,
"filename": "ttutils-0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0e84d1969e7f68d38c43cb12797237c0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 11595,
"upload_time": "2024-10-03T15:19:08",
"upload_time_iso_8601": "2024-10-03T15:19:08.898766Z",
"url": "https://files.pythonhosted.org/packages/83/e0/1e648080409df7f6ec69b753a9d1f500153ebc5721ddcbe36a4e7f656f01/ttutils-0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "7949c75151ce1e4192b628443459310869e5fad30bbb093929e9ebe4a3f3baf5",
"md5": "7f418aaeacd06b11b07373411862e8aa",
"sha256": "21d19fcc113de544058247c5794a17f837e5ba2558343f5df0d83389b0e3e64b"
},
"downloads": -1,
"filename": "ttutils-0.7.tar.gz",
"has_sig": false,
"md5_digest": "7f418aaeacd06b11b07373411862e8aa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 15725,
"upload_time": "2024-10-03T15:19:10",
"upload_time_iso_8601": "2024-10-03T15:19:10.849044Z",
"url": "https://files.pythonhosted.org/packages/79/49/c75151ce1e4192b628443459310869e5fad30bbb093929e9ebe4a3f3baf5/ttutils-0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-03 15:19:10",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "ttutils"
}