Kompot exposes a serialization mechanism for Python builtins and Anvil portable classes.
Kompot provides wrappers for
@anvil.server.callable to take advantage of
the enhanced serialization between client and server calls.
Wikipedia on kompot:
In 1885, Lucyna Ćwierczakiewiczowa wrote in a recipe book that kompot preserved fruit so well it seemed fresh
In addition to standard JSONable types, kompot supports the following builtins:
dict objects will preserve their order and keys can be arbitrary.
type objects registered with kompot can also be serialized.
All portable classes that kompot can serialize must be registered by calling
from anvil_labs import kompot import anvil.server @anvil.server.portable_class class Foo: ... kompot.register(Foo)
(kompot.register can also be used as a decorator)
Serialize an arbitrary object into a JSONable object.
If kompot does not know how to handle the object, it will be left untouched.
Kompot does not know how to handle objects like:
anvil table rows
We leave Anvil to serialize these objects when calling the server.
serializebut will throw a
SerializationErrorif there are any unhandled objects.
preservefor storing an object as a simple object.
serializefor sending an object from the client to the server.
Reconstruct an object from the output of
- call(fn_name, *args, **kws)
- call_s(fn_name, *args, **kws)
- call_async(fn_name, *args, **kws)
Use inplace of
Kompot will serialize the args and kws and reconstruct the returned value.
The server function must be decorated with
Use inplace of
Kompot will reconstruct the serialized args and kws, call the original function and then serialize the return value.
Must be combined with
A context manager for batching calls
from anvil_labs import kompot with kompot.batch_call(silent=True) as c: c.call("foo", x=1) c.call("bar", 42) foo_result, bar_result = c.result