or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

additional-utilities.mdcaching.mddata-structures.mddevelopment-debugging-tools.mdfile-io-operations.mdformat-table-utilities.mdindex.mditeration-processing.mdmath-stats-operations.mdnetwork-url-handling.mdstring-text-processing.mdtime-date-utilities.md
tile.json

tessl/pypi-boltons

When they're not builtins, they're boltons.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/boltons@24.1.x

To install, run

npx @tessl/cli install tessl/pypi-boltons@24.1.0

index.mddocs/

Boltons

Boltons is a comprehensive Python utility library containing over 230 BSD-licensed, pure-Python utilities that extend the standard library with functionality that should be built-in. The library provides essential tools for common programming tasks including atomic file operations, optimized data structures, advanced iteration utilities, recursive data structure manipulation, caching, comprehensive traceback handling, and utilities across domains like debugging, dictionaries, file handling, formatting, functional programming, I/O operations, JSON processing, mathematical operations, networking, statistics, string manipulation, and time handling.

Designed for maximum reusability and reliability, boltons serves as a foundational toolkit for Python developers who need robust, well-tested utility functions that maintain the same quality standards as the standard library while filling gaps in common functionality across CLI tools, web applications, data processing pipelines, and general-purpose Python development.

Package Information

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

Core Imports

Boltons modules are imported individually based on the functionality needed:

from boltons.cacheutils import LRU, cached
from boltons.dictutils import OrderedMultiDict
from boltons.iterutils import chunked, flatten
from boltons.fileutils import atomic_save
from boltons.strutils import slugify, bytes2human

Basic Usage

from boltons.iterutils import chunked, flatten
from boltons.dictutils import OrderedMultiDict
from boltons.cacheutils import LRU
from boltons.strutils import slugify

# Process data in chunks
data = list(range(100))
for chunk in chunked(data, 10):
    print(f"Processing chunk of {len(chunk)} items")

# Maintain insertion order with multiple values per key
omd = OrderedMultiDict()
omd.add('key', 'value1')
omd.add('key', 'value2')
print(omd.getlist('key'))  # ['value1', 'value2']

# Create URL-friendly slugs
title = "Hello, World! This is a test."
slug = slugify(title)
print(slug)  # "hello-world-this-is-a-test"

# Use LRU cache for performance
cache = LRU(max_size=100)
cache['key'] = 'expensive_computation_result'

Architecture

Boltons is organized into focused utility modules, each containing related functionality:

  • Data Structures: Enhanced dictionaries, lists, sets, and queues with specialized behaviors
  • Iteration & Processing: Advanced iteration utilities, chunking, windowing, and data transformation
  • Caching: Multiple cache implementations with different eviction strategies
  • String & Text Processing: Comprehensive text manipulation, formatting, and encoding utilities
  • File & I/O Operations: Atomic file operations, spooled I/O, and path manipulation
  • Network & URL Handling: Socket utilities and comprehensive URL parsing/manipulation
  • Time & Statistics: Time zone handling, relative time formatting, and statistical analysis
  • Development Tools: Debugging utilities, traceback enhancement, and introspection tools

Each module can be imported and used independently, providing composable utilities that integrate seamlessly with existing Python code.

Capabilities

Data Structures

Advanced dictionary, list, set, and queue implementations with specialized behaviors for common programming patterns. Includes ordered multi-dictionaries, bidirectional mappings, priority queues, and indexed sets.

# dictutils
class OrderedMultiDict(dict): ...
class OneToOne(dict): ...
class FrozenDict(dict): ...

# listutils  
class BarrelList(list): ...
class SplayList(list): ...

# setutils
class IndexedSet(MutableSet): ...

# queueutils
class HeapPriorityQueue(BasePriorityQueue): ...
class SortedPriorityQueue(BasePriorityQueue): ...

Data Structures

Iteration & Processing Utilities

Comprehensive tools for working with iterables including chunking, windowing, flattening, uniqueness operations, and advanced data structure manipulation. Provides both list and iterator versions of operations for memory efficiency.

def chunked(src, size, count=None, **kw): ...
def windowed(src, size, fill=_UNSET): ...
def flatten(iterable): ...
def unique(src, key=None): ...
def remap(root_obj, **kwargs): ...
def get_path(root_obj, path, default=_UNSET): ...

Iteration & Processing

Caching

Multiple cache implementations with different eviction strategies, function/method decorators, and cache key generation utilities. Supports LRU, LRI strategies with hit/miss statistics and property caching.

class LRU(dict): ...
class LRI(dict): ...
def cached(cache, scoped=True, typed=False, key=None): ...
def cachedmethod(cache, scoped=True, typed=False, key=None): ...
class cachedproperty: ...

Caching

String & Text Processing

Comprehensive text manipulation including case conversion, slugification, text formatting, HTML processing, ANSI handling, compression, and advanced string operations with internationalization support.

def slugify(text, delim='_', lower=True, ascii=False): ...
def camel2under(camel_string): ...
def under2camel(under_string): ...
def bytes2human(nbytes, ndigits=0): ...
def html2text(html_text): ...
def strip_ansi(text): ...
def multi_replace(input_string, sub_map, **kwargs): ...

String & Text Processing

File & I/O Operations

Atomic file operations, advanced I/O utilities, path manipulation, and file system operations. Includes spooled I/O that automatically switches to disk for large data and atomic file saving with backup support.

def atomic_save(dest_path, **kwargs): ...
def mkdir_p(path): ...
class AtomicSaver: ...
class SpooledBytesIO(SpooledIOBase): ...
class SpooledStringIO(SpooledIOBase): ...
def augpath(path, suffix='', prefix='', ext=None, base=None, dpath=None, multidot=False): ...

File & I/O Operations

Network & URL Handling

Socket programming utilities with buffering and protocol support, plus comprehensive URL parsing, manipulation, and utilities. Includes netstring protocol implementation and complete URL component handling.

class BufferedSocket: ...
class NetstringSocket: ...
class URL: ...
def parse_url(url_text): ...
def find_all_links(text, with_text=False, **kwargs): ...

Network & URL Handling

Time & Date Utilities

Time zone handling, datetime parsing, relative time formatting, and date range generation. Supports ISO 8601 parsing, human-readable time deltas, and timezone-aware operations.

def isoparse(iso_str): ...
def parse_timedelta(text): ...  
def relative_time(d, other=None, ndigits=0): ...
def daterange(start, stop, step=1, inclusive=False): ...
class LocalTZInfo(tzinfo): ...
class USTimeZone(tzinfo): ...

Time & Date Utilities

Mathematical & Statistical Operations

Mathematical utilities, statistical analysis, and data summarization tools. Includes bit manipulation, number clamping, descriptive statistics, and histogram formatting.

def clamp(x, lower=float('-inf'), upper=float('inf')): ...
class Bits: ...
class Stats: ...
def describe(data, quantiles=None, format=None): ...

Mathematical & Statistical Operations

Development & Debugging Tools

Debugging utilities, function introspection, traceback enhancement, garbage collection tools, and development aids. Includes pdb integration, enhanced exception handling, and function manipulation utilities.

def pdb_on_signal(signalnum=None): ...
def pdb_on_exception(limit=100): ...
class TracebackInfo: ...
class ExceptionInfo: ...
class FunctionBuilder: ...
def get_module_callables(mod, ignore=None): ...

Development & Debugging Tools

Format & Table Utilities

String formatting utilities, tabular data handling, and HTML table generation. Includes format string parsing, table creation from various data sources, and flexible output formatting.

def split_format_str(fstr): ...
def get_format_args(fstr): ...
class Table: ... 
def to_text(obj, maxlen=None): ...

Format & Table Utilities

Additional Utilities

Specialized utilities for JSON processing, mailbox handling, named tuples/lists, type checking, and deprecation management. Includes JSON Lines processing, mbox file access, and enhanced type introspection.

class JSONLIterator: ...
def namedtuple(typename, field_names, verbose=False, rename=False): ...
def namedlist(typename, field_names, verbose=False, rename=False): ...
def make_sentinel(name='_MISSING', var_name=None): ...
class DeprecatableModule(ModuleType): ...

Additional Utilities