Code Monkey home page Code Monkey logo

datacrash's Introduction

datacrash

the point of this module is to make something as understandable and chill as dataclasses extremely cringe and awful. it provides a decorator that wraps around standard dataclasses, allowing for automatic data storage without altering the original data or its behavior.

features

  • transparent integration: use datacrash with your existing dataclasses without any modifications to the actual data. (not sure if this is true tbh)
  • extensible: extend dataclasses to be logged/stored/etc with anything

Basic Usage

from dataclasses import dataclass
from datacrash import datacrash
from datacrash.plugins.tinydb import TinydbPlugin

tinydb_plugin = TinydbPlugin(db_path="output/db.json")

@datacrash(plugins=tinydb_plugin)
@dataclass
class MyDataClass:
    name: str
    price: float

with above, now every instance of MyDataClass will automatically be persisted in a TinyDB database located at output/db.json.

extending datacrash

datacrash is designed with extensibility in mind. You can easily create plugins to support other storage backends:

create a new plugin: the plugin class should inherit from the base plugin class provided by datacrash as the hooks will be more defined later. implement required rethods: depending on the storage backend, you might need to override methods like hook, on_init, and on_change.

using the ๐Ÿ”Œ: Once your plugin is ready, simply pass it to the datacrash decorator to start using it. for more details on creating plugins, refer to the provided TinydbPlugin as an example.

The hooks might change as its unclear to me best way to modify the classes that @dataclass wraps (ideally would use __post_init__ but dont think that is feasible)

datacrash's People

Contributors

grahamannett avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.