Name | pydantic-storage JSON |
Version |
0.1.1
JSON |
| download |
home_page | None |
Summary | A lightweight, type-safe storage system for Pydantic models with support for multiple backends and persistent storage. |
upload_time | 2025-08-11 14:26:08 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.13 |
license | # MIT License Copyright (c) 2025 Shailesh Pandit 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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. |
keywords |
bulk-create
data-management
data-storage
data-validation
datastore
file-storage
json-storage
lightweight-storage
metadata
model-storage
object-storage
partial-update
persistent-storage
pydantic
pydantic-model
python-storage
python3
schema-validation
structured-storage
type-safe
unique-constraint
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# ๐๏ธ PydanticStorage
[](https://pypi.org/project/pydantic-storage/)
[](https://pypi.org/project/pydantic-storage/)
[](https://github.com/yourusername/pydantic-storage/blob/main/LICENSE)
A lightweight, extensible, and fully type-safe data storage system built with **Pydantic** and modern Python. Initially file-based (JSON), it's designed to support multiple backends like CSV, SQL, and more. It enables persistent storage of Pydantic models, auto-generated IDs, metadata, uniqueness constraints, partial updates, and structured storage with a real-world schema.
## ๐ Features
* โ
JSON-based file storage for Pydantic models
* ๐ Unique field constraint (e.g., prevent duplicate emails)
* ๐ Auto ID assignment starting from `1`
* ๐งฉ Partial & full record updates
* ๐๏ธ Structured schema with `metadata` + `records`
* ๐งน Methods like `filter`, `exists`, `count`, `clear`, `create`, `bulk_create`, etc.
* ๐ฆ Metadata support
## ๐ฆ Installation
Install the package using your preferred Python package manager:
### Using `uv`
```bash
uv add pydantic-storage
```
### Using `pip`
```bash
pip install pydantic-storage
```
## ๐ง Usage
### 1. Define your Pydantic model
```python
from pydantic import BaseModel
class User(BaseModel):
id: int | None = None
name: str
email: str
```
### 2. Initialize Storage
```python
from pydantic_storage import JsonFileStorage
store = JsonFileStorage(
model=User,
uri="records/users.json",
unique_fileds=["email"],
metadata={
"version": "1.0.0",
"title": "User Store",
"description": "Stores user info",
}
)
```
### 3. Create Records
```python
store.create(User(name="Alice", email="alice@example.com"))
store.create(User(name="Bob", email="bob@example.com"))
```
### 4. Get or Filter Records
```python
user = store.get("email", "alice@example.com")
users = store.filter(lambda user: user.name.startswith("A"))
```
### 5. Update Records
```python
# Full update using function
store.update("id", 1, lambda user: user.model_copy(
update={"email": "new@example.com"}
))
# Partial update
store.update_partial("id", 2, {"name": "Robert"})
```
### 6. Delete or Clear all Records
```python
store.delete("email", "bob@example.com")
store.clear()
```
### 7. Bulk Create
```python
store.bulk_create([
User(name="Charlie", email="charlie@example.com"),
User(name="Alice", email="alice@example.com") # Skipped if duplicate
])
```
## ๐ JSON Structure Example
```json
{
"metadata": {
"version": "1.0.0",
"title": "User records",
"description": "User record descriptions",
"storage": {
"backend": "file",
"format": "json",
"encryption": "none",
"uri": "file:///mnt/data/workshop/applications/pypi-package/pydantic-storage/tests/db_files/users.json"
},
"timestamps": {
"created_at": "2025-08-11T13:54:05.071548Z",
"accessed_at": "2025-08-11T13:56:19.872671Z",
"modified_at": "2025-08-11T13:56:19.872308Z"
}
},
"records": [
{
"id": 1,
"name": "shailesh",
"email": "shailesh@gmail.com"
},
{
"id": 2,
"name": "yash",
"email": "yash@gmail.com"
},
{
"id": 3,
"name": "json",
"email": "json@gmail.com"
},
{
"id": 4,
"name": "nice",
"email": "nice@gmail.com"
},
{
"id": 5,
"name": "yashika",
"email": "yashika@gmail.com"
}
]
}
```
## โ Exceptions
* `DuplicateEntryError`: Raised when uniqueness is violated on `create`.
* `ValidationError`: Raised if an action violates the model schema.
## ๐งช Testing
Run tests with:
```bash
pytest tests
```
Covers record creation, uniqueness, updates, deletions, and metadata.
## ๐ ๏ธ Planned Features
* ๐ Optional encryption
* ๐ฆ Export/import to CSV, SQLite
* ๐ Automatic backups
* ๐งช Pytest-based suite
* ๐ Schema evolution support
## ๐ค Contributing
Contributions are welcome! Please open an issue or PR for any improvements.
## ๐ License
MIT License. See the LICENSE file for details.
## ๐ค Author
For questions or assistance, contact **Shailesh** at [shaileshpandit141@gmail.com](mailto:shaileshpandit141@gmail.com).
Raw data
{
"_id": null,
"home_page": null,
"name": "pydantic-storage",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.13",
"maintainer_email": null,
"keywords": "bulk-create, data-management, data-storage, data-validation, datastore, file-storage, json-storage, lightweight-storage, metadata, model-storage, object-storage, partial-update, persistent-storage, pydantic, pydantic-model, python-storage, python3, schema-validation, structured-storage, type-safe, unique-constraint",
"author": null,
"author_email": "shaileshpandit141 <shaileshpandit141@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c2/f3/6507e7240f282103756e9a70b12e940c21f4f00266879c339e763582f230/pydantic_storage-0.1.1.tar.gz",
"platform": null,
"description": "# \ud83d\uddc3\ufe0f PydanticStorage\n\n[](https://pypi.org/project/pydantic-storage/)\n[](https://pypi.org/project/pydantic-storage/)\n[](https://github.com/yourusername/pydantic-storage/blob/main/LICENSE)\n\nA lightweight, extensible, and fully type-safe data storage system built with **Pydantic** and modern Python. Initially file-based (JSON), it's designed to support multiple backends like CSV, SQL, and more. It enables persistent storage of Pydantic models, auto-generated IDs, metadata, uniqueness constraints, partial updates, and structured storage with a real-world schema.\n\n## \ud83d\ude80 Features\n\n* \u2705 JSON-based file storage for Pydantic models\n* \ud83d\udd10 Unique field constraint (e.g., prevent duplicate emails)\n* \ud83c\udd94 Auto ID assignment starting from `1`\n* \ud83e\udde9 Partial & full record updates\n* \ud83d\uddc2\ufe0f Structured schema with `metadata` + `records`\n* \ud83e\uddf9 Methods like `filter`, `exists`, `count`, `clear`, `create`, `bulk_create`, etc.\n* \ud83d\udce6 Metadata support\n\n## \ud83d\udce6 Installation\n\nInstall the package using your preferred Python package manager:\n\n### Using `uv`\n\n```bash\nuv add pydantic-storage\n```\n\n### Using `pip`\n\n```bash\npip install pydantic-storage\n```\n\n## \ud83e\udde0 Usage\n\n### 1. Define your Pydantic model\n\n```python\nfrom pydantic import BaseModel\n\nclass User(BaseModel):\n id: int | None = None\n name: str\n email: str\n```\n\n### 2. Initialize Storage\n\n```python\nfrom pydantic_storage import JsonFileStorage\n\nstore = JsonFileStorage(\n model=User,\n uri=\"records/users.json\",\n unique_fileds=[\"email\"],\n metadata={\n \"version\": \"1.0.0\",\n \"title\": \"User Store\",\n \"description\": \"Stores user info\",\n }\n)\n```\n\n### 3. Create Records\n\n```python\nstore.create(User(name=\"Alice\", email=\"alice@example.com\"))\nstore.create(User(name=\"Bob\", email=\"bob@example.com\"))\n```\n\n### 4. Get or Filter Records\n\n```python\nuser = store.get(\"email\", \"alice@example.com\")\nusers = store.filter(lambda user: user.name.startswith(\"A\"))\n```\n\n### 5. Update Records\n\n```python\n# Full update using function\nstore.update(\"id\", 1, lambda user: user.model_copy(\n update={\"email\": \"new@example.com\"}\n))\n\n# Partial update\nstore.update_partial(\"id\", 2, {\"name\": \"Robert\"})\n```\n\n### 6. Delete or Clear all Records\n\n```python\nstore.delete(\"email\", \"bob@example.com\")\nstore.clear()\n```\n\n### 7. Bulk Create\n\n```python\nstore.bulk_create([\n User(name=\"Charlie\", email=\"charlie@example.com\"),\n User(name=\"Alice\", email=\"alice@example.com\") # Skipped if duplicate\n])\n```\n\n## \ud83d\udcc1 JSON Structure Example\n\n```json\n{\n \"metadata\": {\n \"version\": \"1.0.0\",\n \"title\": \"User records\",\n \"description\": \"User record descriptions\",\n \"storage\": {\n \"backend\": \"file\",\n \"format\": \"json\",\n \"encryption\": \"none\",\n \"uri\": \"file:///mnt/data/workshop/applications/pypi-package/pydantic-storage/tests/db_files/users.json\"\n },\n \"timestamps\": {\n \"created_at\": \"2025-08-11T13:54:05.071548Z\",\n \"accessed_at\": \"2025-08-11T13:56:19.872671Z\",\n \"modified_at\": \"2025-08-11T13:56:19.872308Z\"\n }\n },\n \"records\": [\n {\n \"id\": 1,\n \"name\": \"shailesh\",\n \"email\": \"shailesh@gmail.com\"\n },\n {\n \"id\": 2,\n \"name\": \"yash\",\n \"email\": \"yash@gmail.com\"\n },\n {\n \"id\": 3,\n \"name\": \"json\",\n \"email\": \"json@gmail.com\"\n },\n {\n \"id\": 4,\n \"name\": \"nice\",\n \"email\": \"nice@gmail.com\"\n },\n {\n \"id\": 5,\n \"name\": \"yashika\",\n \"email\": \"yashika@gmail.com\"\n }\n ]\n}\n```\n\n## \u2757 Exceptions\n\n* `DuplicateEntryError`: Raised when uniqueness is violated on `create`.\n* `ValidationError`: Raised if an action violates the model schema.\n\n## \ud83e\uddea Testing\n\nRun tests with:\n\n```bash\npytest tests\n```\n\nCovers record creation, uniqueness, updates, deletions, and metadata.\n\n## \ud83d\udee0\ufe0f Planned Features\n\n* \ud83d\udd12 Optional encryption\n* \ud83d\udce6 Export/import to CSV, SQLite\n* \ud83d\udd52 Automatic backups\n* \ud83e\uddea Pytest-based suite\n* \ud83d\udcca Schema evolution support\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Please open an issue or PR for any improvements.\n\n## \ud83d\udcc4 License\n\nMIT License. See the LICENSE file for details.\n\n## \ud83d\udc64 Author\n\nFor questions or assistance, contact **Shailesh** at [shaileshpandit141@gmail.com](mailto:shaileshpandit141@gmail.com).\n",
"bugtrack_url": null,
"license": "# MIT License Copyright (c) 2025 Shailesh Pandit 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: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 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.",
"summary": "A lightweight, type-safe storage system for Pydantic models with support for multiple backends and persistent storage.",
"version": "0.1.1",
"project_urls": {
"Homepage": "https://github.com/shaileshpandit141/pydantic-storage",
"Issues": "https://github.com/shaileshpandit141/pydantic-storage/issues",
"Repository": "https://github.com/shaileshpandit141/pydantic-storage"
},
"split_keywords": [
"bulk-create",
" data-management",
" data-storage",
" data-validation",
" datastore",
" file-storage",
" json-storage",
" lightweight-storage",
" metadata",
" model-storage",
" object-storage",
" partial-update",
" persistent-storage",
" pydantic",
" pydantic-model",
" python-storage",
" python3",
" schema-validation",
" structured-storage",
" type-safe",
" unique-constraint"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "530cea493cfab443af7c76467cf995589dfa77856ce492cb5f1ab9f4694cebd4",
"md5": "2d57dd58d75bb0a466fa2b230a274333",
"sha256": "212841500c9d4182d9f87c5ecb8d2a8e3cf0261c5ef8b620035fd8a9133f05a2"
},
"downloads": -1,
"filename": "pydantic_storage-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2d57dd58d75bb0a466fa2b230a274333",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.13",
"size": 15433,
"upload_time": "2025-08-11T14:26:05",
"upload_time_iso_8601": "2025-08-11T14:26:05.164065Z",
"url": "https://files.pythonhosted.org/packages/53/0c/ea493cfab443af7c76467cf995589dfa77856ce492cb5f1ab9f4694cebd4/pydantic_storage-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c2f36507e7240f282103756e9a70b12e940c21f4f00266879c339e763582f230",
"md5": "98c3a615a553d8a058f55bc3fa6fc9e4",
"sha256": "52b2a762fc931bdb1b9359a282dbe080474419d62ebeaf741bd5c282b2d9b434"
},
"downloads": -1,
"filename": "pydantic_storage-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "98c3a615a553d8a058f55bc3fa6fc9e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.13",
"size": 23784,
"upload_time": "2025-08-11T14:26:08",
"upload_time_iso_8601": "2025-08-11T14:26:08.802141Z",
"url": "https://files.pythonhosted.org/packages/c2/f3/6507e7240f282103756e9a70b12e940c21f4f00266879c339e763582f230/pydantic_storage-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-11 14:26:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "shaileshpandit141",
"github_project": "pydantic-storage",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "pydantic-storage"
}