A Python utility function for converting data sizes between different units — bits, bytes, kilobytes, megabytes, gigabytes, and beyond.
- Convert between bit-scale units:
b,kb,mb,gb,tb,pb,eb - Convert between byte-scale units:
B,KB,MB,GB,TB,PB,EB - Smart auto-scaling — automatically selects the most readable unit based on size
- Explicit target conversion — specify exactly which unit to convert to
- Handles floating-point precision with rounding
| Category | Technology |
|---|---|
| Language | Python 3 |
| Type | Pure function (no dependencies) |
from DataConverter import convert
# Convert to a specific unit
print(convert(size="1024 MB", convert_to="GB")) # → "1.0 GB"
print(convert(size="500 b", convert_to="KB")) # → "0.0610 KB"
# Auto-scale to human-readable size
print(convert(size="1048576 KB", mode="Bytes")) # → "1.0 GB"- Handling complex keyword argument patterns (
**kwargs) - Unit conversion math with powers of 1024
- Writing reusable, importable utility functions
- The difference between bit-based and byte-based data units
Made with ❤️ as part of a learning journey