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

Uploaded Python 3

File details

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

File metadata

  • Download URL: crudtape-0.1.3.tar.gz
  • Upload date:
  • Size: 8.6 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.3.tar.gz
Algorithm Hash digest
SHA256 f9f7c0c43a4615aba68b911f5ac2a999e134303323050d7cf24bc4f9f95b18e6
MD5 bfdaaf170fc0c5e996bad037674ae220
BLAKE2b-256 303d7464a55126deea64fc9339b70b3db1b3e0c7baeeefca960ffb402c3e8811

See more details on using hashes here.

Provenance

The following attestation bundles were made for crudtape-0.1.3.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.3-py3-none-any.whl.

File metadata

  • Download URL: crudtape-0.1.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 24d463ea68f292b457fba8fb08f59b769725ca11546b0408478ec051385d7ee5
MD5 1cd3c643ce2c9c7da5a22bbae03f4cd5
BLAKE2b-256 8a9829211198410b5170e1791bbd57c67fa379a2c898a42baae788ca39313cc4

See more details on using hashes here.

Provenance

The following attestation bundles were made for crudtape-0.1.3-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