Use for pybytesize/ByteSize tasks: parsing size strings, converting bytes to metric/binary units, formatting human-readable sizes, readable unit selection, block alignment, and ByteSize arithmetic. Triggers "pybytesize", "ByteSize", "format bytes", "human readable size", "MiB/MB", "GiB/GB", "bytes to string", "parse size string", or requests for block-aligned size calculations.
99
100%
Does it follow best practices?
Impact
96%
2.74xAverage score across 3 eval scenarios
Passed
No known issues
Use pybytesize (imported as bytesize) to parse and manipulate byte sizes with consistent unit conversions and formatting. Provide concise, accurate examples that show how ByteSize objects behave with metric vs binary units.
Create a ByteSize from bytes or a size string and print a readable value.
from bytesize import ByteSize
size = ByteSize(1_048_576)
print(size) # 1.00 MiB
size = ByteSize("500MB")
print(size.bytes) # 500000000
print(size) # 476.84 MiBConvert between metric and binary units using dynamic attributes.
from bytesize import ByteSize
size = ByteSize(1_073_741_824)
print(size.MB) # 1073.741824
print(size.MiB) # 1024.0
print(size.GiB) # 1.0Pick a best-fit unit for display.
from bytesize import ByteSize
size = ByteSize(1_234_567)
unit, value = size.readable_metric
print(f"{value:.2f} {unit}") # 1.23 MB
unit, value = size.readable_binary
print(f"{value:.2f} {unit}") # 1.18 MiBFormat with precision and target units using format spec.
from bytesize import ByteSize
size = ByteSize(123_456_789)
print(f"{size:.2f:MB}") # 123.46 MB
print(f"{size:.2f:GiB}") # 0.11 GiBCompute block-aligned apparent size.
from bytesize import ByteSize
size = ByteSize(123_456_789)
aligned = size.apparent_size(4096)
print(aligned.bytes) # 123457536Arithmetic works on ByteSize objects and preserves units.
from bytesize import ByteSize
total = ByteSize("1GB") + ByteSize("512MB")
print(total) # 1.50 GiBpybytesize provides specific exceptions you can catch for validation and UX.
from bytesize import (
ByteSize,
ByteSizeError,
NegativeByteSizeError,
UnrecognizedSizeStringError,
UnknownUnitError,
)
try:
size = ByteSize("not_a_size")
except UnrecognizedSizeStringError:
print("Could not parse size string")
try:
size = ByteSize("100XX")
except UnknownUnitError as e:
print(f"Unknown unit: {e}")
try:
size = ByteSize(-1000)
except NegativeByteSizeError as e:
print(f"Error: {e}")
try:
size = ByteSize("-50MB")
except ByteSizeError as e:
print(f"ByteSize error: {e}")print(ByteSize(...)) defaults to a best-fit binary unit (base 1024).readable_metric uses base 1000, readable_binary uses base 1024; both return (unit, value).megabytes, gibibytes).apparent_size(block_bytes) requires block_bytes > 0; it raises ValueError otherwise.None.
b74de5e
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.