humanbytes 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
humanbytes/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .human_size import human_size
2
+
3
+ __all__ = ["human_size"]
@@ -0,0 +1,27 @@
1
+ def humanbytes(num, binary=False):
2
+ """
3
+ Convert a number of bytes into a human-readable string.
4
+
5
+ Args:
6
+ num (int or float): The number to convert (e.g., bytes).
7
+ binary (bool): If True, use binary units (KiB, MiB, GiB, ...).
8
+ If False, use decimal units (KB, MB, GB, ...).
9
+
10
+ Returns:
11
+ str: Human-readable string representation.
12
+ """
13
+ if binary:
14
+ units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
15
+ step = 1024.0
16
+ else:
17
+ units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
18
+ step = 1000.0
19
+
20
+ if num < step:
21
+ return f"{num} {units[0]}"
22
+
23
+ for i, unit in enumerate(units[1:], 1):
24
+ num /= step
25
+ if abs(num) < step:
26
+ return f"{num:.2f} {unit}"
27
+ return f"{num:.2f} {units[-1]}"
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.4
2
+ Name: humanbytes
3
+ Version: 0.1.0
4
+ Summary: Convert bytes to human-readable sizes (KB, MB, KiB, MiB, etc.)
5
+ Home-page: https://github.com/Zsombroo/humanbytes
6
+ Author: Zsombroo
7
+ License: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
12
+ Requires-Python: >=3.6
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Dynamic: author
16
+ Dynamic: classifier
17
+ Dynamic: description
18
+ Dynamic: description-content-type
19
+ Dynamic: home-page
20
+ Dynamic: license
21
+ Dynamic: license-file
22
+ Dynamic: requires-python
23
+ Dynamic: summary
24
+
25
+
26
+ # humanbytes
27
+
28
+ `humanbytes` is a simple Python package to convert bytes into human-readable sizes using either decimal (KB, MB, ...) or binary (KiB, MiB, ...) units.
29
+
30
+ ## Features
31
+ - Convert bytes to a human-readable string
32
+ - Supports both decimal (powers of 1000) and binary (powers of 1024) units
33
+ - Minimal, dependency-free, and easy to use
34
+
35
+
36
+ ## Installation
37
+
38
+ ```bash
39
+ pip install humanbytes
40
+ ```
41
+
42
+ ## Usage
43
+
44
+
45
+ ```python
46
+
47
+ from humanbytes import human_size
48
+
49
+ print(human_size(1536)) # 1.54 KB
50
+ print(human_size(1536, binary=True)) # 1.50 KiB
51
+ print(human_size(10**9)) # 1.00 GB
52
+ print(human_size(2**30, binary=True)) # 1.00 GiB
53
+ ```
54
+
55
+ ### Parameters
56
+ - `num`: The number to convert (e.g., bytes)
57
+ - `binary`: If True, use binary units (KiB, MiB, ...). If False (default), use decimal units (KB, MB, ...)
58
+
59
+ ## License
60
+
61
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,7 @@
1
+ humanbytes/__init__.py,sha256=FdaDyyWZZ7m1_fM36M24G13LMocubVfWMcBpLtkSFq0,60
2
+ humanbytes/humanbytes.py,sha256=MMqeqQyb6XoLdLVOhllNhOj6cwuxPxMfw8M9X4pK17U,831
3
+ humanbytes-0.1.0.dist-info/licenses/LICENSE,sha256=mdQzK2LGRISBTdl7VfVSJ63yP8XfdPFNtT3hgxf1XEI,1080
4
+ humanbytes-0.1.0.dist-info/METADATA,sha256=bcXfWmJBfzvo7Twrk67ztBI2k8SKgBDYFWGA4AMRXeI,1580
5
+ humanbytes-0.1.0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
6
+ humanbytes-0.1.0.dist-info/top_level.txt,sha256=8oMwv1UMpim3KqyZgYkWbV3MbgAU5R_bqmHFbSDuDPk,11
7
+ humanbytes-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2026 Zsombroo
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
1
+ humanbytes