Skip to main content

Tools for routine tasks

Project description

Configuration

Constants and valiables

export CONFIG='/path/to/base_config.yaml;/path/to/config.yaml'
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

export CONFIG='/path/to/base_log_config.yaml;/path/to/logging.yaml'
from ttutils import LoggingConfig

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

Safe type convertors

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'

safe_text('<b>text</b>') == '&lt;b&gt;text&lt;/b&gt;'
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

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]}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttutils-0.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttutils-0.2-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file ttutils-0.2.tar.gz.

File metadata

  • Download URL: ttutils-0.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.6

File hashes

Hashes for ttutils-0.2.tar.gz
Algorithm Hash digest
SHA256 69f9d00ecf8218f88617d35ae3b9f5c1b9cf0aebd1bb450e1eb38c5410c49b83
MD5 402ce44b9b10ca3020453c22635f37a3
BLAKE2b-256 a1fdf13754c58f3d27460461d769d9af3449c60bccec5d48c3642d2e431a73d3

See more details on using hashes here.

File details

Details for the file ttutils-0.2-py3-none-any.whl.

File metadata

  • Download URL: ttutils-0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.6

File hashes

Hashes for ttutils-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88086a782692ca9c0411b433a81a9f9c1dcdfd68d662d4899da4c1a37ffd0382
MD5 4686cd4e78fc7fa17cb5f06a49efdfe5
BLAKE2b-256 480f6da99598c3f22a44906d174332302fbfa8f5e5bdb87074f869d8aaf34853

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page