sizelib 0.1.0__tar.gz

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.
sizelib-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Saptarshi Roy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
sizelib-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: sizelib
3
+ Version: 0.1.0
4
+ Summary: A simple, pythonic library for working with and humanizing file sizes.
5
+ Author: Saptarshi Roy
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/saptarshiroy39/sizelib
8
+ Project-URL: Homepage, https://pypi.org/project/sizelib
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ <h1 align="center">
15
+ <img src="./public/sizelib.svg" alt="๐Ÿ“„" width="128">
16
+ <br>
17
+ <b>sizelib</b>
18
+ </h1>
19
+
20
+ <p align="center">
21
+ <a href="https://pypi.org/project/sizelib"><b>sizelib</b></a> is a lightweight, type-safe Python Library for working with and humanizing file sizes. It offers clean, type-preserving size helpers (supporting both `int` and `float`) and loop-based human readable string conversions.
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://pypi.org/project/sizelib"><b>๐Ÿ”— <code>PyPI Package</code></b></a>
26
+ &nbsp;|&nbsp;
27
+ ๐Ÿ†” <code>pip install sizelib</code> or <code>uv add sizelib</code>
28
+ </p>
29
+
30
+ ---
31
+
32
+ ## ๐Ÿ _SDK_
33
+
34
+ `Installation`
35
+
36
+ ```bash
37
+ pip install sizelib
38
+ # or
39
+ uv add sizelib
40
+ ```
41
+
42
+ `Size Helper Functions`
43
+
44
+ ```python
45
+ from sizelib import size
46
+
47
+ # Define constraints using binary (base 2 / 1024) or decimal (base 10 / 1000) helper methods
48
+ MAX_UPLOAD_SIZE = size.mib(10) # 10 MiB (10485760 bytes)
49
+ CACHE_LIMIT = size.gib(2) # 2 GiB (2147483648 bytes)
50
+ USER_QUOTA = size.gb(50) # 50 GB (50000000000 bytes)
51
+
52
+ print(MAX_UPLOAD_SIZE) # Output: 10485760
53
+ print(type(MAX_UPLOAD_SIZE)) # Output: <class 'int'>
54
+ ```
55
+
56
+ `Humanize Byte Sizes`
57
+
58
+ ```python
59
+ from sizelib import humanize
60
+
61
+ # Default binary formatting (base 2 / 1024)
62
+ print(humanize(MAX_UPLOAD_SIZE)) # Output: 10 MiB
63
+ print(humanize(CACHE_LIMIT)) # Output: 2 GiB
64
+
65
+ # Decimal values are formatted up to 2 decimal places
66
+ TOTAL = CACHE_LIMIT + size.mib(500)
67
+ print(humanize(TOTAL)) # Output: 2.49 GiB
68
+
69
+ # Decimal formatting (base 10 / 1000)
70
+ print(humanize(USER_QUOTA, base=10)) # Output: 50 GB
71
+ ```
72
+
73
+ `Exception Handling`
74
+
75
+ ```python
76
+ from sizelib import FileTooLarge, size, humanize
77
+
78
+ file_size = size.mib(12)
79
+
80
+ try:
81
+ if file_size > MAX_UPLOAD_SIZE:
82
+ raise FileTooLarge(f"File size exceeds limit of {humanize(MAX_UPLOAD_SIZE)}")
83
+ except FileTooLarge as e:
84
+ print(e)
85
+ # Output: File size exceeds limit of 10 MiB
86
+ ```
87
+
88
+ ---
89
+
90
+ ## โœจ _Features_
91
+
92
+ | FEATURE | DESCRIPTION |
93
+ | ------------------------ | --------------------------------------------------------------------------------------------------- |
94
+ | ๐Ÿ“ **Unit Helpers** | Standardized functions for all major divisions (`kb`, `mb`, `gb`, `tb`, `kib`, `mib`, `gib`, `tib`) |
95
+ | ๐Ÿงช **Type Preservation** | Dynamically maintains input types (returns int/floats accordingly) |
96
+ | โš™๏ธ **Custom Bases** | Support for both binary (`base=2` / 1024) and decimal (`base=10` / 1000) formats |
97
+ | ๐Ÿ›ก๏ธ **Structured Errors** | Exposes custom `SizeLibError` and `FileTooLarge` exceptions for validation |
98
+ | โšก **Ultra Minimalism** | Zero external dependencies with an optimized, lightweight iteration algorithm |
99
+
100
+ ---
101
+
102
+ ## ๐Ÿ—๏ธ _System Architecture_
103
+
104
+ | # | COMPONENT | DESCRIPTION | STACK |
105
+ | --- | ------------------ | --------------------------------------------------------------- | ------------ |
106
+ | 1๏ธโƒฃ | **Sizelib Size** | The math factor constants and unit calculation helper functions | **_Python_** |
107
+ | 2๏ธโƒฃ | **Sizelib Format** | The humanization formatting module for readable string units | **_Python_** |
108
+
109
+ ---
110
+
111
+ <p align="center">
112
+ Made with ๐Ÿ“„ by <a href="https://hirishi.in">Saptarshi Roy</a>
113
+ </p>
@@ -0,0 +1,100 @@
1
+ <h1 align="center">
2
+ <img src="./public/sizelib.svg" alt="๐Ÿ“„" width="128">
3
+ <br>
4
+ <b>sizelib</b>
5
+ </h1>
6
+
7
+ <p align="center">
8
+ <a href="https://pypi.org/project/sizelib"><b>sizelib</b></a> is a lightweight, type-safe Python Library for working with and humanizing file sizes. It offers clean, type-preserving size helpers (supporting both `int` and `float`) and loop-based human readable string conversions.
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://pypi.org/project/sizelib"><b>๐Ÿ”— <code>PyPI Package</code></b></a>
13
+ &nbsp;|&nbsp;
14
+ ๐Ÿ†” <code>pip install sizelib</code> or <code>uv add sizelib</code>
15
+ </p>
16
+
17
+ ---
18
+
19
+ ## ๐Ÿ _SDK_
20
+
21
+ `Installation`
22
+
23
+ ```bash
24
+ pip install sizelib
25
+ # or
26
+ uv add sizelib
27
+ ```
28
+
29
+ `Size Helper Functions`
30
+
31
+ ```python
32
+ from sizelib import size
33
+
34
+ # Define constraints using binary (base 2 / 1024) or decimal (base 10 / 1000) helper methods
35
+ MAX_UPLOAD_SIZE = size.mib(10) # 10 MiB (10485760 bytes)
36
+ CACHE_LIMIT = size.gib(2) # 2 GiB (2147483648 bytes)
37
+ USER_QUOTA = size.gb(50) # 50 GB (50000000000 bytes)
38
+
39
+ print(MAX_UPLOAD_SIZE) # Output: 10485760
40
+ print(type(MAX_UPLOAD_SIZE)) # Output: <class 'int'>
41
+ ```
42
+
43
+ `Humanize Byte Sizes`
44
+
45
+ ```python
46
+ from sizelib import humanize
47
+
48
+ # Default binary formatting (base 2 / 1024)
49
+ print(humanize(MAX_UPLOAD_SIZE)) # Output: 10 MiB
50
+ print(humanize(CACHE_LIMIT)) # Output: 2 GiB
51
+
52
+ # Decimal values are formatted up to 2 decimal places
53
+ TOTAL = CACHE_LIMIT + size.mib(500)
54
+ print(humanize(TOTAL)) # Output: 2.49 GiB
55
+
56
+ # Decimal formatting (base 10 / 1000)
57
+ print(humanize(USER_QUOTA, base=10)) # Output: 50 GB
58
+ ```
59
+
60
+ `Exception Handling`
61
+
62
+ ```python
63
+ from sizelib import FileTooLarge, size, humanize
64
+
65
+ file_size = size.mib(12)
66
+
67
+ try:
68
+ if file_size > MAX_UPLOAD_SIZE:
69
+ raise FileTooLarge(f"File size exceeds limit of {humanize(MAX_UPLOAD_SIZE)}")
70
+ except FileTooLarge as e:
71
+ print(e)
72
+ # Output: File size exceeds limit of 10 MiB
73
+ ```
74
+
75
+ ---
76
+
77
+ ## โœจ _Features_
78
+
79
+ | FEATURE | DESCRIPTION |
80
+ | ------------------------ | --------------------------------------------------------------------------------------------------- |
81
+ | ๐Ÿ“ **Unit Helpers** | Standardized functions for all major divisions (`kb`, `mb`, `gb`, `tb`, `kib`, `mib`, `gib`, `tib`) |
82
+ | ๐Ÿงช **Type Preservation** | Dynamically maintains input types (returns int/floats accordingly) |
83
+ | โš™๏ธ **Custom Bases** | Support for both binary (`base=2` / 1024) and decimal (`base=10` / 1000) formats |
84
+ | ๐Ÿ›ก๏ธ **Structured Errors** | Exposes custom `SizeLibError` and `FileTooLarge` exceptions for validation |
85
+ | โšก **Ultra Minimalism** | Zero external dependencies with an optimized, lightweight iteration algorithm |
86
+
87
+ ---
88
+
89
+ ## ๐Ÿ—๏ธ _System Architecture_
90
+
91
+ | # | COMPONENT | DESCRIPTION | STACK |
92
+ | --- | ------------------ | --------------------------------------------------------------- | ------------ |
93
+ | 1๏ธโƒฃ | **Sizelib Size** | The math factor constants and unit calculation helper functions | **_Python_** |
94
+ | 2๏ธโƒฃ | **Sizelib Format** | The humanization formatting module for readable string units | **_Python_** |
95
+
96
+ ---
97
+
98
+ <p align="center">
99
+ Made with ๐Ÿ“„ by <a href="https://hirishi.in">Saptarshi Roy</a>
100
+ </p>
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sizelib"
7
+ version = "0.1.0"
8
+ description = "A simple, pythonic library for working with and humanizing file sizes."
9
+ authors = [{name = "Saptarshi Roy"}]
10
+ license = "MIT"
11
+ readme = "README.md"
12
+
13
+ requires-python = ">=3.8"
14
+ dependencies = []
15
+
16
+ [project.urls]
17
+ Repository = "https://github.com/saptarshiroy39/sizelib"
18
+ Homepage = "https://pypi.org/project/sizelib"
19
+
20
+ [tool.setuptools]
21
+ package-dir = {"" = "src"}
22
+ packages = ["sizelib"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,5 @@
1
+ from . import size
2
+ from .exceptions import FileTooLarge, SizeLibError
3
+ from .humanize import humanize
4
+
5
+ __all__ = ["size", "humanize", "SizeLibError", "FileTooLarge"]
@@ -0,0 +1,11 @@
1
+ BYTE = 1
2
+
3
+ KB = 1000
4
+ MB = 1000**2
5
+ GB = 1000**3
6
+ TB = 1000**4
7
+
8
+ KIB = 1024
9
+ MIB = 1024**2
10
+ GIB = 1024**3
11
+ TIB = 1024**4
@@ -0,0 +1,6 @@
1
+ class SizeLibError(Exception):
2
+ pass
3
+
4
+
5
+ class FileTooLarge(SizeLibError):
6
+ pass
@@ -0,0 +1,23 @@
1
+ def humanize(size_bytes: int | float, base: int = 2) -> str:
2
+ if size_bytes < 0:
3
+ raise ValueError("Size cannot be negative")
4
+ if size_bytes == 0:
5
+ return "0 B"
6
+
7
+ if base == 2:
8
+ divisor = 1024
9
+ units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
10
+ elif base == 10:
11
+ divisor = 1000
12
+ units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
13
+ else:
14
+ raise ValueError("base must be 2 or 10")
15
+
16
+ for unit in units:
17
+ if size_bytes < divisor:
18
+ break
19
+ size_bytes /= divisor
20
+
21
+ if size_bytes == int(size_bytes):
22
+ return f"{int(size_bytes)} {unit}"
23
+ return f"{size_bytes:.2f} {unit}"
@@ -0,0 +1,37 @@
1
+ from .config import BYTE, GB, GIB, KB, KIB, MB, MIB, TB, TIB
2
+
3
+
4
+ def b(value: int | float) -> int | float:
5
+ return value * BYTE
6
+
7
+
8
+ def kb(value: int | float) -> int | float:
9
+ return value * KB
10
+
11
+
12
+ def mb(value: int | float) -> int | float:
13
+ return value * MB
14
+
15
+
16
+ def gb(value: int | float) -> int | float:
17
+ return value * GB
18
+
19
+
20
+ def tb(value: int | float) -> int | float:
21
+ return value * TB
22
+
23
+
24
+ def kib(value: int | float) -> int | float:
25
+ return value * KIB
26
+
27
+
28
+ def mib(value: int | float) -> int | float:
29
+ return value * MIB
30
+
31
+
32
+ def gib(value: int | float) -> int | float:
33
+ return value * GIB
34
+
35
+
36
+ def tib(value: int | float) -> int | float:
37
+ return value * TIB
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: sizelib
3
+ Version: 0.1.0
4
+ Summary: A simple, pythonic library for working with and humanizing file sizes.
5
+ Author: Saptarshi Roy
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/saptarshiroy39/sizelib
8
+ Project-URL: Homepage, https://pypi.org/project/sizelib
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Dynamic: license-file
13
+
14
+ <h1 align="center">
15
+ <img src="./public/sizelib.svg" alt="๐Ÿ“„" width="128">
16
+ <br>
17
+ <b>sizelib</b>
18
+ </h1>
19
+
20
+ <p align="center">
21
+ <a href="https://pypi.org/project/sizelib"><b>sizelib</b></a> is a lightweight, type-safe Python Library for working with and humanizing file sizes. It offers clean, type-preserving size helpers (supporting both `int` and `float`) and loop-based human readable string conversions.
22
+ </p>
23
+
24
+ <p align="center">
25
+ <a href="https://pypi.org/project/sizelib"><b>๐Ÿ”— <code>PyPI Package</code></b></a>
26
+ &nbsp;|&nbsp;
27
+ ๐Ÿ†” <code>pip install sizelib</code> or <code>uv add sizelib</code>
28
+ </p>
29
+
30
+ ---
31
+
32
+ ## ๐Ÿ _SDK_
33
+
34
+ `Installation`
35
+
36
+ ```bash
37
+ pip install sizelib
38
+ # or
39
+ uv add sizelib
40
+ ```
41
+
42
+ `Size Helper Functions`
43
+
44
+ ```python
45
+ from sizelib import size
46
+
47
+ # Define constraints using binary (base 2 / 1024) or decimal (base 10 / 1000) helper methods
48
+ MAX_UPLOAD_SIZE = size.mib(10) # 10 MiB (10485760 bytes)
49
+ CACHE_LIMIT = size.gib(2) # 2 GiB (2147483648 bytes)
50
+ USER_QUOTA = size.gb(50) # 50 GB (50000000000 bytes)
51
+
52
+ print(MAX_UPLOAD_SIZE) # Output: 10485760
53
+ print(type(MAX_UPLOAD_SIZE)) # Output: <class 'int'>
54
+ ```
55
+
56
+ `Humanize Byte Sizes`
57
+
58
+ ```python
59
+ from sizelib import humanize
60
+
61
+ # Default binary formatting (base 2 / 1024)
62
+ print(humanize(MAX_UPLOAD_SIZE)) # Output: 10 MiB
63
+ print(humanize(CACHE_LIMIT)) # Output: 2 GiB
64
+
65
+ # Decimal values are formatted up to 2 decimal places
66
+ TOTAL = CACHE_LIMIT + size.mib(500)
67
+ print(humanize(TOTAL)) # Output: 2.49 GiB
68
+
69
+ # Decimal formatting (base 10 / 1000)
70
+ print(humanize(USER_QUOTA, base=10)) # Output: 50 GB
71
+ ```
72
+
73
+ `Exception Handling`
74
+
75
+ ```python
76
+ from sizelib import FileTooLarge, size, humanize
77
+
78
+ file_size = size.mib(12)
79
+
80
+ try:
81
+ if file_size > MAX_UPLOAD_SIZE:
82
+ raise FileTooLarge(f"File size exceeds limit of {humanize(MAX_UPLOAD_SIZE)}")
83
+ except FileTooLarge as e:
84
+ print(e)
85
+ # Output: File size exceeds limit of 10 MiB
86
+ ```
87
+
88
+ ---
89
+
90
+ ## โœจ _Features_
91
+
92
+ | FEATURE | DESCRIPTION |
93
+ | ------------------------ | --------------------------------------------------------------------------------------------------- |
94
+ | ๐Ÿ“ **Unit Helpers** | Standardized functions for all major divisions (`kb`, `mb`, `gb`, `tb`, `kib`, `mib`, `gib`, `tib`) |
95
+ | ๐Ÿงช **Type Preservation** | Dynamically maintains input types (returns int/floats accordingly) |
96
+ | โš™๏ธ **Custom Bases** | Support for both binary (`base=2` / 1024) and decimal (`base=10` / 1000) formats |
97
+ | ๐Ÿ›ก๏ธ **Structured Errors** | Exposes custom `SizeLibError` and `FileTooLarge` exceptions for validation |
98
+ | โšก **Ultra Minimalism** | Zero external dependencies with an optimized, lightweight iteration algorithm |
99
+
100
+ ---
101
+
102
+ ## ๐Ÿ—๏ธ _System Architecture_
103
+
104
+ | # | COMPONENT | DESCRIPTION | STACK |
105
+ | --- | ------------------ | --------------------------------------------------------------- | ------------ |
106
+ | 1๏ธโƒฃ | **Sizelib Size** | The math factor constants and unit calculation helper functions | **_Python_** |
107
+ | 2๏ธโƒฃ | **Sizelib Format** | The humanization formatting module for readable string units | **_Python_** |
108
+
109
+ ---
110
+
111
+ <p align="center">
112
+ Made with ๐Ÿ“„ by <a href="https://hirishi.in">Saptarshi Roy</a>
113
+ </p>
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/sizelib/__init__.py
5
+ src/sizelib/config.py
6
+ src/sizelib/exceptions.py
7
+ src/sizelib/humanize.py
8
+ src/sizelib/size.py
9
+ src/sizelib.egg-info/PKG-INFO
10
+ src/sizelib.egg-info/SOURCES.txt
11
+ src/sizelib.egg-info/dependency_links.txt
12
+ src/sizelib.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ sizelib