storagepy 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.
storagepy/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .core import *
2
+
3
+
storagepy/core.py ADDED
@@ -0,0 +1,141 @@
1
+ def counter(counter):
2
+ try:
3
+ with open(counter,"r") as f:
4
+ p=f.read().split()
5
+ p=''.join(p)
6
+ with open(counter,"w") as f:
7
+ o = int(p) + 1
8
+ f.write(str(o))
9
+ return o
10
+ except FileNotFoundError:
11
+ with open(counter,"w") as f:
12
+ o=0
13
+ f.write(str(o))
14
+ return o
15
+ def upload(f,data):
16
+ items=[]
17
+ for key,value in data.items():
18
+ items.append("|-|")
19
+ items.append(key)
20
+ items.append("-->")
21
+ items.append(value)
22
+ with open(f,"w") as f:
23
+ for i in items:
24
+ f.write(str(i))
25
+
26
+ def read(file):
27
+ with open(file, "r") as f:
28
+ raw = f.read().strip()
29
+
30
+ entries = raw.split("|-|")
31
+ result = {}
32
+
33
+ for entry in entries:
34
+ if "-->" in entry:
35
+ key, value = entry.split("-->")
36
+ result[key] = value
37
+
38
+ return result
39
+
40
+
41
+
42
+
43
+ def createfile(c):
44
+ name = f"dataset_{c}.txt"
45
+ with open(name, "w") as f:
46
+ pass
47
+ return name
48
+
49
+ def tablify(file):
50
+ with open(file, "r") as f:
51
+ raw = f.read().strip()
52
+
53
+ entries = raw.split("|-|")
54
+ result = {}
55
+
56
+ for entry in entries:
57
+ if "-->" in entry:
58
+ key, value = entry.split("-->")
59
+ result[key] = value
60
+
61
+ row_in = []
62
+ row_out = []
63
+
64
+ for key, value in result.items():
65
+ row_in.append(key)
66
+ row_out.append(value)
67
+
68
+ a = []
69
+
70
+ for i in row_in:
71
+ idx = row_in.index(i)
72
+ a.append(f"{i} | {row_out[idx]}")
73
+ colum_1=input("Name Colum 1: ")
74
+ colum_2=input("Name Colum 2: ")
75
+ import os
76
+ os.system("cls")
77
+ colums=f"""{colum_1} | {colum_2}"""
78
+ b=""""""
79
+ b=b+colums+"\n"+"-"*len(colums)+"\n"
80
+ for i in a:
81
+ b=b+i+"\n"
82
+ return b
83
+ def find(pair_key,data):
84
+ import os
85
+ counter=0
86
+ matches={}
87
+ keys=[]
88
+ for key,value in data.items():
89
+ if key.lower() == pair_key.lower():
90
+ counter+=1
91
+ matches[key]=value
92
+ keys.append(key)
93
+ if counter == 1:
94
+ print("Match Found!")
95
+ os.system("cls")
96
+ return matches
97
+ else:
98
+ print("No Match Found!")
99
+ os.system("cls")
100
+ return None
101
+ def encrypt(file):
102
+ with open(file, "r") as f:
103
+ raw = f.read().encode()
104
+
105
+ encrypted = FERNET.encrypt(raw)
106
+
107
+ with open(file, "wb") as f:
108
+ f.write(encrypted)
109
+
110
+ return encrypted
111
+ def decrypt(file):
112
+ with open(file, "rb") as f:
113
+ encrypted = f.read()
114
+
115
+ decrypted = FERNET.decrypt(encrypted)
116
+
117
+ with open(file, "w") as f:
118
+ f.write(decrypted.decode())
119
+
120
+ return decrypted.decode()
121
+
122
+ #===============================================
123
+ import os
124
+ from cryptography.fernet import Fernet
125
+
126
+ KEYFILE = "storagepy.key"
127
+
128
+ def load_or_create_key():
129
+ if not os.path.exists(KEYFILE):
130
+ key = Fernet.generate_key()
131
+ with open(KEYFILE, "wb") as f:
132
+ f.write(key)
133
+ return key
134
+ else:
135
+ with open(KEYFILE, "rb") as f:
136
+ return f.read()
137
+
138
+ # Auto-load key at module import
139
+ KEY = load_or_create_key()
140
+ FERNET = Fernet(KEY)
141
+ #===========================================================
@@ -0,0 +1,58 @@
1
+ Metadata-Version: 2.4
2
+ Name: storagepy
3
+ Version: 0.1.0
4
+ Summary: A simple text-based storage system where you can create tables, store data, and more! Encryption is included for data files.
5
+ Author: Yuvaan Pandita
6
+ Author-email: Nehan Nishad <creativenehan@gmail.com>
7
+ License: MIT
8
+ Requires-Python: >=3.8
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: cryptography
12
+ Dynamic: license-file
13
+
14
+ # storagepy
15
+
16
+ storagepy is a lightweight text-based key-value storage system with strong AES encryption.
17
+ All functionality is contained in a single file: `core.py`.
18
+
19
+ ## Features
20
+
21
+ - Simple key-value text storage
22
+ - Automatic AES encryption key generation
23
+ - Strong encryption/decryption using Fernet (AES-128)
24
+ - Table formatting
25
+ - Key lookup
26
+ - Easy file creation
27
+
28
+ ## Installation
29
+ pip install storagepy
30
+
31
+ ## Usage
32
+ Create a file
33
+ from storagepy import create
34
+
35
+ # Create a new storage file
36
+ create("data.txt")
37
+ ### Create a file
38
+ ```python
39
+ from storagepy.core import createfile
40
+ createfile("data.txt")
41
+ ### Upload data
42
+ from storagepy.core import upload
43
+ upload("data.txt", {"Name": "John", "Age": 15})
44
+ ### Encrypt file
45
+ from storagepy.core import encrypt
46
+ encrypt("data.txt")
47
+ ### Decrypt file
48
+ from storagepy.core import decrypt
49
+ decrypt("data.txt")
50
+ ### Tablify (format)
51
+ from storagepy.core import tablify
52
+ print(tablify("data.txt"))
53
+ ### Find data
54
+ from storagepy.core import find
55
+ print(find("Name", {"Name": "John", "Age": 15}))
56
+ ###License
57
+ MIT
58
+
@@ -0,0 +1,7 @@
1
+ storagepy/__init__.py,sha256=Uq-z-BRJL2N4tBnL2quXXe0g8phv-M3RnVo07McT4QQ,25
2
+ storagepy/core.py,sha256=897UlCmg3qUEjcz_CqRq09Upf5ceFEnGVUNgfxyuws0,3296
3
+ storagepy-0.1.0.dist-info/licenses/LICENSE,sha256=b_R-VqlUxCH_I1zYu0mahyNtUql2kaTiR_w5g_O7fzg,1117
4
+ storagepy-0.1.0.dist-info/METADATA,sha256=nSrRGnGKHRCM_Co9Qfpk_QRgT0vCW-uY8T95HAw2o8M,1496
5
+ storagepy-0.1.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
6
+ storagepy-0.1.0.dist-info/top_level.txt,sha256=Ccan32AOzvrSECgRbx79H-pWybvM8L7y46B7YDoUnys,10
7
+ storagepy-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (83.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Yuvaan Pandita and Nehan Nishad
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.
@@ -0,0 +1 @@
1
+ storagepy