BellaPy - A useful helper for any python program
Project description
bellapy
BellaPy - A useful helper for any python program
Contents
Setup
pip install bella
# or build from source
git clone https://github.com/ndaidong/bellapy.git
cd bellapy
python3 setup.py install
Usage
from bella import genid, md5
genid() # --> akrqHX7eQyT3neF6
genid(5) # --> xzxNK
md5('hello') # --> 5d41402abc4b2a76b9719d911017c592
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') # --> 5d41402abc4b2a76b9719d911017c592
md160('hello') # --> 108f07b8382412612c048d07d13f814118445acd
sha256('1234', 'v23') # --> 457b01a0f6169725
# dkpower relates to length of output, default is 3
# output length = 2 ** (dkpower + 1)
# for example with dkpower = 4 --> output length = 2 ** 5 = 32
sha256('1234', 'v23', dkpower=4) # --> 457b01a0f61697250083c598f7b8a8fd
Date & time
PY_DATE_PATTERN # '%Y-%m-%d %H:%M:%S %z'
MY_DATE_PATTERN # '%a, %b %d, %Y %H:%M:%S'
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)
# Get list of child files/folders by specific glob pattern
fs.get_files(pattern)
# Copy file or folder `source` into `dest`:
fs.copy(source, dest)
# Remove file or folder
fs.remove(path)
Utils
genid(count: int = 16, prefix: str = '') # return a random string
slugify(text: str) # create slug from a string
strip_accents(text: str) # remove accents string
remove_tags(text: str) # remove HTML tags from a string
truncate(text: str, maxlen: int) # cut a long string to shorter one
plurialize(word: str = None, count: int = 1) # return plural format of word
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) # decorator, make a function throttling
timing(name: str) # decorator, measure time to execute an expression
has_installed(package) # check if a python package is installed
curry(func) # make `func` become a curry function
compose(functions) # performs right-to-left function composition
pipe(functions) # performs left-to-right function composition
Examples:
print(genid()) # --> akrqHX7eQyT3neF6
print(genid(5)) # --> xzxNK
print(genid(10, 'id_')) # --> id_j0fpXAZ
slugify('BellaPy - A useful helper for any python program')
# --> bellapy-a-useful-helper-for-any-python-program
slugify('Ngày hội “đám mây” của Amazon')
# --> ngay-hoi-dam-may-cua-amazon
plurialize('leaf', 1) # => leaf
plurialize('leaf', 2) # => leaves
@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'))
# => Timing for save_item: 0.00134 s
Dev & Test
git clone https://github.com/ndaidong/bellapy.git
cd bellapy
poetry install
./run_test.sh
License
The MIT License (MIT)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bella-2.1.6.tar.gz
(9.4 kB
view details)
Built Distribution
bella-2.1.6-py3-none-any.whl
(9.1 kB
view details)
File details
Details for the file bella-2.1.6.tar.gz
.
File metadata
- Download URL: bella-2.1.6.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.18.13-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb57fe93320afe17e034c7a5c6154bdc6c77ed5c2d1d53bddc874a0fafeaaf00 |
|
MD5 | ce96878fc1c8f2702b4a5570bfff267c |
|
BLAKE2b-256 | b46ed868dc94dc67604deb44b4d8551be7ca1821a80db8f068e33f027714dd07 |
File details
Details for the file bella-2.1.6-py3-none-any.whl
.
File metadata
- Download URL: bella-2.1.6-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.14 CPython/3.10.5 Linux/5.18.13-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eef35d86ad9de925160a04eeb0ded4e7c0675c036ab7c3f9c4e006efd5d8f209 |
|
MD5 | 9b2ed04aba729d27cc3d06b2f4e5c902 |
|
BLAKE2b-256 | 7368a31a36ff07cdd9081f27fc3da370528ee346c756e1da8d8a868af473c605 |