This project has been archived by its maintainers, and is no longer receiving any updates.
dlpt
Damogran Labs Python Tools, a collection of modules with utility functions to ease everyday Python
usage. It runs smoothly on windows, linux and mac-os.
Homepage: https://damogranlabs.com/2021/01/dlpt/
PyPi: https://pypi.org/project/dlpt/
Docs: https://dlpt.readthedocs.io/en/latest/
Install: pip install -U dlpt
Why?
This package main purpose is to stop reinventing the wheel on top of the built-in Python functions in every single project. Everyday struggle with:
- how do I initialize logger and add file handler?
- how do I temporary change current working directory?
- how do I spawn a subprocess and add stdout on any exception?
- how do I get only directories inside some location?
- how do I parse JSON file with comments?
- how do I format time to string in one line?
- how do I dynamically import some module that is not on a
sys.path? - ...
These and many more everyday Python code questions should be covered with this library. Nothing extra,
just simplified.
Mostly built upon standard built-in code, but with a lot more straight-forward and less cluttered API.
Modules
dlpt.pth: everything about paths and file/directory operations: list files/directories, copy/remove, get extensions, ...
dlpt.utils: everyhting we always need and never remember: list/dict comparison, values<->string transformation, module inspections, ...
dlpt.log: create new logger(s) and/or add common handlers (console/stream, file, ...) to any logger. Supports cross-process logging.
dlpt.proc: everything about common process use cases, but with more info on exceptions and easier straight-forward API.
dlpt.time: everything about time<->string transformation and code timing (timing decorator or special function wrapper)...
dlpt.json: read/write JSON files or python objects, with comments and smart pickling using jsonpickle library...
dlpt.importer: dynamically import python modules and inspect its object or call its functions/classes...
Examples:
How do I initialize logger and add file handler?
# init default logger with console and file handler (file in <cwd>/log sub-directory)
import dlpt
logger = dlpt.log.create_logger("my_logger")
dlpt.log.add_console_hdlr(logger)
hdlr, file_path = dlpt.log.add_file_hdlr(logger, "dlpt_example.log")
log.debug(f"Logger initialised, file: {file_path}")
How do I temporary change current working directory?
import os
import dlpt
print(f"Current working directory: {os.getcwd()}")
dir_path = os.path.join(os.getcwd(), "..", "..")
with dlpt.pth.ChangeDir(dir_path):
print(f"Current temporary working directory: {os.getcwd()}")
print(f"Current working directory: {os.getcwd()}")
How do I spawn a subprocess and add stdout on any exception?
import sys
import dlpt
# a valid subprocess
args = [sys.executable, "-c", "import dlpt; print(dlpt.utils.float_to_str(12324.5678))"]
proc = dlpt.proc.spawn_subproc(args)
print(proc.stdout) # will print '12324.57'
# invalid subprocess, will throw exception
args = [sys.executable, "-c", "throw exception"]
dlpt.proc.spawn_subproc(args)
How do I get only directories inside some location?
import dlpt
files = dlpt.pth.get_files_in_dir_tree(os.getcwd(), exclude_ext=[".pyc"])
for file_path in files:
print(f"File {dlpt.pth.get_name(file_path)}: {file_path}")
How do I parse JSON file with comments?
import dlpt
file_path = input("Enter a path to a JSON file with comments: ")
data = dlpt.json.read(file_path)
# alternatively, if file was created with `dlpt.json.writeJsonpickle()`, user can:
data = dlpt.json.read_jsonpickle(file_path)
How do I format time to string in one line?
import dlpt
# 2 days, 4 hours, 6 mins, 12 sec, 0.33 milliseconds
sec = dlpt.time.time_to_seconds(h=52, m=6, s=12.033)
end_time = dlpt.time.sec_to_str(duration_sec, dlpt.time.TIME_FORMAT_HMS_STRING)
print(end_time) # will print: '52 h 6 min 12.33 sec'
How do I dynamically import some module that is not on a
sys.path?
import dlpt
file_path = input("Enter a path to a python module that you wish to dynamically import: ")
importer = dlpt.importer.ModuleImporter(file_path)
print("Does module have an object with name 'myObject'? {importer.has_object('myObject')}")
# call a function of this module:
module = importer.get_module()
module.someFunction()
Metadata
Release files for dlpt 3.0.0
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 |
|---|---|---|---|---|
| dlpt-3.0.0.tar.gz | 25.9 kB | Without provenance | Details for dlpt-3.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dlpt-3.0.0-py3-none-any.whl | Python 3 | none | any | Details for dlpt-3.0.0-py3-none-any.whl |
Total release size: 55.6 kB
Release files / dlpt-3.0.0.tar.gz
| Download URL | dlpt-3.0.0.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a35859f8732271e235b28b90ebd75ac1816df6bef83e760af273b8d0d696d42
|
|
BLAKE2b-256 checksum How to use checksums |
9c2f6d781f63b8a269f63d1f5fec651f514369dbc148608795f3320fc7520316
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8
|
Release files / dlpt-3.0.0-py3-none-any.whl
| Download URL | dlpt-3.0.0-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0be177013576a1b414a9e6cb31150c0c822d5742c2b0f6a06209f1deed28a83f
|
|
BLAKE2b-256 checksum How to use checksums |
e45d58e039d8b7fd37609469720a04f3b9bc97b30e15d184931036cd9cf285d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8
|
Security for dlpt 3.0.0
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.