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
DOP-Tuning(Domain-Oriented Prefix-tuning model)

DOP-Tuning DOP-Tuning(Domain-Oriented Prefix-tuning model)代码基于Prefix-Tuning改进. Files ├── seq2seq # Code for encoder-decoder arch

Andrew Zeng 5 Nov 02, 2022
:art: Diagram as Code for prototyping cloud system architectures

Diagrams Diagram as Code. Diagrams lets you draw the cloud system architecture in Python code. It was born for prototyping a new system architecture d

MinJae Kwon 27.5k Jan 04, 2023
Arabic to Roman Converter in Python

Arabic-to-Roman-Converter Made together with https://github.com/goltaraya . Arabic to Roman Converter in Python. -Instructions: 1 - Make sure you have

Pedro Lucas Tomazeti Fernandes 6 Oct 28, 2021
Python tools for working with Orbit Ephemeris Messages (OEMs).

Python Orbit Ephemeris Message tools Python tools for working with Orbit Ephemeris Messages (OEMs). Development Status Installation The oem package is

Brad Sease 4 Apr 06, 2022
Module for remote in-memory Python package/module loading through HTTP/S

httpimport Python's missing feature! The feature has been suggested in Python Mailing List Remote, in-memory Python package/module importing through H

John Torakis 220 Dec 17, 2022
Dotfiles & list of programs

dotfiles & list of programs So I wanted to just backup my most used files. I have a bad habit, sometimes I get tired of a distro and do a wipe and sta

2 Sep 04, 2022
Empresas do Brasil (CNPJs)

Biblioteca em Python que coleta informações cadastrais de empresas do Brasil (CNPJ) obtidas de fontes oficiais (Receita Federal) e exporta para um formato legível por humanos (CSV ou JSON).

BR-API: Democratizando dados do Brasil. 8 Aug 17, 2022
Statically typed BNF with semantic actions; A frontend of frontend frameworks; Use your grammar everywhere.

Statically typed BNF with semantic actions; A frontend of frontend frameworks; Use your grammar everywhere.

Taine Zhao 56 Dec 14, 2022
Cairo-math-64x61 - Fixed point 64.61 math library for Cairo / Starknet

Cairo Math 64x61 A fixed point 64.61 math library for Cairo & Starknet Signed 64

Influence 63 Dec 05, 2022
Recreating my first CRUD in python, but now more professional

Recreating my first CRUD in python, but now more professional

Ricardo Deo Sipione Augusto 2 Nov 27, 2021
NFT-Image-Generator - Utility to generate a large collection of unique images

NFT-Image-Generator Utility for creating a generative art collection from suppli

Sem Moolenschot 60 Dec 15, 2022
Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you class scheduling.

Class Schedule Shortcut Tracking development of the Class Schedule Siri Shortcut, an iOS program that checks the type of school day and tells you clas

3 Jun 28, 2022
Python library for the Unmand APIs.

Unmand Python SDK This is a simple package to aid in consuming the Unmand APIs. For more help, see our docs. Getting Started Create virtual environmen

Unmand 4 Jul 22, 2022
A faster Python generator that get function results from multi-process workers

multiyield This package implements a Python generator that get function results from multi-process workers. The faster_fifo Queue (instead of the stan

Xin Du 1 Nov 18, 2021
This repo is related to Google Coding Challenge, given to Bright Network Internship Experience 2021.

BrightNetworkUK-GCC-2021 This repo is related to Google Coding Challenge, given to Bright Network Internship Experience 2021. Language used here is py

Dareer Ahmad Mufti 28 May 23, 2022
This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

This is a Python 3.10 port of mock, a library for manipulating human-readable message strings.

Alexander Bartolomey 1 Dec 31, 2021
A python library for writing parser-based interactive fiction.

About IntFicPy A python library for writing parser-based interactive fiction. Currently in early development. IntFicPy Docs Parser-based interactive f

Rita Lester 31 Nov 23, 2022
Short, introductory guide for the Python programming language

100 Page Python Intro This book is a short, introductory guide for the Python programming language.

Sundeep Agarwal 185 Dec 26, 2022
A programming language that for tech savvy graphic designers

Microsoft Hackathon - PhoTex Idea A programming language that allows tech savvy graphic designers develop scalable vector graphics using plain text co

Joe Furfaro 5 Nov 14, 2021
Python requirements.txt Guesser

Python-Requirements-Guesser ⚠️ This is alpha quality software. Work in progress Attempt to guess requirements.txt modules versions based on Git histor

Jerome 9 May 24, 2022