renew

raw JSON →
0.5.4 verified Sat May 09 auth: no python maintenance

A Python library for reproducible object serialization in a 100% Pythonic format. It provides a consistent way to represent Python objects, enabling easy reconstruction and debugging. Current version: 0.5.4. Release cadence: low, with no recent releases.

pip install renew
error ImportError: No module named 'renew'
cause Library not installed or installed with different name.
fix
Run 'pip install renew' in your environment.
error AttributeError: module 'renew' has no attribute 'renew'
cause Import statement used 'from renew import renew' but the module is imported as 'import renew'.
fix
Correct import: 'import renew' then use 'renew.renew()'.
error TypeError: can't pickle ... objects
cause renew works via __init__ signature analysis; objects with complex constructors or non-standard attributes cannot be serialized.
fix
Simplify the object's __init__ to directly assign all attributes from arguments. For complex objects, consider using dill or pickle.
deprecated Library is in maintenance mode; no updates since 2018. May not support newer Python versions (3.9+).
fix Consider alternatives like dill or cloudpickle for serialization.
gotcha renew.renew() only works for objects with simple __init__ signatures; complex objects (e.g., with non-trivial constructor logic) may fail or produce incorrect code.
fix Ensure your class has a simple __init__ that directly assigns arguments to attributes. Test serialization on your objects.
gotcha The rebuild() function uses eval internally; it can execute arbitrary code from the serialized string. Only use on trusted data.
fix Never rebuild untrusted serialized data. Use a sandbox or avoid using rebuild if data origin is not secure.

Basic usage: serialize an object with renew.renew() and reconstruct with rebuild().

import renew
from renew import rebuild

# Define a simple class
class MyClass:
    def __init__(self, x):
        self.x = x
    def __repr__(self):
        return f"MyClass({self.x})"

# Create an object
obj = MyClass(42)

# Renew the object (serialize to Python source code)
renewed_code = renew.renew(obj)
print(renewed_code)
# Output: something like "MyClass(42)"

# Rebuild from the code
new_obj = rebuild(renewed_code)
print(new_obj)
# Output: MyClass(42)