Proxy helpers
% start main % start synopsis
This module provides proxy helpers for serializing and deserializing objects across process boundaries or network connections. It includes:
- Transparent proxy objects that can be serialized and reconstructed
- Object registration and name mapping for proxied objects
- Data-carrying proxies (DProxy) for including object state
- Integration with CBOR, msgpack, and other serialization formats
% end synopsis
Usage
Basic proxy registration
from moat.lib.proxy import name2obj, obj2name, Proxy
# Register a class for proxying
class MyService:
def do_something(self):
return "result"
# Register the class with a name
name2obj("myapp.MyService", MyService)
# Get the proxy name for an object
service = MyService()
proxy_name = obj2name(service) # Returns "myapp.MyService"
Using proxies
from moat.lib.proxy import as_proxy, get_proxy
# Create a proxy reference to an object
obj = MyService()
proxy = as_proxy(obj) # Returns a Proxy object
# Later, retrieve the original object
original = get_proxy(proxy) # Returns the MyService instance
Data-carrying proxies (DProxy)
from moat.lib.proxy import DProxy
class MyData(DProxy):
"""A proxy that includes object state"""
def __init__(self, value):
self.value = value
def __reduce__(self):
# Define how to serialize the object
return (self.__class__, (self.value,))
# The object can be serialized with its state
data = MyData(42)
# When serialized and deserialized, the value is preserved
Working with serialization
from moat.lib.proxy import wrap_obj, unwrap_obj
# Serialize an object for transmission
class MyObject:
pass
name2obj("myapp.MyObject", MyObject)
obj = MyObject()
# Wrap for serialization
wrapped = wrap_obj(obj) # Creates a serializable representation
# Later, unwrap to reconstruct
reconstructed = unwrap_obj(wrapped) # Returns a MyObject instance
Integration with Serialization Formats
This module integrates with MoaT's serialization libraries:
- CBOR:
moat.lib.codec.cbor - Msgpack:
moat.lib.codec.msgpack - YAML: Supports proxy references in configuration files
% end main
Metadata
Release files for moat-lib-proxy 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| moat_lib_proxy-0.1.3.tar.gz | 9.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| moat_lib_proxy-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.4 kB
Release files / moat_lib_proxy-0.1.3.tar.gz
| Download URL | moat_lib_proxy-0.1.3.tar.gz |
|---|---|
| Size | 9.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4db049816585941df686102f1813107ea8b295cc92d2ec233cd12513dc6c130
|
|
BLAKE2b-256 checksum How to use checksums |
5837784f31460b67ca25f47db2d0bb8f310dd24ec93616aef193d91e56957077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / moat_lib_proxy-0.1.3-py3-none-any.whl
| Download URL | moat_lib_proxy-0.1.3-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
77f420545f4770d17d287c9e03396c99781c27292ba49a008506f325af346d6b
|
|
BLAKE2b-256 checksum How to use checksums |
79a53dedac2901e8f5d9f408b3b9e845eb5be640575d2162437c6881a665acdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|