Python Rison Encoder/Decoder
"prison" is a Python library providing an encoder and decoder for the Rison data serialization format. Rison (Recursive object notation) is a compact, URL-safe data format designed for representing simple data structures, often used in URLs. The current version is 0.2.1. The library is largely feature-complete for the Rison specification and has a low release cadence.
Warnings
- gotcha Rison is not JSON. Its syntax and supported data types differ significantly. Direct mental mapping from JSON to Rison often leads to parsing errors or unexpected output. For example, objects use parentheses `()` instead of curly braces `{}`, and unquoted identifiers are common.
- gotcha The `prison` library has not been updated since August 2021 (v0.2.1). While stable and functional for the existing Rison specification, new Python features, performance optimizations, or edge-case bug fixes are unlikely to be implemented.
- gotcha Deserializing Rison data from untrusted sources with `prison.loads()` carries inherent security risks. While Rison's simplicity mitigates some complex attack vectors found in formats like YAML or Pickle, malicious input could still lead to resource exhaustion (e.g., deep nesting) or unexpected data structures.
Install
-
pip install prison
Imports
- loads
from prison import loads
- dumps
from prison import dumps
Quickstart
import prison
data = {'name': 'Alice', 'age': 30, 'tags': ['dev', 'python']}
# Encode Python dict to Rison string
rison_string = prison.dumps(data)
print(f"Encoded Rison: {rison_string}")
# Expected: (name:Alice,age:30,tags:!(dev,python))
# Decode Rison string back to Python dict
decoded_data = prison.loads(rison_string)
print(f"Decoded data: {decoded_data}")
# Expected: {'name': 'Alice', 'age': 30, 'tags': ['dev', 'python']}