Skip to main content

Damogran Labs Python Tools

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

dlpt

Damogran Labs Python Tools, a collection of modules with utility functions to ease everyday Python usage.

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 get only folders 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.

What?

Paths, processes, loggers, JSON handlers, pytest fixtures, time utils, watchdog, ... Example:

import os
import time

import dlpt
import dlpt.log as log

LOG_FILE_NAME = "dlpt_example.log"

startTime = time.time()

# init default logger with console and file handler (file in <cwd>/log subfolder)
logger = log.LogHandler()
logger.addConsoleHandler()
logFilePath = logger.addFileHandler(LOG_FILE_NAME)
log.debug("Logger initialised...")

# search log file path
files = dlpt.pth.getFilesInFolderTree(os.getcwd())
for filePath in files:
    fileName = dlpt.pth.getName(filePath)
    if fileName == LOG_FILE_NAME:
        log.info(f"Log file found: {filePath}")
        break
else:
    log.error(f"Log file not found, expected in a default folder: '{log.DEFAULT_LOG_FOLDER_NAME}'")

# process example
pid = os.getpid()
executable = dlpt.proc.getExecutable(pid)
log.info(f"This process was run with python: {executable}")
args = dlpt.proc.getCmdArgs(pid)
log.info(f"\tArgs: {dlpt.utils.getListStr(args[1:])}")

# utils
endTime = time.time()
log.info(f"Example duration: {dlpt.time.secondsToString(endTime - startTime)}")

# close logger and remove log file
log.closeAllLoggers()
dlpt.pth.removeFile(logFilePath)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dlpt-1.0.1.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

dlpt-1.0.1-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

File details

Details for the file dlpt-1.0.1.tar.gz.

File metadata

  • Download URL: dlpt-1.0.1.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.2

File hashes

Hashes for dlpt-1.0.1.tar.gz
Algorithm Hash digest
SHA256 71e14f00e324756cc452d83a243f31bc7fdaa5666d81383de71003cc8e6d7171
MD5 7e1968fb5e5e7d48d2c56bcd05c4e302
BLAKE2b-256 1c72ea79ae8eb456d804242e0d1ed75bbed47b93760498a961b97047e1fac2cd

See more details on using hashes here.

File details

Details for the file dlpt-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: dlpt-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.8.2

File hashes

Hashes for dlpt-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31e4b048a90940ceffbde85fa2a3c759d20ac2a2465cb01e5ffbad76f74e204c
MD5 76e18c76458813066277969f2fe0acfa
BLAKE2b-256 790245416191e8667594b9ce91e07ab7530f8f525a962bd86ead928d2ecb2064

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page