Skip to main content

Common Python shortcuts and utilities that speed up debug workflows

Project description

cmstuff

Common Python shortcuts and utilities that speed up debug workflows by 30%.

Installation

pip install cmstuff

For development:

git clone https://github.com/Williams/cmstuff.git
cd cmstuff
pip install -e .

Overview

The library provides a set of commonly used functions and shortcuts to make coding in Python easier. It includes shortcuts for printing, file searching, directory management, introspection, and logging.

Introspection utilities

  • doc(obj) — print or return documentation from an object
  • classname(obj) — return the class name of an object
  • mefun(obj) — return all callable non-class attributes
  • methods(obj) — return a list of methods (excluding magic methods)
  • group(obj) — return a mapping of types to their respective attributes
  • Stat(obj) — group and display all types in an object
  • filterout(type_, obj) — filter attributes by type
  • filterout_base_attrs(obj) — list properties not inherited from base classes
  • filterstr(s, obj) — filter attributes containing a substring

Path utilities

  • HOME — path to user home directory
  • desktop() — path to the desktop
  • cdesktop() — change working directory to the desktop
  • pypath() — path to the Python installation
  • opendir(dir) — open a directory in the file explorer
  • search_files(fname) — recursively search for files by keyword

Other utilities

  • concat(*items) — concatenate items into a space-separated string
  • cls() — clear the console
  • setargs(arg, *args) — set sys.argv conveniently
  • get_logger(...) — create a custom logger with sensible defaults
  • get_caller_module() — get the module of the calling code

Example

import cmstuff as cm


class Example:
    def __init__(self):
        self.name = "John"
        self.age = 30
        self._id = "12345"
        self.other_name = "Doodleman"

    def display_info(self):
        print(f"Name: {self.name}, Age: {self.age}")

    def full_name(self):
        return f"{self.name} {self.other_name}"


# get an object
example = Example()

# filter the methods and attributes that are relevant to you
filtered_attrs = cm.filterstr("name", example)

# it returns a list so you can do further processing
print(filtered_attrs)  # Output: ['full_name', 'name', 'other_name']

# If you think this is cool try
# cm.Stat(example).show()

Author

Williams — williamusanga22@gmail.com

License

MIT

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

cmstuff-1.1.0.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

cmstuff-1.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file cmstuff-1.1.0.tar.gz.

File metadata

  • Download URL: cmstuff-1.1.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.1

File hashes

Hashes for cmstuff-1.1.0.tar.gz
Algorithm Hash digest
SHA256 a07ad956e81bd2e6fdcecc0e6561eee4d4aa8d9ad0f6de9c281989584b082390
MD5 ee90f609180579724fdf9bf2f8cab260
BLAKE2b-256 70d8d094a7874305d7843f6a60999ce68d4d75e817b46102543731d98aff406f

See more details on using hashes here.

File details

Details for the file cmstuff-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: cmstuff-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.10.0 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.20 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.1

File hashes

Hashes for cmstuff-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69ec5a119b64f11644f6cb4e6bd9707c02a3336b7dc5a9b665b34da1742166ff
MD5 46afe438e178f6b081bb621e66a40908
BLAKE2b-256 a5912be99df4965c47ceb43ddf3cb24c5482cf1494ccbb2727a64b9e2f705387

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