nestio 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.
nestio-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nestio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the "Software"),
7
+ to deal in the Software without restriction, including without limitation
8
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ and/or sell copies of the Software, and to permit persons to whom the
10
+ Software is furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ OR 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
20
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
+ DEALINGS IN THE SOFTWARE.
nestio-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: nestio
3
+ Version: 0.1.0
4
+ Summary: Async-first nested JSON/TOML storage with dot-path access and atomic writes
5
+ Author: MrBaconHat
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/MrBaconHat/nestio
8
+ Project-URL: Repository, https://github.com/MrBaconHat/nestio
9
+ Project-URL: Issues, https://github.com/MrBaconHat/nestio/issues
10
+ Keywords: async,json,storage,database,nest,dotpath
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Classifier: Topic :: Database
15
+ Classifier: Framework :: AsyncIO
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: aiofiles>=23.0.0
20
+ Dynamic: license-file
nestio-0.1.0/README.md ADDED
File without changes
@@ -0,0 +1 @@
1
+ from .json import Json
@@ -0,0 +1,129 @@
1
+ import aiofiles
2
+ import tempfile
3
+ import os
4
+ from pathlib import Path
5
+
6
+ from .lock import LockManager
7
+
8
+
9
+ class BaseStorage:
10
+ def __init__(self, path: str):
11
+ self.path = Path(path)
12
+ self.path.parent.mkdir(parents=True, exist_ok=True)
13
+
14
+ self._lock_manager = LockManager()
15
+
16
+ # --- format layer ---
17
+ def _serialize(self, data): ...
18
+ def _deserialize(self, text): ...
19
+
20
+ # --- IO ---
21
+ async def _load(self):
22
+ try:
23
+ async with aiofiles.open(self.path, "r", encoding="utf-8") as f:
24
+ return self._deserialize(await f.read())
25
+ except FileNotFoundError:
26
+ return {}
27
+
28
+ async def _save(self, data):
29
+ content = self._serialize(data)
30
+
31
+ with tempfile.NamedTemporaryFile(
32
+ "w",
33
+ dir=self.path.parent,
34
+ delete=False,
35
+ encoding="utf-8"
36
+ ) as tmp:
37
+ tmp.write(content)
38
+ tmp.flush()
39
+ os.fsync(tmp.fileno())
40
+ temp_path = tmp.name
41
+
42
+ os.replace(temp_path, self.path)
43
+
44
+ # --- helpers ---
45
+ def _resolve_parent(self, data, path, create=False):
46
+ keys = path.split(".")
47
+ current = data
48
+
49
+ for k in keys[:-1]:
50
+ if k not in current:
51
+ if create:
52
+ current[k] = {}
53
+ else:
54
+ raise KeyError(path)
55
+
56
+ if not isinstance(current[k], dict):
57
+ raise TypeError(f"Invalid path: {path}")
58
+
59
+ current = current[k]
60
+
61
+ return current, keys[-1]
62
+
63
+ def _deep_merge(self, original, new):
64
+ for k, v in new.items():
65
+ if isinstance(v, dict) and isinstance(original.get(k), dict):
66
+ self._deep_merge(original[k], v)
67
+ else:
68
+ original[k] = v
69
+
70
+ # ==== Functions ====
71
+ async def get(self, path, default=None):
72
+ data = await self._load()
73
+
74
+ try:
75
+ parent, key = self._resolve_parent(data, path)
76
+ return parent.get(key, default)
77
+ except Exception:
78
+ return default
79
+
80
+ async def set(self, path, value):
81
+ async with await self._lock_manager.get(path):
82
+ data = await self._load()
83
+
84
+ parent, key = self._resolve_parent(data, path, create=True)
85
+ parent[key] = value
86
+
87
+ await self._save(data)
88
+
89
+ async def delete(self, path):
90
+ async with await self._lock_manager.get(path):
91
+ data = await self._load()
92
+
93
+ parent, key = self._resolve_parent(data, path)
94
+
95
+ if key in parent:
96
+ del parent[key]
97
+ await self._save(data)
98
+
99
+ async def append(self, path, value):
100
+ async with await self._lock_manager.get(path):
101
+ data = await self._load()
102
+
103
+ parent, key = self._resolve_parent(data, path, create=True)
104
+
105
+ if key not in parent:
106
+ parent[key] = []
107
+
108
+ if not isinstance(parent[key], list):
109
+ raise TypeError("Target is not a list")
110
+
111
+ parent[key].append(value)
112
+
113
+ await self._save(data)
114
+
115
+ async def update(self, path, new_data: dict):
116
+ async with await self._lock_manager.get(path):
117
+ data = await self._load()
118
+
119
+ parent, key = self._resolve_parent(data, path, create=True)
120
+
121
+ if key not in parent:
122
+ parent[key] = {}
123
+
124
+ if not isinstance(parent[key], dict):
125
+ raise TypeError("Target is not a dict")
126
+
127
+ self._deep_merge(parent[key], new_data)
128
+
129
+ await self._save(data)
@@ -0,0 +1,13 @@
1
+ import json
2
+ from .base import BaseStorage
3
+
4
+
5
+ class Json(BaseStorage):
6
+ def __init__(self, path: str):
7
+ super().__init__(path)
8
+
9
+ def _serialize(self, data):
10
+ return json.dumps(data, indent=4)
11
+
12
+ def _deserialize(self, text):
13
+ return json.loads(text)
@@ -0,0 +1,26 @@
1
+ import asyncio
2
+ import time
3
+
4
+
5
+ class LockManager:
6
+ def __init__(self, ttl=300):
7
+ self._locks = {}
8
+ self._last_used = {}
9
+ self._ttl = ttl
10
+ self._global = asyncio.Lock()
11
+
12
+ async def get(self, key: str) -> asyncio.Lock:
13
+ async with self._global:
14
+ now = time.monotonic()
15
+
16
+ # cleanup old locks
17
+ for k in list(self._locks.keys()):
18
+ if now - self._last_used.get(k, 0) > self._ttl:
19
+ del self._locks[k]
20
+ del self._last_used[k]
21
+
22
+ if key not in self._locks:
23
+ self._locks[key] = asyncio.Lock()
24
+
25
+ self._last_used[key] = now
26
+ return self._locks[key]
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.4
2
+ Name: nestio
3
+ Version: 0.1.0
4
+ Summary: Async-first nested JSON/TOML storage with dot-path access and atomic writes
5
+ Author: MrBaconHat
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/MrBaconHat/nestio
8
+ Project-URL: Repository, https://github.com/MrBaconHat/nestio
9
+ Project-URL: Issues, https://github.com/MrBaconHat/nestio/issues
10
+ Keywords: async,json,storage,database,nest,dotpath
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Software Development :: Libraries
14
+ Classifier: Topic :: Database
15
+ Classifier: Framework :: AsyncIO
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: aiofiles>=23.0.0
20
+ Dynamic: license-file
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ nestio/__init__.py
5
+ nestio/base.py
6
+ nestio/json.py
7
+ nestio/lock.py
8
+ nestio.egg-info/PKG-INFO
9
+ nestio.egg-info/SOURCES.txt
10
+ nestio.egg-info/dependency_links.txt
11
+ nestio.egg-info/requires.txt
12
+ nestio.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ aiofiles>=23.0.0
@@ -0,0 +1 @@
1
+ nestio
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+
6
+ [project]
7
+ name = "nestio"
8
+ version = "0.1.0"
9
+ description = "Async-first nested JSON/TOML storage with dot-path access and atomic writes"
10
+ readme = "README.md"
11
+ requires-python = ">=3.9"
12
+ license = {text = "MIT"}
13
+
14
+ authors = [
15
+ {name = "MrBaconHat"}
16
+ ]
17
+
18
+ dependencies = [
19
+ "aiofiles>=23.0.0"
20
+ ]
21
+
22
+ keywords = [
23
+ "async",
24
+ "json",
25
+ "storage",
26
+ "database",
27
+ "nest",
28
+ "dotpath"
29
+ ]
30
+
31
+ classifiers = [
32
+ "Programming Language :: Python :: 3",
33
+ "Operating System :: OS Independent",
34
+ "Topic :: Software Development :: Libraries",
35
+ "Topic :: Database",
36
+ "Framework :: AsyncIO"
37
+ ]
38
+
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/MrBaconHat/nestio"
42
+ Repository = "https://github.com/MrBaconHat/nestio"
43
+ Issues = "https://github.com/MrBaconHat/nestio/issues"
44
+
45
+
46
+ [tool.setuptools]
47
+ packages = ["nestio"]
nestio-0.1.0/setup.cfg ADDED
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+