API Reference

Complete documentation for all 150+ functions and classes

Decorators 6 decorators

@spell_timer(print_result=False) Decorator

Time execution of functions and print duration.

Parameters

print_result bool Whether to print function result False

Example

from pywizardry import spell_timer

@spell_timer(print_result=True)
def process_data(data):
    # Your processing logic
    return result

# Output: ✨ process_data completed in 0.1234s
#         Result: ...

@retry_spell(max_attempts=3, delay=1.0, backoff=2.0, exceptions=(Exception,)) Decorator

Retry function on failure with exponential backoff.

Parameters

max_attempts int Maximum retry attempts 3
delay float Initial delay between retries (seconds) 1.0
backoff float Backoff multiplier 2.0

Example

@retry_spell(max_attempts=5, delay=2.0)
def fetch_api_data(url):
    response = requests.get(url)
    response.raise_for_status()
    return response.json()

FileMagic 35+ functions

FileMagic.safe_write(path, content, backup=True, atomic=True) → Path Method

Safely write to file with optional backup and atomic operations.

Parameters

path Union[str, Path] Path to write file Required
content Union[str, bytes] Content to write Required
backup bool Create backup of existing file True

Returns

Path - Path to written file

Example

from pywizardry import FileMagic

# Safe write with backup
path = FileMagic.safe_write(
    "data.json",
    '{"key": "value"}',
    backup=True
)

# Atomic write without backup
path = FileMagic.safe_write(
    "config.yaml",
    yaml_content,
    backup=False,
    atomic=True
)

FileMagic.find_files(directory, pattern="*", recursive=True, size_limit=None, modified_after=None, modified_before=None) → List[Path] Method

Find files with advanced filtering options.

Example

# Find all Python files
files = FileMagic.find_files(
    "/projects",
    pattern="*.py",
    recursive=True
)

# Find large files modified recently
from datetime import datetime, timedelta
files = FileMagic.find_files(
    "/logs",
    pattern="*.log",
    size_limit=1024 * 1024 * 10,  # 10MB
    modified_after=datetime.now() - timedelta(days=7)
)

StringSorcery 25+ functions

StringSorcery.slugify(text, separator="-", lowercase=True, replace_chars=None) → str Method

Convert text to URL-safe slug with custom character replacement.

Example

from pywizardry import StringSorcery

# Basic slugify
slug = StringSorcery.slugify("Hello World!")
# Returns: "hello-world"

# With custom separator
slug = StringSorcery.slugify("File Name", separator="_")
# Returns: "file_name"

# With character replacement
slug = StringSorcery.slugify(
    "Café & Bar",
    replace_chars={"é": "e", "&": "and"}
)
# Returns: "cafe-and-bar"

All Functions Reference

SecuritySpells

  • hash_password() - Hash password with salt
  • verify_password() - Verify password against hash
  • aes_encrypt() - AES encryption
  • aes_decrypt() - AES decryption
  • jwt_encode() - JWT token generation
  • jwt_decode() - JWT token validation
  • generate_key() - Generate secure key
  • password_strength() - Check password strength
  • sanitize_input() - Sanitize HTML input

TimeWizardry

  • humanize() - Human-readable time
  • format_duration() - Format duration
  • next_business_day() - Next business day
  • is_business_hours() - Check business hours
  • cron_schedule() - Parse cron expression
  • timezone_convert() - Timezone conversion
  • countdown_timer() - Countdown timer

NetworkEnchantments

  • fetch_json() - Fetch JSON from URL
  • async_fetch_json() - Async fetch JSON
  • download_with_progress() - Download with progress bar
  • check_port() - Check if port is open
  • get_local_network_info() - Network info
  • ping() - Ping host
  • resolve_dns() - DNS resolution
  • create_simple_server() - Create HTTP server

DataAlchemy

  • chunk_data() - Chunk data into batches
  • remove_duplicates() - Remove duplicates
  • group_by() - Group data by key
  • flatten() - Flatten nested structure
  • transpose() - Transpose matrix
  • normalize() - Normalize data
  • standardize() - Standardize data
  • moving_average() - Calculate moving average
  • calculate_statistics() - Statistical analysis
  • detect_outliers() - Detect outliers
  • interpolate_missing() - Interpolate missing values