Skip to content

Custom unpickler and pickler for the shelve module  #99631

Closed

Description

@furkanonder

The goal of this enhancement is to make the shelve module more usable by accepting custom types of pickler and unpickler.

Example

The lambda functions can not be pickled by Python's pickle module. So, for that reason the shelve library also can’t do that.

The shelve module was unable to handle this situation.

import shelve
with shelve.open("test_file") as sh:
    squared = lambda x: x ** 2
    sh['test_key'] = squared

With the changes made here, the shelve module can easily overcome this issue.

import dill
import shelve

with shelve.open("test_file_2", pickler=dill.Pickler, unpickler=dill.Unpickler) as sh:
    squared = lambda x: x ** 2
    sh['test_key'] = squared

Previous discussion

Linked PRs

Activity

  1. added
    type-feature
    on Nov 20, 2022
  2. added
    stdlib
    on Nov 28, 2023
  3. self-assigned this
    on Apr 21, 2024
  4. added
    3.13
    on Apr 21, 2024
  5. added
    3.14
    and removed
    3.13
    on Mar 22, 2025
  6. removed
    3.14
    on Mar 22, 2025
  7. added a commit that references this issue on Jul 12, 2025
  8. added a commit that references this issue on Jul 12, 2025
  9. added a commit that references this issue on Jul 13, 2025
  10. added a commit that references this issue on Aug 4, 2025
  11. added a commit that references this issue on Aug 19, 2025
  12. added a commit that references this issue on Mar 13, 2026
  13. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

stdlibtype-feature

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions