simple-storage-python-module 1.1.4__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.
@@ -0,0 +1,8 @@
1
+ MIT License
2
+ Copyright 2026 Andrew Abdelmalek
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,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple_storage_python_module
3
+ Version: 1.1.4
4
+ Summary: A small, easy to use module that helps you store data easily.
5
+ Author-email: Andrew Abdelmalek <aa2@olprahraneast.catholic.edu.au>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://simple-storage-module.netlify.app
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Dynamic: license-file
14
+
15
+ # simple-storage
16
+
17
+ A tiny Python module for safely saving and loading JSON data.
18
+
19
+ ## Install
20
+ ```bash
21
+ pip install simple_storage_python_module
@@ -0,0 +1,7 @@
1
+ # simple-storage
2
+
3
+ A tiny Python module for safely saving and loading JSON data.
4
+
5
+ ## Install
6
+ ```bash
7
+ pip install simple_storage_python_module
@@ -0,0 +1,23 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "simple_storage_python_module"
7
+ version = "1.1.4"
8
+ authors = [
9
+ { name="Andrew Abdelmalek", email="aa2@olprahraneast.catholic.edu.au" },
10
+ ]
11
+ description = "A small, easy to use module that helps you store data easily."
12
+ readme = "README.md"
13
+ requires-python = ">=3.9"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "Operating System :: OS Independent",
17
+ ]
18
+ license = "MIT"
19
+ license-files = ["LICENSE.txt"]
20
+
21
+ [project.urls]
22
+ Homepage = "https://simple-storage-module.netlify.app"
23
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .simple_storage import (safe_save, safe_load, save, load, exists, delete)
2
+
3
+ __all__ = ["safe_save", "safe_load", "save", "load", "exists", "delete"]
@@ -0,0 +1,127 @@
1
+ # Simple Storage
2
+ # Descripton: Easy to use long term storage module
3
+ # Version 1.1.0
4
+ # Documentation at this link:
5
+ # By Andrew Abdelmalek
6
+ # © 2026 Andrew Abdelmalek
7
+
8
+ import json
9
+ import os
10
+ import base64
11
+
12
+ _STORAGE_FOLDER = "simple_storage_folder"
13
+ os.makedirs(_STORAGE_FOLDER, exist_ok=True)
14
+
15
+
16
+ _STORAGE_FOLDER = "simple_storage_folder"
17
+ _KEY = b"MyFixedSecretKey1234567890pneumonoutramicroscopicsilicovoclacjkku49^^&6348736*&^#^*&(#*(^t5v-m(&(#*&$_+?"
18
+
19
+
20
+ def _ensure_folder(): # Helper function
21
+ if not os.path.exists(_STORAGE_FOLDER): #Checks if storage folder exists
22
+ os.makedirs(_STORAGE_FOLDER)# If not, creates
23
+
24
+
25
+ def _file_path(name): #Helper Function
26
+ return os.path.join(_STORAGE_FOLDER, f"{name}.json")
27
+
28
+ def save(name, data): #Save any JSON-safe data (dict, list, str, int, etc.)u
29
+ if not name or data == "":
30
+ raise ValueError("Error while saving information: No value in argument 'name' and/or 'data'")
31
+ _ensure_folder()
32
+ with open(_file_path(name), "w", encoding="utf-8") as f: # Opens file
33
+ json.dump(data, f, indent=4)
34
+
35
+ def load(name, default=None): #Load saved data. Returns default if not found.
36
+ try:
37
+ with open(_file_path(name), "r", encoding="utf-8") as f:
38
+ return json.load(f)
39
+ except FileNotFoundError:
40
+ return default
41
+
42
+ def _encrypt_string(s: str) -> str:
43
+ encrypted_bytes = bytes([b ^ _KEY[i % len(_KEY)] for i, b in enumerate(s.encode())])
44
+ return base64.b64encode(encrypted_bytes).decode()
45
+
46
+
47
+ def _decrypt_string(s: str) -> str:
48
+ encrypted_bytes = base64.b64decode(s.encode())
49
+ decrypted_bytes = bytes([b ^ _KEY[i % len(_KEY)] for i, b in enumerate(encrypted_bytes)])
50
+ return decrypted_bytes.decode()
51
+
52
+ def safe_save(name: str, data):
53
+ """
54
+ Encrypts the JSON data and saves it to a file.
55
+ """
56
+ if not name or data:
57
+ raise ValueError("Error while saving information: No value in argument 'name' and/or 'data'")
58
+ json_str = json.dumps(data)
59
+ encrypted_str = _encrypt_string(json_str)
60
+ with open(_file_path(name), "w") as f:
61
+ f.write(encrypted_str)
62
+
63
+
64
+ def safe_load(name: str):
65
+ """
66
+ Loads the file and decrypts the JSON data.
67
+ Returns the original Python object.
68
+ """
69
+ if not os.path.exists(_file_path(name)):
70
+ return None
71
+ with open(_file_path(name), "r") as f:
72
+ encrypted_str = f.read()
73
+ json_str = _decrypt_string(encrypted_str)
74
+ return json.loads(json_str)
75
+
76
+
77
+
78
+ def exists(name): #Check if a saved item exists.
79
+ return os.path.exists(_file_path(name))
80
+
81
+
82
+ def delete(name): #Delete saved data.
83
+ if exists(name):
84
+ os.remove(_file_path(name))
85
+
86
+ # MODULE TEST
87
+ def _run_tests():
88
+ print("Running simple_storage tests...")
89
+
90
+ test_name = "__test_item__"
91
+
92
+ # Clean up before test
93
+ if exists(test_name):
94
+ delete(test_name)
95
+
96
+ # Test: file should not exist
97
+ assert not exists(test_name), "Test failed: file should not exist"
98
+
99
+ # Test: save data
100
+ data = {
101
+ "name": "Test",
102
+ "value": 123,
103
+ "active": True
104
+ }
105
+ save(test_name, data)
106
+
107
+ # Test: file should exist
108
+ assert exists(test_name), "Test failed: file should exist"
109
+
110
+ # Test: load data
111
+ loaded = load(test_name)
112
+ assert loaded == data, "Test failed: loaded data does not match saved data"
113
+
114
+ # Test: load with default
115
+ missing = load("does_not_exist", default="default")
116
+ assert missing == "default", "Test failed: default value not returned"
117
+
118
+ # Test: delete data
119
+ delete(test_name)
120
+ assert not exists(test_name), "Test failed: file was not deleted"
121
+
122
+ print("All tests passed successfully.")
123
+
124
+
125
+ if __name__ == "__main__":
126
+ _run_tests()
127
+
@@ -0,0 +1,21 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple_storage_python_module
3
+ Version: 1.1.4
4
+ Summary: A small, easy to use module that helps you store data easily.
5
+ Author-email: Andrew Abdelmalek <aa2@olprahraneast.catholic.edu.au>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://simple-storage-module.netlify.app
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE.txt
13
+ Dynamic: license-file
14
+
15
+ # simple-storage
16
+
17
+ A tiny Python module for safely saving and loading JSON data.
18
+
19
+ ## Install
20
+ ```bash
21
+ pip install simple_storage_python_module
@@ -0,0 +1,9 @@
1
+ LICENSE.txt
2
+ README.md
3
+ pyproject.toml
4
+ src/simple_storage_module_SIMPLES/_init_.py
5
+ src/simple_storage_module_SIMPLES/simple_storage.py
6
+ src/simple_storage_python_module.egg-info/PKG-INFO
7
+ src/simple_storage_python_module.egg-info/SOURCES.txt
8
+ src/simple_storage_python_module.egg-info/dependency_links.txt
9
+ src/simple_storage_python_module.egg-info/top_level.txt