Git Product home page Git Product logo

lk-utils's Introduction

LK Utils

lk-utils is a set of utilities to make data processing more simple and fluent.

Install

pip install lk-utils

lk-utils requires python 3.8 or higher version.

Usage

subproc

new thread decorator

from lk_utils import new_thread


def main(files: list[str]) -> None:
    for f in files:
        handle_file(f)


@new_thread()
def handle_file(file: str) -> None:
    # do something
    ...

fetch results from threads

from lk_utils import new_thread


def main(files: list[str]) -> None:
    pool = []
    for f in files:
        thread = handle_file(f)
        pool.append(thread)
    
    ...
    
    for thread in pool:
        result = thread.join()
        print(result)


@new_thread()
def handle_file(file: str) -> str:
    # do something
    ...

run cmd args

from lk_utils import run_cmd_args
from lk_utils import run_cmd_shell
run_cmd_args('python', '-m', 'pip', 'list')
run_cmd_shell('python -m pip list')

advanced filter:

from lk_utils import run_cmd_args


def pip_install(
        dest: str, 
        url_index: str = None
) -> None:
    run_cmd_args(
        ('python', '-m', 'pip'),
        ('install', '-r', 'requirements.txt'),
        ('-t', dest),
        ('-i', url_index),
    )

mklink, mklinks

from lk_utils import mklink, mklinks
mklink('/from_dir', '/to_dir_1')
mklinks('/from_dir', '/to_dir_2')

filesniff

get current dir, get relative path

import os
from lk_utils import filesniff as fs
print(fs.currdir() == os.path.dirname(__file__).replace('\\', '/'))  # -> True
print(fs.relpath('..') == os.path.dirname(fs.currdir()))  # -> True

list files/dirs

from lk_utils import filesniff as fs

for path, name in fs.find_files('.'):  # this is an generator.
    print(path, name)
    #   the first element is the **abspath**, the second is path's
    #   basename (<- os.path.basename(path))

for path in fs.find_file_paths('.'):  # this is a list[str]
    print(path)

for name in fs.find_file_names('.'):  # this is a list[str]
    print(name)

# more:
#   fs.findall_files
#   fs.findall_file_paths
#   fs.findall_file_names
#
#   fs.find_dirs
#   fs.find_dir_paths
#   fs.find_dir_names
#
#   fs.findall_dirs
#   fs.findall_dir_paths
#   fs.findall_dir_names

read_and_write

loads and dumps

from lk_utils import read_and_write as rw

data_r = rw.loads(file_i)
#   it recognizes json, yaml, pkl as sturctured data. others are treated as
#   plain text.

data_w = ...
rw.dumps(data_w, file_o)
#   it recognizes json, yaml, pkl as sturctured data. others are treated as
#   plain text.

below are marked as deprecated.

excel

excel reader and writer

from lk_utils import excel as exl

reader = exl.ExcelReader(file_i)
#   accepts '.xls' and '.xlsx' files.
...  # TODO:CompleteExample

writer = exl.ExcelWriter(file_o)
#   accepts only '.xlsx' files.
...  # TODO:CompleteExample
writer.save()

nlp

TODO

lk-utils's People

Contributors

likianta avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.