serpent
Serialization based on ast.literal_eval
What it is and what it does
Serpent is a serialization library that converts Python objects into human-readable, executable Python source code (literals) that can be safely deserialized using ast.literal_eval(). Unlike pickle, which has known security risks, serpent produces text that is safe to transport over networks or store in files because it only recreates literal values—no arbitrary code execution occurs during deserialization.
The library extends basic repr() and literal_eval() by adding automatic serialization for types like uuid, datetime, array, and decimal, encoding bytes as base-64, and allowing pretty-printed output with comments. It's designed for scenarios where human readability, safety, and cross-platform compatibility matter more than performance. Serpent also has implementations in Java and .NET, enabling data exchange between Python, Java, and C# ecosystems.
Use it for:
- Serialize configuration or data files that humans need to read and edit while maintaining type safety.
- Exchange structured data between Python, Java, and .NET services without security risks of pickle.
- Store application state or cache data in a format that survives code changes and is auditable.
- Debug and log complex object structures in a readable, executable format.
- Build a lightweight data protocol for inter-process communication where JSON's type limitations are insufficient.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Serpent serializes Python objects to human-readable, safe literals that can be deserialized using ast.literal_eval(), with support for uuid, datetime, array, and decimal types.
Yes, if you need safe, human-readable serialization and can accept the constraint that circular object references are not supported. The zero-dependency installation, active maintenance, permissive license, and lack of known vulnerabilities make it a solid choice for configuration, logging, and cross-language data exchange. Not suitable if you need binary efficiency or must serialize arbitrary object graphs.
Install
serpent on PyPI
pip
pip install serpentuv
uv add serpentpoetry
poetry add serpentInstalling serpent
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a recent release; last commit 2026-05-30 and status marked active.
License in practice
MIT license (permissive) means you can use, modify, and distribute serpent freely in commercial or private projects as long as you retain the copyright notice and license text.
Quickstart
import serpent
data = {'names': ['Alice', 'Bob'], 'count': 42}
ser_bytes = serpent.dumps(data)
obj = serpent.loads(ser_bytes)
Requires Python 3.2 or later; cannot serialize object graphs (circular references will raise ValueError).
Verify before relying
- Performance characteristics compared to alternative serialization formats in typical workloads.
- Whether cross-language interoperability (Java and .NET) is actively maintained and tested.
- Handling of very large objects or deeply nested structures in practice.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.2) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 76 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 663,667/month — #5,435 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: serpent-1.43-py3-none-any.whl
Keywords: serialization
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
phpserializeConverts Python objects to and from PHP…
permissive · top 15,000 on PyPI
renewGenerates reproducible string representations…
permissive · top 15,000 on PyPI
yamlableConverts Python objects to YAML and back using…
permissive · top 15,000 on PyPI
dicttoxmlConverts Python dictionaries and other native…
copyleft · top 5,000 on PyPI
xml-pythonConverts XML documents into Python objects,…
copyleft · top 5,000 on PyPI
orjsonorjson is a fast JSON serialization and…
copyleft · top 1,000 on PyPI
lkmlParses LookML strings into Python objects or…
permissive · top 5,000 on PyPI
py-serializableSerializes and deserializes Python classes to…
permissive · top 1,000 on PyPI
marshmallowMarshmallow converts complex Python objects to…
permissive · top 1,000 on PyPI
numpyencoderProvides a custom JSON encoder class that…
permissive · top 15,000 on PyPI