bellapy
BellaPy - A useful helper for any python program
Contents
Setup
pip install bella
git clone https://github.com/ndaidong/bellapy.git
cd bellapy
python3 setup.py install
Usage
from bella import genid, md5
genid()
genid(5)
md5('hello')
APIs
Datatype detection
- is_int(val: Any)
- is_float(val: Any)
- is_num(val: Any)
- is_str(val: Any)
- is_bool(val: Any)
- is_list(val: Any)
- is_dict(val: Any)
- is_valid_url(val: Any)
Encryption
md5(text: str)
md160(text: str)
sha256(text: str, salt: str, dkpower: int = 3, iterations: int = 50000)
Examples:
md5('hello')
md160('hello')
sha256('1234', 'v23')
sha256('1234', 'v23', dkpower=4)
Date & time
PY_DATE_PATTERN
MY_DATE_PATTERN
get_time()
format_time(datetime, pattern)
get_local_time()
get_utc_time()
Examples
from bella import PY_DATE_PATTERN, format_time, get_time
now = get_time()
date_str = format_time(now, PY_DATE_PATTERN)
print(date_str)
Filesystem
from bella import fs
fs.exists(file_path: str)
fs.isdir(file_path: str)
fs.isfile(file_path: str)
fs.get_files(pattern)
fs.copy(source, dest)
fs.remove(path)
Utils
genid(count: int = 16, prefix: str = '')
slugify(text: str)
strip_accents(text: str)
remove_tags(text: str)
truncate(text: str, maxlen: int)
plurialize(word: str = None, count: int = 1)
byte_to_text(bytesize: int, precision: int = 2)
write_json_to_file(file_path: str = '', data: dict = {})
read_json_from_file(file_path: str = '')
jprint(data: Any, sorting=True, identation=2)
throttle(seconds: int)
timing(name: str)
has_installed(package)
curry(func)
compose(functions)
pipe(functions)
Examples:
print(genid())
print(genid(5))
print(genid(10, 'id_'))
slugify('BellaPy - A useful helper for any python program')
slugify('Ngày hội “đám mây” của Amazon')
plurialize('leaf', 1)
plurialize('leaf', 2)
@throttle(5)
def fn(a):
print('No call multi times within 5 seconds')
print(a)
fn(1)
fn(2)
fn(3)
fn(4)
fn(5)
fn(6)
fn(7)
@timing('save_item')
def save_item(data):
write_json_to_file('./cache.json', data)
save_item(dict(name='Alice'))
Dev & Test
git clone https://github.com/ndaidong/bellapy.git
cd bellapy
poetry install
./run_test.sh
License
The MIT License (MIT)