kandi background
Explore Kits

pickledb | open source keyvalue store using Python's json module | JSON Processing library

 by   patx Python Version: Current License: BSD-3-Clause

 by   patx Python Version: Current License: BSD-3-Clause

Download this library from

kandi X-RAY | pickledb Summary

pickledb is a Python library typically used in Utilities, JSON Processing applications. pickledb has no vulnerabilities, it has build file available, it has a Permissive License and it has low support. However pickledb has 2 bugs. You can install using 'pip install pickledb' or download it from GitHub, PyPI.
pickleDB is lightweight, fast, and simple database based on the json module. And it's BSD licensed!.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • pickledb has a low active ecosystem.
  • It has 589 star(s) with 102 fork(s). There are 13 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 13 open issues and 39 have been closed. On average issues are closed in 421 days. There are 13 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of pickledb is current.
pickledb Support
Best in #JSON Processing
Average in #JSON Processing
pickledb Support
Best in #JSON Processing
Average in #JSON Processing

quality kandi Quality

  • pickledb has 2 bugs (0 blocker, 0 critical, 2 major, 0 minor) and 1 code smells.
pickledb Quality
Best in #JSON Processing
Average in #JSON Processing
pickledb Quality
Best in #JSON Processing
Average in #JSON Processing

securitySecurity

  • pickledb has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • pickledb code analysis shows 0 unresolved vulnerabilities.
  • There are 1 security hotspots that need review.
pickledb Security
Best in #JSON Processing
Average in #JSON Processing
pickledb Security
Best in #JSON Processing
Average in #JSON Processing

license License

  • pickledb is licensed under the BSD-3-Clause License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
pickledb License
Best in #JSON Processing
Average in #JSON Processing
pickledb License
Best in #JSON Processing
Average in #JSON Processing

buildReuse

  • pickledb releases are not available. You will need to build from source code and install.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • pickledb saves you 163 person hours of effort in developing the same functionality from scratch.
  • It has 404 lines of code, 57 functions and 5 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
pickledb Reuse
Best in #JSON Processing
Average in #JSON Processing
pickledb Reuse
Best in #JSON Processing
Average in #JSON Processing
Top functions reviewed by kandi - BETA

kandi has reviewed pickledb and discovered the below as its top functions. This is intended to give you an instant insight into pickledb implemented functionality, and help decide if they suit your requirements.

  • Load database .
  • Dump the database
  • Initialize the plugin .
  • Create a database entry .
  • Set the key s value .
  • Creates a pickle database .

pickledb Key Features

pickleDB is an open source key-value store using Python's json module.

pickleDB is Fun

copy iconCopydownload iconDownload
>>> import pickledb

>>> db = pickledb.load('test.db', False)

>>> db.set('key', 'value')

>>> db.get('key')
'value'

>>> db.dump()
True

Easy to Install

copy iconCopydownload iconDownload
$ pip install pickledb

Removing item from a stored list in pickleDB throws: list.remove(x): x not in list

copy iconCopydownload iconDownload
class Message:

    def __init__(self, id, content):
        self.id = id
        self.content = content

    def __eq__(self, other):
        if isinstance(other, Message):
            return self.id == other.id and self.content == other.content
        return False
class MyMessage(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        # As an example, we only check `extra`, and ignore everything else
        if isinstance(other, MyMessage):
            return self.extra == other.extra
        return False
class MyMessage2(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        if isinstance(other, MyMessage2):
            ret = super().__eq__(other)
            if not ret:
                return False
            return self.extra == other.extra
        return False
-----------------------
class Message:

    def __init__(self, id, content):
        self.id = id
        self.content = content

    def __eq__(self, other):
        if isinstance(other, Message):
            return self.id == other.id and self.content == other.content
        return False
class MyMessage(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        # As an example, we only check `extra`, and ignore everything else
        if isinstance(other, MyMessage):
            return self.extra == other.extra
        return False
class MyMessage2(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        if isinstance(other, MyMessage2):
            ret = super().__eq__(other)
            if not ret:
                return False
            return self.extra == other.extra
        return False
-----------------------
class Message:

    def __init__(self, id, content):
        self.id = id
        self.content = content

    def __eq__(self, other):
        if isinstance(other, Message):
            return self.id == other.id and self.content == other.content
        return False
class MyMessage(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        # As an example, we only check `extra`, and ignore everything else
        if isinstance(other, MyMessage):
            return self.extra == other.extra
        return False
class MyMessage2(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        if isinstance(other, MyMessage2):
            ret = super().__eq__(other)
            if not ret:
                return False
            return self.extra == other.extra
        return False

Community Discussions

Trending Discussions on pickledb
  • Removing item from a stored list in pickleDB throws: list.remove(x): x not in list
  • Main loop does not wait for python multiprocessing pool to finish & freeze
Trending Discussions on pickledb

QUESTION

Removing item from a stored list in pickleDB throws: list.remove(x): x not in list

Asked 2021-Jan-17 at 10:27

I have a Message class:

messages = []

class Message:
   id = 1
   content = "m1"

   def __init__(self, id, content):
      self.id = id
      self.content = content

Following code works as expected:

m1 = Message(1, "m1")
m2 = Message(2, "m2")

messages.append(m1)
messages.append(m2)
messages.remove(m2) #Works as expected

But when I load messages from a pickleDB and try to remove the item, it throws this error:

list.remove(x): x not in list

def save_database():
   with open("database.db", 'wb') as f:
      pickle.dump(messages, f)

def load_database():
   global messages
   with open("database.db", 'rb') as f:
      messages = pickle.load(f)

def add_message(msg):
  load_database()
  messages.append(msg)
  save_database()


m1 = Message(1, "m1")
m2 = Message(2, "m2")

add_message(m1)
add_message(m2)

load_database()
messages.remove(m2) #ERROR: list.remove(x): x not in list

ANSWER

Answered 2021-Jan-17 at 10:27

That's because the objects that are read from the pickle dump are not the same as those in your program (pickle.load() creates new objects).

Hence, when list.remove() looks for the object in the list, it won't find it and instead raises an exception.

See also, this post which discusses how equality is defined on objects in Python by default.

You need to override the way equality is checked, by implementing a custom __eq__ method in your Message class:

class Message:

    def __init__(self, id, content):
        self.id = id
        self.content = content

    def __eq__(self, other):
        if isinstance(other, Message):
            return self.id == other.id and self.content == other.content
        return False

The general approach is to first check whether the object being compared is of the right type. If it is, then compare the relevant fields.

How do I handle this if I don't own the class?

You could subclass it, and then override __eq__. Though in such a case, you may need to consider how super().__eq__ behaves as well.

Subclass that overrides __eq__ completely:

In this version, we discard the superclass's __eq__ completely and implement our own logic for checking equality.

class MyMessage(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        # As an example, we only check `extra`, and ignore everything else
        if isinstance(other, MyMessage):
            return self.extra == other.extra
        return False

Subclass that overrides and takes super().__eq__ into account:

In this version, we call the superclass's __eq__ and add our own logic for checking equality in addition to it.

class MyMessage2(Message):

    def __init__(self, id, content, extra):
        super().__init__(id, content)
        self.extra = extra

    def __eq__(self, other):
        if isinstance(other, MyMessage2):
            ret = super().__eq__(other)
            if not ret:
                return False
            return self.extra == other.extra
        return False

Source https://stackoverflow.com/questions/65758350

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install pickledb

You can install using 'pip install pickledb' or download it from GitHub, PyPI.
You can use pickledb like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

websitedocumentationpypigithub repo

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with pickledb
Consider Popular JSON Processing Libraries
Try Top Libraries by patx
Compare JSON Processing Libraries with Highest Support
Compare JSON Processing Libraries with Permissive License
Compare JSON Processing Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.