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)
Metadata
Release files for bella 2.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bella-2.1.6.tar.gz | 9.4 kB | Without provenance | Details for bella-2.1.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bella-2.1.6-py3-none-any.whl | Python 3 | none | any | Details for bella-2.1.6-py3-none-any.whl |
Total release size: 18.5 kB
Release files / bella-2.1.6.tar.gz
| Download URL | bella-2.1.6.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
eb57fe93320afe17e034c7a5c6154bdc6c77ed5c2d1d53bddc874a0fafeaaf00
|
|
BLAKE2b-256 checksum How to use checksums |
b46ed868dc94dc67604deb44b4d8551be7ca1821a80db8f068e33f027714dd07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.5 Linux/5.18.13-arch1-1
|
Release files / bella-2.1.6-py3-none-any.whl
| Download URL | bella-2.1.6-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eef35d86ad9de925160a04eeb0ded4e7c0675c036ab7c3f9c4e006efd5d8f209
|
|
BLAKE2b-256 checksum How to use checksums |
7368a31a36ff07cdd9081f27fc3da370528ee346c756e1da8d8a868af473c605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.14 CPython/3.10.5 Linux/5.18.13-arch1-1
|
Security for bella 2.1.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.