Skip to main content

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

Release files for moat-lib-proxy 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moat-lib-proxy 0.1.2
File Size Uploaded
moat_lib_proxy-0.1.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moat-lib-proxy 0.1.2
File Interpreter ABI Platform
moat_lib_proxy-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.8 kB

Release files / moat_lib_proxy-0.1.2.tar.gz

Download URL moat_lib_proxy-0.1.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
09fab7a532e0dece32636f772a6f1ef2193f5af5e6d249edb527ae13c88cc64b
BLAKE2b-256 checksum
How to use checksums
7a96a2d6a5dc17e3b77c1fc03cb91ec46dff321b487e1ca1778c59730963b21b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / moat_lib_proxy-0.1.2-py3-none-any.whl

Download URL moat_lib_proxy-0.1.2-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dad20d3b7e6f40cc49e3e758aa97e11ae9108c22c772221196e978dd9384efe4
BLAKE2b-256 checksum
How to use checksums
30cf8e1e8e66acad535a847b2b697798683903c172e0fc3a5a0236dbec8b333d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page