funbase 0.0.1__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.
funbase/__init__.py
ADDED
funbase/funbase.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Any, Dict, List, Optional
|
|
5
|
+
|
|
6
|
+
# ↓↓↓ ТОЛЬКО ЭТО МЕСТО МОЖНО МЕНЯТЬ НА СВОЙ ШИФР ↓↓↓
|
|
7
|
+
from cryptography.fernet import Fernet # pip install cryptography
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FunBase:
|
|
11
|
+
"""
|
|
12
|
+
Файловая база FunBase.
|
|
13
|
+
Файлы: *.fb (funbase format).
|
|
14
|
+
Шифрование вынесено в отдельный метод — его можно заменить.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, db_path: str, key: Optional[bytes] = None):
|
|
18
|
+
if not db_path.endswith(".fb"):
|
|
19
|
+
raise ValueError("FunBase file must have extension .fb")
|
|
20
|
+
|
|
21
|
+
self.db_path = db_path
|
|
22
|
+
self.key = key or Fernet.generate_key()
|
|
23
|
+
self.cipher = Fernet(self.key) # одно место с шифром
|
|
24
|
+
|
|
25
|
+
self.data: Dict[str, List[Dict]] = {}
|
|
26
|
+
self._load()
|
|
27
|
+
|
|
28
|
+
def _encrypt(self, data: bytes) -> bytes:
|
|
29
|
+
"""Здесь можно поменять шифрацию на свою."""
|
|
30
|
+
return self.cipher.encrypt(data)
|
|
31
|
+
|
|
32
|
+
def _decrypt(self, data: bytes) -> bytes:
|
|
33
|
+
"""Здесь можно поменять дешифрацию на свою."""
|
|
34
|
+
return self.cipher.decrypt(data)
|
|
35
|
+
|
|
36
|
+
def _load(self):
|
|
37
|
+
if not os.path.exists(self.db_path):
|
|
38
|
+
self.data = {}
|
|
39
|
+
self._save()
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
with open(self.db_path, "rb") as f:
|
|
43
|
+
encrypted = f.read()
|
|
44
|
+
|
|
45
|
+
decrypted = self._decrypt(encrypted)
|
|
46
|
+
self.data = json.loads(decrypted.decode("utf-8"))
|
|
47
|
+
|
|
48
|
+
def _save(self):
|
|
49
|
+
raw = json.dumps(self.data, ensure_ascii=False).encode("utf-8")
|
|
50
|
+
encrypted = self._encrypt(raw)
|
|
51
|
+
|
|
52
|
+
with open(self.db_path, "wb") as f:
|
|
53
|
+
f.write(encrypted)
|
|
54
|
+
|
|
55
|
+
def create_table(self, table_name: str) -> "FunBase":
|
|
56
|
+
if table_name not in self.data:
|
|
57
|
+
self.data[table_name] = []
|
|
58
|
+
self._save()
|
|
59
|
+
return self
|
|
60
|
+
|
|
61
|
+
def insert(self, table_name: str, record: Dict[str, Any]) -> "FunBase":
|
|
62
|
+
table = self.data.setdefault(table_name, [])
|
|
63
|
+
table.append(record)
|
|
64
|
+
self._save()
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def select_all(self, table_name: str) -> List[Dict]:
|
|
68
|
+
return self.data.get(table_name, [])
|
|
69
|
+
|
|
70
|
+
def delete_table(self, table_name: str) -> "FunBase":
|
|
71
|
+
if table_name in self.data:
|
|
72
|
+
del self.data[table_name]
|
|
73
|
+
self._save()
|
|
74
|
+
return self
|
|
75
|
+
|
|
76
|
+
def get_key(self) -> bytes:
|
|
77
|
+
"""Вернуть ключ; его нужно сохранить отдельно."""
|
|
78
|
+
return self.key
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: funbase
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: FunBase: encrypted file-based database with .fb extension
|
|
5
|
+
Author: Nite017
|
|
6
|
+
Author-email: Nite017 <nite27845@yandex.ru>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Nite017
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
Project-URL: Homepage, https://github.com/Nite017/funbase
|
|
29
|
+
Project-URL: Repository, https://github.com/Nite017/funbase
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
32
|
+
Classifier: Operating System :: OS Independent
|
|
33
|
+
Requires-Python: >=3.7
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
License-File: LICENSE
|
|
36
|
+
Requires-Dist: cryptography>=3.4
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
Dynamic: requires-python
|
|
40
|
+
|
|
41
|
+
# funbase
|
|
42
|
+
|
|
43
|
+
FunBase — простая файловая база данных с шифрованием и расширением `.fb`.
|
|
44
|
+
|
|
45
|
+
## Установка
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install funbase
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Использование
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from funbase import FunBase
|
|
55
|
+
from cryptography.fernet import Fernet
|
|
56
|
+
|
|
57
|
+
# ключ один раз создать и сохранить
|
|
58
|
+
key = Fernet.generate_key()
|
|
59
|
+
db = FunBase("data.fb", key)
|
|
60
|
+
|
|
61
|
+
db.create_table("users")
|
|
62
|
+
db.insert("users", {"id": 1, "name": "Alice"})
|
|
63
|
+
print(db.select_all("users"))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Файлы базы данных имеют расширение `.fb` и зашифрованы с помощью `cryptography.fernet`.
|
|
67
|
+
Шифрование можно заменить, правя методы `_encrypt` и `_decrypt` в `FunBase`.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
funbase/__init__.py,sha256=3Qqqs9Z5ZQxzewSVBHy-efuDTa99M4VhnAqVyHbs2TU,53
|
|
2
|
+
funbase/funbase.py,sha256=32GSjuoE8cJSQjzXPv8G95kpwgALEDeO6jrQMSH50rA,2645
|
|
3
|
+
funbase-0.0.1.dist-info/licenses/LICENSE,sha256=aiGl5HrpJmbnWy2Z08qZophI9gLuGy92By03lPmxV2c,1074
|
|
4
|
+
funbase-0.0.1.dist-info/METADATA,sha256=3hoMuZeeB0uX6x2aNHkeiK9tOSczaLoHsAQR4opdTcI,2699
|
|
5
|
+
funbase-0.0.1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
6
|
+
funbase-0.0.1.dist-info/top_level.txt,sha256=6jOaINYGFuOhmoKIaH--6ish5OUeB7_snxvAU1YysMg,8
|
|
7
|
+
funbase-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nite017
|
|
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 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
|
+
funbase
|