Skip to main content

Essential functions to be easily reused across Python projects.

Project description

Python Essentials

PyPI PyPI - Python Version

  • Easily create a logger enhanced with rich logging handler
  • Traceback formatting that you can easily following via rich Traceback
  • Non-blocking hotkey monitoring via keyboard (e.g. enable debug logging on the fly)

Example Usage

Installing

essentialsx is registered on pypi and can be installed via pip

pip install essentialsx

Basic Setup

from essentialsx import Essentials

essentials = Essentials()

Logging

A simple wrapper for creating a logger (uses built-in logging module) was created which also adds in the rich logging handler for a beautiful logging experience. A couple optional parameters exist for this wrapper:

Parameter Functionality
name The name space to use for the logger. Uses root by default.
logfile Creates a file handler at this path and logs entries to this file in addition to the console handler.
loglevel The loglevel to be used (INFO, DEBUG, WARNING, ERROR, CRITICAL). Uses INFO by default.
# Create a basic logger with console handler
log = essentials.get_logger()
log.info('Logging to console works!')

# Create a logger with log file handler
log = essentials.get_logger(logfile='/tmp/logfile.log')
log.info('Logging to console and file works!')

Hotkeys

There are a few wrapper functions for the keyboard hotkey functions, this is to help keep track of hotkeys in use which gives us the opportunity to provide some predefined hotkeys. Hotkeys will need to be registered via the register_hotkey() function and will not be active (including the predefined hotkeys) until the enable_hotkeys() function is called. To disable hotkeys once they have been enabled, simply call the disable_hotkeys() function.

Predefined Hotkeys

Hotkey Functionality
ctrl+alt+d Toggles debug log level
ctrl+alt+l Lists all registered hotkeys

Registering Hotkeys

# Register a function with no arguments
def foo():
    print('bar')

essentials.register_hotkey('ctrl+f', foo)
>> bar

# Register a function with arguments
def bar(baz):
    print(baz)

essentials.register_hotkey('ctrl+b', bar, args=('baz',))
>> baz

Note: Registered hotkeys aren't active until enable_hotkeys() is called.

Enabling / Disabling Hotkeys

# Enable all registered hotkeys
essentials.enable_hotkeys()

# Disable all enabled hotkeys
essentials.disable_hotkeys()

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

essentialsx-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

essentialsx-0.0.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file essentialsx-0.0.2.tar.gz.

File metadata

  • Download URL: essentialsx-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for essentialsx-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a999cef0a921804dcdd2b6ee59f09a9e24b4ffd013534e3ca84451f3afe3a772
MD5 1ea8e426ed5c74704ab6b915207d836f
BLAKE2b-256 55800f22d94ee5711234c42b95e57a41a0bf7b7269f615cce3ed9d19644c0c8c

See more details on using hashes here.

File details

Details for the file essentialsx-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: essentialsx-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.1

File hashes

Hashes for essentialsx-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 59d87d9e91227fcc54825610033e5d59d937721c3c2eea783fab2494b9caabcc
MD5 f0eedca1a634942ba1f9ed3cd469529a
BLAKE2b-256 69e462517fc3f699e98caf6d561a12ebc4d0a1cef7b5c600603ac024cd2a40b3

See more details on using hashes here.

Supported by

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