Registry / serialization / prison

prison

JSON →
library0.2.1pypypi✓ verified 27d ago

"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.

pip install prison
INSTALL
IMPORT
SIG · PRISON
P
prison
serializationpythonv0.2.1
Install
1.6s avg
Import
13ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.014s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.012s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

loads
from prison import loads
dumps
from prison import dumps

Demonstrates encoding a Python dictionary to a Rison string and then decoding it back. Rison is optimized for URL-safe representation of simple data structures.

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']}
Debug
Known issues
gotchaRison 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.
fix
Familiarize yourself with the Rison specification, especially regarding object and array delimiters, string quoting rules, and special values like `!n` for null.
affects: All versions
gotchaThe `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.
fix
Be aware that the library's development is quiescent. For mission-critical applications, consider a review of its source code or potential maintenance forks if advanced features or active support become necessary.
affects: 0.2.1 and potentially future versions if no updates occur
gotchaDeserializing 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.
fix
Always validate or sanitize Rison input from untrusted sources. Limit the depth of nested structures and verify data types if parsing user-supplied data.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prison'
The 'prison' library is not installed in the Python environment where the code is being executed.
fix
pip install prison
prison.decoder.ParserException: missing ', '
The input string provided to `prison.loads()` is not valid Rison, often due to improper escaping of special characters or malformed Rison syntax.
fix
Ensure the Rison string conforms to the Rison specification. If constructing the string manually, be mindful of characters like '!', '(', ')', ':', and ',' and use `prison.dumps()` to serialize Python objects into valid Rison. For example, `prison.loads("(key:value)")` for an object, or `prison.loads("!(item1,item2)")` for an array.
rison decoder error: missing ':'
The input Rison string is syntactically incorrect, specifically missing a colon where a key-value pair is expected in an object, or other structural issues.
fix
Verify that your Rison string adheres to the correct syntax. For object keys, ensure they are followed by a colon and a value, e.g., `(key:value)`. Use `prison.dumps()` to reliably generate correct Rison strings.
AttributeError: module 'prison' has no attribute 'dumps'
This error occurs when attempting to access a function or attribute, such as `dumps` or `loads`, from the 'prison' module incorrectly, often by trying to import them directly when they are intended to be accessed as methods of the imported module itself.
fix
Import the 'prison' module and access its functions as attributes, e.g., `import prison` then `prison.dumps()` or `prison.loads()`.
Upgrade
Version history
0.2.1latest on PyPI · released Aug 26, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
18
Resources
prison — pip install prison · libregistry