CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-ubelt

A Python utility belt containing simple tools, a stdlib like feel, and extra batteries

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

UBelt

A Python utility belt containing simple tools, a stdlib-like feel, and extra batteries. UBelt provides a comprehensive collection of 150+ focused utilities that make everyday Python tasks shorter, cleaner, and more consistent across different platforms.

Package Information

  • Package Name: ubelt
  • Language: Python
  • Installation: pip install ubelt

Core Imports

import ubelt as ub

All utilities are available at the top level:

import ubelt as ub
# Use any function directly
ub.cmd('ls')
ub.Timer()
ub.download('https://example.com/file.zip')

Basic Usage

import ubelt as ub

# Command execution with enhanced features
result = ub.cmd('ls -la', verbose=2)
print(result['out'])

# Progress iteration with timing and ETA
items = range(1000)
for item in ub.ProgIter(items, desc='Processing'):
    # Do work
    pass

# Dictionary operations and grouping
items = ['apple', 'banana', 'cherry', 'apricot']
grouped = ub.group_items(items, key=lambda x: x[0])
print(grouped)  # {'a': ['apple', 'apricot'], 'b': ['banana'], 'c': ['cherry']}

# Caching computations
cache = ub.Cacher('my_cache', depends=['input_data'])
result = cache.tryload()
if result is None:
    result = expensive_computation()
    cache.save(result)

# Path operations
with ub.TempDir() as tmp:
    fpath = tmp / 'example.txt'
    ub.touch(fpath)
    print(ub.augpath(fpath, suffix='_backup'))

# Timing operations
with ub.Timer('my_operation'):
    time.sleep(1)  # Replace with actual work

Architecture

UBelt is organized into 27 focused submodules, each containing related functionality:

  • Data Structures: Enhanced dictionaries (UDict, AutoDict), ordered sets, and data manipulation utilities
  • I/O Operations: File operations, downloads, path utilities, and stream handling
  • System Integration: Command execution, platform detection, and cross-platform compatibility
  • Performance Tools: Progress tracking, timing, caching, and memoization
  • Development Utilities: Import helpers, debugging tools, and code formatting

All utilities follow consistent design patterns with optional parameters, sensible defaults, and cross-platform compatibility.

Capabilities

Dictionary and Data Operations

Comprehensive dictionary utilities including enhanced dict classes with set operations, grouping functions, and data structure manipulation tools.

class UDict(dict): ...
class AutoDict(dict): ...
def group_items(items, key): ...
def dict_hist(items, weights=None): ...
def dict_union(*args, **kwargs): ...
def find_duplicates(items, k=2): ...

Dictionary Operations

Command Execution and System Integration

Execute shell commands with enhanced features, platform detection, and system integration utilities.

def cmd(command, shell=False, detach=False, verbose=0, **kwargs): ...
WIN32: bool
LINUX: bool
DARWIN: bool
def find_exe(name, **kwargs): ...

System Integration

File and Path Operations

Cross-platform path utilities, file operations, symbolic links, and temporary directory management.

class Path(pathlib.Path): ...
class TempDir: ...
def ensuredir(dpath, **kwargs): ...
def symlink(real_path, link_path, **kwargs): ...
def touch(fpath, **kwargs): ...
def delete(fpath, **kwargs): ...

Path Operations

Download and Caching

Download files with progress tracking, verification, and comprehensive caching systems for computations and data.

def download(url, fpath=None, **kwargs): ...
def grabdata(url, fpath=None, **kwargs): ...
class Cacher: ...
class CacheStamp: ...

Download and Caching

Progress and Timing

Progress iteration with ETA, timing utilities, and performance measurement tools.

class ProgIter: ...
class Timer: ...
def timestamp(datetime=None, **kwargs): ...
def timeparse(stamp): ...

Progress and Timing

List and Sequence Operations

Comprehensive sequence manipulation including chunking, filtering, sorting, and uniqueness operations.

def chunks(sequence, chunksize): ...
def group_items(items, key): ...
def argmax(sequence, key=None): ...
def argmin(sequence, key=None): ...
def argsort(sequence, key=None, reverse=False): ...
def unique(items, key=None): ...
def flatten(nested_list): ...

List Operations

String and Text Processing

String manipulation utilities including indentation, formatting, and text processing functions.

def indent(text, prefix='    '): ...
def codeblock(text): ...
def paragraph(text): ...
def hzcat(args, **kwargs): ...

Text Processing

Hashing and Import Utilities

Hash arbitrary data and files, plus dynamic module importing and path resolution utilities.

def hash_data(data, hasher='sha512', base='hex', **kwargs): ...
def hash_file(fpath, hasher='sha512', base='hex', **kwargs): ...
def import_module_from_name(name, **kwargs): ...
def import_module_from_path(fpath, **kwargs): ...

Hashing and Imports

Function and Concurrency Utilities

Function manipulation, memoization, and enhanced concurrency tools.

def memoize(func=None, **kwargs): ...
def identity(arg): ...
class Executor: ...
class JobPool: ...

Function Utilities

Types

# Sentinel value for unspecified parameters  
NoParam: object  # Special sentinel used as default for hasher, base, and other parameters

# Enhanced dictionary types
class UDict(dict):
    """Dictionary with set operations and convenience methods"""
    
class AutoDict(dict):
    """Auto-vivifying dictionary"""

class SetDict(dict):
    """Dictionary with key-wise set operations"""

# Path utilities
class Path(pathlib.Path):
    """Enhanced pathlib.Path with additional methods"""

class TempDir:
    """Context manager for temporary directories"""
    
class ChDir:
    """Context manager for changing directories"""

# Progress and timing
class ProgIter:
    """Progress iterator with timing and ETA"""
    
class Timer:
    """Context manager and decorator for timing code"""

# Caching
class Cacher:
    """On-disk caching with dependency tracking"""
    
class CacheStamp:
    """Lightweight cache stamping for file-producing computations"""

# Command execution
class CmdOutput(dict):
    """Container for command output"""

# Concurrency
class Executor:
    """Enhanced executor interface"""
    
class JobPool:
    """Job pool for managing concurrent tasks"""

# Data structures
class OrderedSet:
    """Set that preserves insertion order"""

# Stream handling
class TeeStringIO:
    """StringIO that can write to multiple streams"""
    
class CaptureStdout:
    """Context manager to capture stdout"""
    
class CaptureStream:
    """Context manager to capture arbitrary stream"""

# Mixins
class NiceRepr:
    """Mixin for nice string representations"""

# Indexable utilities
class IndexableWalker:
    """Walk through indexable nested data structures"""
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/ubelt@1.4.x
Publish Source
CLI
Badge
tessl/pypi-ubelt badge