Reading preferences
Concept

Binary Data, Pickle, and Distribution

Distinguish bytes from text, understand pickle trust, and follow a package build.

python, bytes, binary, pickle, packaging, distribution

Bytes are not characters

Text is a sequence of Unicode characters; a binary file contains bytes. An encoding maps between text and bytes. Open with rb or wb for binary I/O; wb can overwrite an existing file.

Python illustration

text = "café"
data = text.encode("utf-8")
print(list(data))
print(data.decode("utf-8"))

Prepared output — not live execution:

[99, 97, 102, 195, 169]
café

The final character uses two bytes in UTF-8. Decoding must use a compatible encoding; invalid bytes can raise UnicodeDecodeError.

See the reasoning

Follow text into bytes and back

See why the final character occupies two UTF-8 bytes. This is a prepared demonstration, not live code execution.

Start with text

Encoding and decoding
  1. TextcaféCurrent focus
  2. UTF-8 bytesnot yet encoded
  3. Decoded textpending

The string contains four Unicode characters.

Trust and distribution

pickle.dumps(value) produces bytes and pickle.loads(data) reconstructs objects. Never unpickle untrusted or tampered data: loading can execute arbitrary code. Pickle is not encryption or a safe interchange format. For untrusted data, choose a suitable data-only format and validate it.

import pickle

payload = pickle.dumps({"count": 3})
restored = pickle.loads(payload)  # Only bytes created and trusted by this program
print(restored["count"])

The prepared output is 3. This is a trusted in-memory round trip, not a safe pattern for data from another person, a network, or a writable file.

For distribution, configure a build backend and project metadata in pyproject.toml; a build frontend such as python -m build can create a source distribution and a wheel. Test installation in a clean environment and publish only to an intended repository with appropriate credentials. A wheel may be platform-specific; a source distribution needs a build step. Build and installation can execute project or dependency code, so review the source. These are local workflow examples, not Intuvo runtime features.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What does encoding text produce?
2. What does rb mean when opening a file?
3. Why must untrusted pickle data not be loaded?
4. What is a wheel?

References and further reading