Pyrmanent - Make all your classes permanent in a flash ๐Ÿ’พ

Overview

Pyrmanent

A base class to make your Python classes permanent in a flash.

PyPI Python License Support

Features

  • Easy to use.
  • Great compatibility.
  • No database needed.
  • Ask for new features through the issues section.
  • Join our Telegram group for support or development.

Installation

You can install or upgrade the module with:

pip install pyrmanent --upgrade

Usage guide

Basic usage:

Making your custom clases permanent is as easy as adding Pyrmanent as the base class.

from pyrmanent import Pyrmanent

class MyClass(Pyrmanent):
    pass

Call the save method to save the current instance data:

my_class_instance = MyClass()
my_class_instance.my_data = "Hello world!"
my_class_instance.save()

To load a previously saved instance data, just create the instance and data will be automatically loaded:

my_class_instance = MyClass()
print(my_class_instance.my_data)

"Hello world!"

Configuration

Instance name

The name parameter allows saving different instances of the same class. Each one will keep its own data.

first_instance = MyClass(name="first")
first_instance.my_data = "This is the first instance"
first_instance.save()

second_instance = MyClass(name="second")
second_instance.my_data = "And this the second one"
second_instance.save()

Saving path

The path for the saved files can be customized with the folder parameter. If not provided, the files will be saved on the execution folder.

my_class_instance = MyClass(folder="data")

Auto saving

The autosave parameter allows using the autosave method to save data only when True. This is specially useful for your custom class methods.

class MyClass(Pyrmanent):
    def set_title(self, title):
        self.title = title
        self.autosave()

# The instance data will be saved when the method is called
my_class_instance = MyClass(autosave=True)
my_class_instance.set_title("Test")

# You should manually save the instance data
my_class_instance = MyClass(autosave=False)
my_class_instance.set_title("Test")
my_class_instance.save()

Instance initialization

Override the __init__ method

The __init__ method can be overrided to provide default configurations, like for example the saving path in below example.

class MyClass(Pyrmanent):
    def __init__(self, name, autosave=True):
        super().__init__(name=name, folder="data", autosave=autosave)

The init method

On the other hand, you can define the init method (without the underscores) to initialize attribute values. This method is called before saving the instance data for the first time.

class MyClass(Pyrmanent):
    def init(self):
        self.first_value = 1
        self.second_value = 2

Use dill instead of pickle

Dill extends the compatibility with several data types that pickle module can't serialize. It provides the same interface, so it's totally compatible without any code change needed. To start using dill, just install it using pip and it will be used by default:

pip install dill --upgrade

To stop using dill, just uninstall it. You can find more information about dill in the official repo.

License

Copyright ยฉ 2021 Sergio Abad. See license for details.

You might also like...
Python Classes Without Boilerplate

attrs is the Python package that will bring back the joy of writing classes by relieving you from the drudgery of implementing object protocols (aka d

Simple tooling for marking deprecated functions or classes and re-routing to the new successors' instance.

pyDeprecate Simple tooling for marking deprecated functions or classes and re-routing to the new successors' instance

Simple but maybe too simple config management through python data classes. We use it for machine learning.

๐Ÿ‘ฉโ€โœˆ๏ธ Coqpit Simple, light-weight and no dependency config handling through python data classes with to/from JSON serialization/deserialization. Curre

An extended version of the hotkeys demo code using action classes

An extended version of the hotkeys application using action classes. In adafruit's Hotkeys code, a macro is using a series of integers, assumed to be

Python Interactive Graphical System made during Computer Graphics classes (INE5420-2021.1)
Python Interactive Graphical System made during Computer Graphics classes (INE5420-2021.1)

PY-IGS - The PYthon Interactive Graphical System The PY-IGS Installation To install this software you will need these dependencies (with their thevelo

On this repo, you'll find every codes I made during my NSI classes (informatical courses)

๐Ÿ‘จโ€๐Ÿ’ป ๐Ÿ‘ฉโ€๐Ÿ’ป school-codes On this repo, you'll find every codes I made during my NSI classes (informatical courses) French for now since this repo is d

This is a backport of the BaseExceptionGroup and ExceptionGroup classes from Python 3.11.

This is a backport of the BaseExceptionGroup and ExceptionGroup classes from Python 3.11. It contains the following: The exceptiongroup.BaseExceptionG

WATTS provides a set of Python classes that can manage simulation workflows for multiple codes where information is exchanged at a coarse level

WATTS (Workflow and Template Toolkit for Simulation) provides a set of Python classes that can manage simulation workflows for multiple codes where information is exchanged at a coarse level.

 ๐Ÿ—ฝ Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.
๐Ÿ—ฝ Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.

pipupgrade The missing command for pip Table of Contents Features Quick Start Usage Basic Usage Docker Environment Variables FAQ License Features Upda

Releases(v1.1.0)
Owner
Sergio Abad
Full stack developer. I love learning something new every day. Typescript and Python.
Sergio Abad
Izy - Python functions and classes that make python even easier than it is

izy Python functions and classes that make it even easier! You will wonder why t

null 5 Jul 4, 2022
Mnemosyne: efficient learning with powerful digital flash-cards.

Mnemosyne: Optimized Flashcards and Research Project Mnemosyne is: a free, open-source, spaced-repetition flashcard program that helps you learn as ef

null 359 Dec 24, 2022
Just some mtk tool for exploitation, reading/writing flash and doing crazy stuff

Just some mtk tool for exploitation, reading/writing flash and doing crazy stuff. For linux, a patched kernel is needed (see Setup folder) (except for read/write flash). For windows, you need to install zadig driver and replace pid 0003 / pid 2000 driver.

Bjoern Kerler 1.1k Dec 31, 2022
The fastest way to copy to (not from) high speed flash storage.

FastestCopy The fastest way to copy to (not from) high speed flash storage. This is about 3-6x faster than file copy on explorer.exe to usb flash driv

Derek Frombach 0 Nov 3, 2021
This an Anki add on that automatically converts Notion notes into Anki flash cards. Currently in development!

NotionFlash This is an Anki add on in development that will allow automatically convert your Notion study notes into Anki flash cards. The Anki deck c

Neeraj Patel 10 Oct 7, 2022
A tool to flash .ofp files in bootloader mode without needing MSM Tool, an alternative to official realme tool

Oppo/Realme Flash .OFP File on Bootloader A tool to flash .ofp files in bootloader mode without needing MSM Tool, an alternative to official realme to

Italo Almeida 70 Jan 2, 2023
Donatus Prince 6 Feb 25, 2022
Ahmed Hossam 12 Oct 17, 2022
Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends.

Quiz Application Its a simple and fun to use application. You can make your own quizes and send the lik of the quiz to your friends. When they would a

Atharva Parkhe 1 Feb 23, 2022
Macros in Python: quasiquotes, case classes, LINQ and more!

MacroPy3 1.1.0b2 MacroPy is an implementation of Syntactic Macros in the Python Programming Language. MacroPy provides a mechanism for user-defined fu

Li Haoyi 3.2k Jan 6, 2023