Skip to main content

Simple in-memory CRUD store for rapid prototyping

Project description

crudtape

"Like duck tape but for CRUD..."

A lightweight in-memory CRUD store for Pydantic-style objects, designed for rapid prototyping. Powered by TinyDB.

Installation

pip install crudtape

Usage

The store is designed to work with any model class that implements the basic Storable protocol, which defines a minimal subset of the Pydantic model interface. Importantly, the store does not depend on Pydantic itself - you can use any compatible class. This means:

  • Pydantic models (as-is)
  • @dataclass decorated classes
  • Custom classes built from scratch

The only caveat is that the store manages the object IDs internally. In essence, a compatible model class needs to provide:

  • __init__ method that accepts keyword arguments, including an optional id of type int (used when constructing returned objects).
  • model_dump() method returning a dictionary representation, excluding the id attribute (it will be ignored by the store otherwise).
import BaseModel from pydantic

class Pet(BaseModel):
    name: str
    age: str
    id: int = None

Additional examples are shown in the test suit.

The class is used to create a corresponding store instance:

import Store from crudtape

store = Store(Pet)

The store offers basic self-explanatory CRUD operations, all typed to the specified model class and with decent error checking. See the API reference for full details.

# insert an object
store.insert(Pet(name="Bob", age=3))

# list all objects 
store.all()

# get an object with given ID
store.get(1)

# update an object with given ID
store.update(1, Pet(name="Rob", age=5))

# delete an object with given ID
store.delete(1)

The store raises StoreError for general failures, with two exceptions: NotFoundError is raised when an object with the given ID doesn’t exist, and TypeError when an input object has the wrong type.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crudtape-0.1.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crudtape-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file crudtape-0.1.1.tar.gz.

File metadata

  • Download URL: crudtape-0.1.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for crudtape-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a16d637af775b09ca08c252a993579779947d4cf8d9fc645663af2f05db0b19c
MD5 d382c0c219d8b9855147746d7c779a3b
BLAKE2b-256 45b44b589eb04632fcdd21eddbb4289921282380d420e73d46647f73e0e1489d

See more details on using hashes here.

File details

Details for the file crudtape-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: crudtape-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for crudtape-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 994ad6a53a0ad379a939c5487599873e3aaf9582d2422ee031b1c3a399cfb38f
MD5 b641fdc4494293e9280fed37f7c90111
BLAKE2b-256 5316a6f5e5c27e8cbeed92d07eb0ad639334d0c6a58c1bb66b6d619b663254a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page