Easiest way to Store JSON typed data using a Pydantic models and database-like structure.
Project description
StoreJSON
StoreJSON is the easiest way to manage data with JSON. It allows you to store, manipulate, and query objects in table form, similar to a database, but with the simplicity and readability of the JSON format. This project is designed to be as accessible as possible while remaining powerful enough for various use cases.
Why Use StoreJSON?
-
Simplicity: With StoreJSON, working with structured data becomes as simple as manipulating Python objects. No complex configuration is needed. Everything is managed through classes.
-
Performance: The use of typed models via Pydantic. enables efficient data validation while ensuring data integrity.
-
Readability: Storing data in JSON format ensures that your data remains easily readable and modifiable, even without specific tools.
Example Usage
from storejson import Storage, TableObject
# Create a new storage instance using a JSON file
storage = Storage("./mystorage.json")
# Define a data model for the "users" table
class UserModel(TableObject):
id: int
username: str
# Add the "users" table to the storage
User = storage.add_table("users", id_key="id", model_class=UserModel)
# Create a new user and add them to the table
user = User(id=1, username="JohnDoe")
user.storage.push()
# Retrieve a user by their ID
retrieved_user = User.get(1)
print(retrieved_user)
# Update a user
retrieved_user.username = "JaneDoe"
retrieved_user.push()
# Delete a user
retrieved_user.remove()
Using Decorators
If you prefer to use decorators for more concise syntax:
# Create a "users" table using a decorator
@storage.table("users", id_key="id")
class User(TableObject):
id: int
username: str
# Create and add a user
user = User(id=2, username="Alice")
user.storage.push()
# Retrieve and display the user
print(User.storage.get(2))
Complete Documentation
To view the full documentation of the project, it is recommended to use pdoc
.
pip install pdoc
py -m pdoc storejson
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file storejson-0.1.1.tar.gz
.
File metadata
- Download URL: storejson-0.1.1.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebd6ee5db865e6a35bb6e5787213b4f9dad4a90f9b3cff5a133bde7de88abe9e |
|
MD5 | 79a25cbe9b2a3ef677aeb58d8fd8f875 |
|
BLAKE2b-256 | 10d36cb6721732696a28d571bd6e132a4124a7d2273f7ac731f8d881886da3f6 |
File details
Details for the file storejson-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: storejson-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.5 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6949e8e18821de10cc57cb93ec0c8418c79b2be4f17834d22bd31cfc4959bec |
|
MD5 | 14bbecedb17683fae8f93c2b33541cd0 |
|
BLAKE2b-256 | 64e746541f11c1d7d504a5f960d19d4f5d7607009ee842a9ac4c5e8aa7c491b1 |