Skip to main content

Python utility package

Project description

from xml.etree.ElementTree import indentfrom sys import prefix

Tools

Python Utility Tools Library

Startup Info

This module print in stdout general info at startup. Should be added at the beginning of the main program or where you need to display this information:

  • examples:

    from tools.startup_info import startup_info
    startup_info()
    

    result:

    --------------------------
    2020-11-12 13:14:15.678901
    User: DemoUser
    Host: DemoUser-PC
    OS Platform: Windows-10-10.0.19020-SP0
    Python Version: 3.11.2 (tags/v3.11.2:bffe2c1, Jan 08 2020, 10:12:11) [MSC v.1936 64 bit (AMD64)]
    Implementation: CPython
    -----------------------
    

Common

This module contains tools for general use.

Attribute Manager

This class contains methods for managing class attributes taking in consideration real mangled name of each attribute.

  • examples:
    from tools.common import AttributeManager
    
    class SomeClass:
        __slots__ = ('__private_attr', '_protected_attr', 'public_attr')
        ...
        def as_static(self, attr_name: str):
            mangled_name = AttributeManager.get_name(obj=self, attr=attr_name)
            print(f'attribute_mangled_name: {mangled_name}')
            #
            found = AttributeManager.has_attribute(obj=self, attr=attr_name)
            print(f'found: {found}')
            #
            if not found:
                AttributeManager.set_attribute(obj=self, attr=attr_name, value=None)
            #
            value = AttributeManager.get_attribute(obj=self, attr=attr_name)
            print(f'value: {value}')
            pass
            
        def as_instance(self, attr_name: str):
            attr = AttributeManager(obj=self, attr=attr_name)
            #
            mangled_name = attr.name
            print(f'attribute_mangled_name: {mangled_name}')
            #
            found = attr.exists
            print(f'found: {found}')
            #
            if not found:
                attr.value = None
            #
            value = attr.value
            print(f'value: {value}')
            pass
        ...
    pass
    
Hide Big Content

This method tries to hide big content over a limit of characters.

  • examples:
    from tools.common import hide_big_content
    
    content = {
        'key': 'value',
        'l': [1, 'a', 'b'],
        's': 'aaa',
        't': (1, 2, 'a' * 5000)
    }
    print(f'content: {content}')
    processed = hide_big_content(value=content)
    print(f'processed: {processed}')
    
Mask password

This method tries to mask passwords from provided object.

  • examples:
    from tools.common import mask_password
    
    content = [
        1, 2, True,
        {
            'password': '12345',
            'pwd': 'x56',
            'pwd_lst': ['123', '345', '567']
        }
    ]
    print(f'content: {content}')
    processed = mask_password(value=content)
    print(f'processed: {processed}')
    
Get Location

Try to resolve file / method location. Can be used for template relative location

  • examples:
    from tools.common import get_location
    
    def func(): pass
    
    func_location = get_location(func=func)
    print(f'func_location: {func_location}')
    
    file_location = get_location(file=__file__)
    print(f'file_location: {file_location}')
    

Folders

This module was created to manage main folder operations.

  • examples:
    from tools.folders import Folder
    
    path = 'path/to/folder'
    
    if not Folder.exists(path=path):
        Folder.create(path='path/to/old-folder', recursive=True)
        
    Folder.remove(path='path/to/new-folder', recursive=True)
    

Files

This module was created to perform main file operations.

  • examples:
    from tools.files import File
    
    path = 'path/to/file'
    name = 'file-name.ext'
    
    if not File.exists(path=path, name=name):
        File.write(path=path, name=name, content=None)
    
    demo = File.read(path=path, name=name)
    print(f'Demo file: {demo}')
    
    locked = File.lock(path=path, name=name)
    print('File is locked')
    
    try:
        File.write(path=path, name=name, content=b'new-content')
    except Exception as exc:
        print(f'Something got wrong: {exc}')
    
    File.unlock(file=locked)
    print('File is free to use')
    
    File.remove(path=path, name=name)
    

Tables

This module was created to store data as a table, with data / column validation and filtering. Cells can be accessed by index or by key.

  • examples:
    from tools.tables import Table
    
    table = Table(
        table={
            'columns': ['col-1', 'col-2'],
            'data': [
                # row-1
                {'col-1': 1, 'col-2': 2},
                # row-2
                {'col-1': True, 'col-2': 'str'}
            ]
        }
    )
    print(f'table: {table}')
    
    filtered_1 = table.filter(exclude=('col-1',))
    print(f'filtered_1: {filtered_1}')
    
    filtered_2 = table.filter(include=('col-2',))
    print(f'filtered_2: {filtered_2}')
    

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

ruth_tools-2022.1.0-cp313-cp313-win_amd64.whl (250.6 kB view details)

Uploaded CPython 3.13Windows x86-64

ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_i686.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ i686

ruth_tools-2022.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

ruth_tools-2022.1.0-cp313-cp313-macosx_11_0_arm64.whl (266.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ruth_tools-2022.1.0-cp312-cp312-win_amd64.whl (253.6 kB view details)

Uploaded CPython 3.12Windows x86-64

ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_i686.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ i686

ruth_tools-2022.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

ruth_tools-2022.1.0-cp312-cp312-macosx_11_0_arm64.whl (269.8 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ruth_tools-2022.1.0-cp311-cp311-win_amd64.whl (255.8 kB view details)

Uploaded CPython 3.11Windows x86-64

ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_i686.whl (1.4 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ i686

ruth_tools-2022.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

ruth_tools-2022.1.0-cp311-cp311-macosx_11_0_arm64.whl (269.9 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file ruth_tools-2022.1.0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ca364862b6bbf13385405698d1af25cbcf9759b465e2792420d2632ca866f26c
MD5 2361ccc497c5aba3ccb055e10512b156
BLAKE2b-256 e68070e5dc8169ea56fd646fc73a0f44f5624ad71b1d1050b8f3cb8419dc3b68

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 796bb972ad145a401db449875542f3434d3d84b8a243e3b428aecf9cfa29339f
MD5 8a85811939f08b1d1a67ddf5a145f011
BLAKE2b-256 4d3374ec625d326dc19590d10cc040f3848a72e50bc0971da2b2246b0187145b

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp313-cp313-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c4a09b8bc1a89281272fd6f09c386b38a3d2dde0f0416fe20dd70762451e5524
MD5 09dba05e085eb8592dde1ca74cdcee77
BLAKE2b-256 82f95ab350e0bb5336aa70e22fa21810df74bcc26731765a4959d83164469dc7

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1f2585501858406a3320c59f90d95c66b636b2ccd3cbce90421d82270f09dc8e
MD5 1c70314ab25f59ddc776a1cddb0b528e
BLAKE2b-256 4c298ccf15bc2e952067a4977f2e62281603511c90ea6b3ecedfedffa46e24e0

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c2fd92402ac60dbd37d27dddada2258c44c64d26c49d2cdc3975062797e081de
MD5 e672595842738caefaaa8864e804b2c2
BLAKE2b-256 f504cb7c34509dc46dd94d89c8c4f6ce3363bb4d9fd649030c33e1e30b3400a2

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 94ef2b51f0a6339ba0059abbf4bcc74e1a23e5f4a02142b8d1e21fcdf589e125
MD5 42285532c6fb2dbf0d8a27121e9b1699
BLAKE2b-256 58e034aa6f2b0ab36efdbf94d9420f28192b89c658dbce295059964728ed5194

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2107b28e37c2bfe0530af4608511fab5390bc187864d3c3e30cdcbfb71fe8ecc
MD5 e6505f754819a6f3fe5ddbe95fd0534e
BLAKE2b-256 466a3df1a366578d480e4d5f0761cdb6929c300ae3b770159e22a0cdbddd310f

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp312-cp312-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 837c2fabf41d4a7576539956a27b9341914239156979d271163726de27f406d0
MD5 59d4c74425d7b101146cd262583c38ba
BLAKE2b-256 0ecdf8232d161680ff1e7042cfcdc0c1422c0dc25a7805e0f3941ed73b5e91d7

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4889f6ca9c775c18ef1b42f1ab6d4271f125882d6e612279a12241ca50882952
MD5 cca529d70a5385d592305c8c35c6860c
BLAKE2b-256 49b0d54aea3e0507a07ca306b681ec243c5319299d9c10a3a7ddedb5a5d37b5c

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a77c0dd7f2d0611571b657b15e0c72501397a47f0826dcc177446a6fa4487002
MD5 e6e3f1567ab83436d03b3fbc5dbe9c0a
BLAKE2b-256 a8c36b4bcfb47dfdcc841352fcf48e5b44e0659b47fe11ca6e811b9fe70f7ea8

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 769443f81d9672eafd14d9808f38d731ef9ce54a4ad8fb562f1eac74fd719cf8
MD5 fad4971e0e51a1487d4e3377b84c2036
BLAKE2b-256 7b6faa08f91727d7cdbd55ec2951c782e339a3c1e05c35d6ca582bab19e6564d

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3e76b7d58e37afb5f590747cd1d429829f24aaaf6059758d35bca3747885e033
MD5 5982fe8c948bb96f5114a8930cbc31bb
BLAKE2b-256 9b5996508f0fb65067dc6a97bcbe5a216e7e9d8a94dde58e86a1dec75ec26cf2

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp311-cp311-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 ff8b09c57cc762976a99cbb23070533f1843a22196d0848808f11d642e3160ed
MD5 088f16729b2ad6099ee4c2c9768f078c
BLAKE2b-256 a8ccef21c0de9ea943cbf48f71fe2c91fcb7692f5e6214966265239ffba25eb5

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 00a7aa77052444d9aa9f7b1b47f32e9182f512874ec89386e075217d7c63b321
MD5 dcaa8668b28335305b7c31f1d7cc9f9b
BLAKE2b-256 774217e8f1dd027ffeb3221429e2db026b43fe0a92ee979d0659cb58e35d2158

See more details on using hashes here.

File details

Details for the file ruth_tools-2022.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ruth_tools-2022.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d2ca0c7039898d1def34539f42f9e1d118e421ae535f4ee0d8a97d127d0f7cc3
MD5 5443a88418535c34722f5a3393258def
BLAKE2b-256 8e6f17556510ea0df60403682b1ede51054404e4b0fdaf1b6456de0872bf2fec

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