easydatastore
- Create type-safe, in-memory datastores
Requirements
Install
pip install easydatastore
Usage
If you want to prototype a web application quickly and just need a way to validate your mock data, you can use easydatastore
to create an in-memory datastore for your models, directly out of the box.
Features:
- In-memory tables for your models with
easydatastore.Table
, with a familiar pydantic-flavored syntax and ORM-like API. - Enforce uniqueness constraints with
Column(unique=True)
- Use indexing for faster lookups with
Column(index=True)
- IDE-friendly type hints ensure your coding experience is type-safe.
Example
import easydatastore.exceptions
from easydatastore import Column, Table
class Person(Table):
name: str = Column(primary_key=True)
email: str | None = Column(unique=True, default=None)
family_name: str
age: int
Person(name="Snap", family_name="Krispies", email="snap@example.com", age=92)
Person(name="Crackle", family_name="Krispies", age=92)
Person(name="Pop", family_name="Krispies", age=92)
Person(name="Tony", family_name="Tiger", email="tony@example.com", age=72)
Person(name="Cap'n", family_name="Crunch", age=53)
tony = Person.get("Tony")
print(tony)
print([person.name for person in Person.filter(family_name="Krispies")])
print([person.name for person in Person.filter(lambda person: person.age < 90)])
Person.delete(Person.get("Crackle"))
print([person.name for person in Person.all()])
try:
tony.email = Person.get("Snap").email
except ValueError as e:
print(e.args[0])
try:
Person(name="Snap", family_name="Rice", age=1)
except easydatastore.exceptions.DuplicateUniqueFieldValueError as e:
print(e.args[0])