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 saltverify_password()- Verify password against hashaes_encrypt()- AES encryptionaes_decrypt()- AES decryptionjwt_encode()- JWT token generationjwt_decode()- JWT token validationgenerate_key()- Generate secure keypassword_strength()- Check password strengthsanitize_input()- Sanitize HTML input
TimeWizardry
humanize()- Human-readable timeformat_duration()- Format durationnext_business_day()- Next business dayis_business_hours()- Check business hourscron_schedule()- Parse cron expressiontimezone_convert()- Timezone conversioncountdown_timer()- Countdown timer
NetworkEnchantments
fetch_json()- Fetch JSON from URLasync_fetch_json()- Async fetch JSONdownload_with_progress()- Download with progress barcheck_port()- Check if port is openget_local_network_info()- Network infoping()- Ping hostresolve_dns()- DNS resolutioncreate_simple_server()- Create HTTP server
DataAlchemy
chunk_data()- Chunk data into batchesremove_duplicates()- Remove duplicatesgroup_by()- Group data by keyflatten()- Flatten nested structuretranspose()- Transpose matrixnormalize()- Normalize datastandardize()- Standardize datamoving_average()- Calculate moving averagecalculate_statistics()- Statistical analysisdetect_outliers()- Detect outliersinterpolate_missing()- Interpolate missing values