A collection of useful Python utilities for dict, list, string manipulation, encoding, and data serialization
Project description
toolbox-py
A comprehensive collection of Python utilities for everyday programming tasks.
Features
Dictionary Utilities (toolbox.dict)
- DotDict: Dictionary with dot notation access
- flatten_dict: Flatten nested dictionaries with customizable separators
- unflatten_dict: Convert flattened dicts back to nested structure
- merge_dicts: Recursively merge dictionaries
- get_nested/set_nested: Access nested values using dot notation paths
- filter_dict: Filter dictionaries with predicate functions
- invert_dict: Swap keys and values
- deep_copy_dict: Deep copy nested dictionaries
List Utilities (toolbox.list)
- flatten_list: Recursively flatten nested lists
- chunk_list: Split lists into fixed-size chunks
- unique: Remove duplicates while preserving order
- partition: Split lists based on predicate
- group_by: Group items by key function
- dedupe: Advanced deduplication with custom key functions
- interleave: Merge multiple lists element by element
- compact: Remove falsy values (None, '', False, etc.)
String Utilities (toolbox.string)
- Case conversion: camel_to_snake, snake_to_camel, kebab_case, title_case
- Compression: compress_string/decompress_string with base64 encoding
- Formatting: slugify, truncate, wrap_text
- Text processing: remove_accents, strip_html, reverse_string, count_words
Encoding/Decoding (toolbox.encode, toolbox.decode)
- Base64 encoding and decoding
- Support for both str and bytes
Data Serialization (toolbox.dataclass)
- SerializableDataclass: Enhanced dataclass with JSON serialization
- Alias support for field name mapping
- Preprocessors for data transformation
- Nested dataclass handling
Installation
pip install toolbox-py
Or with uv:
uv add toolbox-py
Usage Examples
Dictionary Operations
from toolbox.dict import flatten_dict, get_nested, DotDict
# Flatten nested dictionary
nested = {'user': {'name': 'John', 'address': {'city': 'NYC'}}}
flat = flatten_dict(nested)
# {'user.name': 'John', 'user.address.city': 'NYC'}
# Access nested values safely
city = get_nested(nested, 'user.address.city', default='Unknown')
# Dot notation access
config = DotDict({'database': {'host': 'localhost'}})
print(config.database.host) # localhost
List Operations
from toolbox.list import chunk_list, group_by, dedupe
# Split into chunks
items = [1, 2, 3, 4, 5, 6, 7]
chunks = chunk_list(items, 3) # [[1, 2, 3], [4, 5, 6], [7]]
# Group by key
words = ['apple', 'apricot', 'banana', 'blueberry']
by_first = group_by(words, lambda w: w[0])
# {'a': ['apple', 'apricot'], 'b': ['banana', 'blueberry']}
# Deduplicate with custom key
users = [{'id': 1, 'name': 'Alice'}, {'id': 1, 'name': 'Bob'}]
unique_users = dedupe(users, key=lambda u: u['id'])
String Operations
from toolbox.string import slugify, truncate, camel_to_snake
# Create URL-friendly slugs
slug = slugify('Hello World!') # 'hello-world'
# Truncate with ellipsis
text = truncate('Long text here', 10) # 'Long te...'
# Convert naming conventions
snake = camel_to_snake('CamelCase') # 'camel_case'
Development
# Setup environment
uv sync
# Run tests
pytest
# Format code
black toolbox/ tests/
isort toolbox/ tests/
# Type check
mypy toolbox/
# Build docs
cd docs && make html
Requirements
- Python >= 3.11
License
MIT License - see LICENSE file for details
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sadtech_kit-0.1.0.tar.gz
(34.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sadtech_kit-0.1.0.tar.gz.
File metadata
- Download URL: sadtech_kit-0.1.0.tar.gz
- Upload date:
- Size: 34.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aff9a66e0831f292157d0470f819e05feebe4203920608d8bfd17ab72927fe3f
|
|
| MD5 |
24d3692ef899bd1732199c96f2514e2c
|
|
| BLAKE2b-256 |
8d454de54f0abc2cf73171cf7f730db0d3dbe6a9c07b61c86e53de8de8d09440
|
File details
Details for the file sadtech_kit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sadtech_kit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.5 {"installer":{"name":"uv","version":"0.10.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
503b9aa8dee69d5a6c849f9906c4c9efeaf041706e52ab9f16f1f17360b8e6c3
|
|
| MD5 |
ddb30e400ed72ef6a59ea082a844618b
|
|
| BLAKE2b-256 |
e38609fb1e73440c23dc9affdba954a9f20079aaecf5f8798d044dd680fa02f1
|