A humble collection of Python utilities for data processing, serialization, and everyday patterns
Project description
sugarpowder
A humble collection of Python utilities for data processing, serialization, and everyday patterns.
Install
pip install sugarpowder
Test
uv run pytest tests/
Serialization
Compressed pickle/dill and DataFrame serialization utilities.
from sugarpowder.serialization import (
blosc_pickle, blosc_unpickle, # pickle + blosc compression
blosc_dill, blosc_undill, # dill + blosc compression (supports lambdas)
df_to_parquetstream, parquetstream_to_df,
df_to_hex, hex_to_df,
df_to_base64, base64_to_df,
)
# Any Python object
data = blosc_pickle(obj)
obj = blosc_unpickle(data)
# Lambda / closure (dill)
data = blosc_dill(lambda x: x * 2)
fn = blosc_undill(data)
# DataFrame <-> bytes
pqbytes = df_to_parquetstream(df)
df = parquetstream_to_df(pqbytes)
Lists
from sugarpowder.lists import dedup, deep_flatten
# Dedup while preserving order
dedup([3, 1, 2, 1, 3]) # [3, 1, 2]
dedup([{"id": 1}, {"id": 1}, {"id": 2}], key=lambda x: x["id"]) # [{"id": 1}, {"id": 2}]
# Deep flatten
deep_flatten([1, [2, [3, [4]]]]) # [1, 2, 3, 4]
Strings
from sugarpowder.strings import fix_mac_hangul, strip_invisible
# Fix NFD Korean from macOS
fix_mac_hangul("ㄱㅏ") # "가"
# Remove hidden Unicode characters (zero-width space, BOM, etc.)
strip_invisible("hello\u200bworld") # "helloworld"
Dates
from sugarpowder.dates import date_stats
result = date_stats(df, date_col="date")
result.min # earliest date
result.max # latest date
result.nunique # number of unique dates
pmap
Parallel element-wise map using multiprocessing.
from sugarpowder.pmap import pmap
pmap(add, [1, 2, 3], [4, 5, 6]) # [5, 7, 9]
pmap(add, [1, 2, 3], [4, 5, 6], num_workers=4)
tick
Lap timer for measuring elapsed time between checkpoints.
from sugarpowder.tick import tick
t = tick()
# ... work ...
t = tick(t, label="step 1") # [main:10] Elapsed step 1: 0.1234s
t = tick(t, label="step 2", msg="done") # [main:12] Elapsed step 2: 0.0234s / done
Pipes (removed in v2.0)
Use the pipe package instead.
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
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 sugarpowder-2.0.1.tar.gz.
File metadata
- Download URL: sugarpowder-2.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","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 |
27de5ccaa4abe9a89b1edea6d0358c501817af8066ece0c6b70b0e5067962765
|
|
| MD5 |
d7fd6408317866ba5f377b49246d1993
|
|
| BLAKE2b-256 |
57bef3708db00fc73b04645374bb8ee9cc55517f2ff31bb098e5f7a5cbd5075a
|
File details
Details for the file sugarpowder-2.0.1-py3-none-any.whl.
File metadata
- Download URL: sugarpowder-2.0.1-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","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 |
0ae7643797bce9b638bd32cbe936b49143a1bffa37391d4a037db3727c5d3f3e
|
|
| MD5 |
c51cdfe5b486e2a1b616e54157626ba9
|
|
| BLAKE2b-256 |
1f49ddb11d930591815c911e533ab1bad331d88f5a1d3ba784be952ddf375ea0
|