Skip to main content
Loading page…
Python Mastery
Chapter 23
Lesson 2 of 3
pickle & Its Dangers
Contents
Notes
Tutor
Concept
What pickle Is and Why It Exists
Loading activity…
Previous
1 / 9
Continue
Contents
Notes
Discussion
Tutor
22 min
9 activities
0 of 9 done
In this lesson
1
What pickle Is and Why It Exists
2
Basic pickle: dump and load
3
CRITICAL SECURITY WARNING: Never Unpickle Untrusted Data
4
shelve: A Persistent Dict Backed by pickle
5
Why is unpickling dangerous?
6
Safer Alternatives: JSON, msgpack, and safetensors
7
Exercise: Safe Pickle with __getstate__
8
pickle Knowledge Check
9
Correct Order: Pickling an Object to Disk
Objectives
Use pickle.dump and pickle.load to serialize arbitrary Python objects
Explain what pickle can and cannot serialize
Articulate the critical security risk of unpickling untrusted data and why it enables arbitrary code execution
Use shelve as a persistent dict backed by pickle
Choose among JSON, pickle, and msgpack based on the use case
Chapter 23 · Serialization, Config & Data Interchange
JSON, Deeply
pickle & Its Dangers
Config: TOML, YAML, INI & .env
Previous: JSON, Deeply
Next: Config: TOML, YAML, INI & .env