Skip to main content

Simple in-memory CRUD store for rapid prototyping

Project description

crudtape

"Like duct 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

Or add it as a dependency to you favorite build configuration file.

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).

An example model class using Pydantic:

import BaseModel from pydantic

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

The same but using @dataclass decorator:

@dataclass
class Pet:
    name: str
    age: int
    id: int = None

    def model_dump(self, *args, **kwargs):
        return {"name": self.name, "age": self.age}

And once again, this time made from scratch:

class Pet:
    def __init__(self, **data):
        self.name = data.get("name")
        self.age = data.get("age")
        self.id = data.get("id", None)

    def model_dump(self, *args, **kwargs):
        return {"name": self.name, "age": self.age}    

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.4.tar.gz (8.7 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.4-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for crudtape-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9a19c16afff6306b01cd8e7677f37932ef4b0f5e58d433f2db10ca23680f564e
MD5 520ae517d82b8948e31911a4b2515ae1
BLAKE2b-256 346bf81b8fc21953424423aa96bc17bba6ccf4b782444baf568f644977b4c67c

See more details on using hashes here.

Provenance

The following attestation bundles were made for crudtape-0.1.4.tar.gz:

Publisher: publish.yaml on alesbukovsky/crudtape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

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

File hashes

Hashes for crudtape-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1a7503299015f49d0cffe5d6a9957ec582b8d81f3a16bf13e3984d017bb3ccb2
MD5 a24fef536919a76aff630759bb5c9f29
BLAKE2b-256 b36ee145388b3d23315df2bbbba7bc9cf508dbd4926cee578222e92b301653a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for crudtape-0.1.4-py3-none-any.whl:

Publisher: publish.yaml on alesbukovsky/crudtape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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