{"id":6782,"library":"proxy-tools","title":"Proxy Tools","description":"The `proxy-tools` library provides a simple yet useful proxy implementation for Python, based on the Gang of Four (GoF) design pattern. It was lovingly extracted from the `werkzeug` project to be applicable outside the web context, for example, to enable `@property` like behavior on modules. The current version is 0.1.0, with its last release in 2014, suggesting a maintenance or inactive release cadence. [4, 8]","status":"maintenance","version":"0.1.0","language":"en","source_language":"en","source_url":"http://github.com/jtushman/proxy_tools","tags":["proxy","delegation","metaprogramming","design-pattern","python2"],"install":[{"cmd":"pip install proxy-tools","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"Proxy","correct":"from proxy_tools import Proxy"},{"symbol":"module_property","correct":"from proxy_tools import module_property"}],"quickstart":{"code":"from proxy_tools import module_property\n\n# Example: Simulating a 'current_user' on a module\n# In a real application, 'request' and 'User' would be defined elsewhere.\n# For this example, we'll mock them.\n\nclass MockUser:\n    def __init__(self, user_id):\n        self.id = user_id\n        self.name = f\"User_{user_id}\"\n\n    def __repr__(self):\n        return f\"<MockUser id={self.id}, name='{self.name}'>\"\n\nclass MockRequest:\n    def __init__(self, user_id):\n        self.user_id = user_id\n\ndef get_current_user_from_request(request_obj):\n    # Simulate fetching user from a request context\n    return MockUser.find_by_id(request_obj.user_id)\n\n# Patch MockUser to have a find_by_id method for the example\nMockUser.find_by_id = lambda uid: MockUser(uid)\n\n# Create a mock request object for the context\nmock_request = MockRequest(user_id=123)\n\n# Define a module-level property using module_property decorator\n# This assumes a mechanism to get the current request, e.g., from a thread-local storage.\n# For this quickstart, we'll directly use the mock_request in a closure.\n\nclass _ModuleContext:\n    current_request = None\n\n@module_property\ndef current_user():\n    # In a real app, you'd get the request from a global/thread-local context\n    if _ModuleContext.current_request:\n        return get_current_user_from_request(_ModuleContext.current_request)\n    return None # Or raise an error if no request context\n\n# Set the mock request in the context for demonstration\n_ModuleContext.current_request = mock_request\n\n# Now, access current_user as if it were a module attribute\nprint(f\"Current user via module_property: {current_user}\")\n\n# Demonstrate Proxy class (more generic use case)\ndef greet_target(name):\n    return f\"Hello, {name}!\"\n\nclass MyProxy(Proxy):\n    def __init__(self, target):\n        super().__init__(target)\n\n    def __call__(self, *args, **kwargs):\n        print(f\"Proxying call to: {self.__wrapped__.__name__} with args: {args}, kwargs: {kwargs}\")\n        return super().__call__(*args, **kwargs)\n\nmy_proxy_instance = MyProxy(greet_target)\nprint(my_proxy_instance('World'))","lang":"python","description":"The `proxy-tools` library provides a `Proxy` class for general object delegation and a `module_property` decorator to enable `@property`-like behavior on modules. The quickstart demonstrates how to define a `module_property` that can dynamically return a value (e.g., a current user based on a request context) and a basic `Proxy` usage with a wrapped callable. [8]"},"warnings":[{"fix":"Review the source code for Python 2 specific constructs (e.g., `print` statements, `long` type, `__cmp__`, `next()`) and manually port them to Python 3 compatible alternatives. Consider alternative, actively maintained libraries for proxying or module-level properties if a direct port is too complex.","message":"The library was last released in 2014 and explicitly classified for Python 2.7. It is highly likely that it contains Python 2 specific syntax or assumptions that are incompatible with Python 3+. Direct use in modern Python 3 environments may lead to syntax errors or runtime issues.","severity":"breaking","affected_versions":"< 0.1.0"},{"fix":"Evaluate the stability and criticality of its use in your project. If you encounter bugs or require new features, you will need to fork the repository and maintain the changes yourself. For new projects, it is strongly recommended to seek actively maintained alternatives.","message":"The project appears to be unmaintained. The last PyPI release was in May 2014, and the GitHub repository has seen no significant activity since the same period. This means there will be no official updates, bug fixes, or compatibility improvements for newer Python versions or emerging issues.","severity":"gotcha","affected_versions":"All versions (0.1.0 and earlier)"},{"fix":"Thoroughly test proxy implementations, especially in performance-critical paths. Understand the `__getattr__`, `__setattr__`, `__delattr__`, and `__call__` methods and how they interact with the wrapped object. Ensure that proxying logic explicitly handles attributes it intends to manage, delegating others correctly.","message":"The `Proxy` class and `module_property` rely on Python's introspection and attribute access mechanisms. Misuse, especially with complex object graphs or dynamic attribute resolution, could lead to unexpected behavior, infinite recursion, or performance overhead if not carefully managed.","severity":"gotcha","affected_versions":"All versions (0.1.0 and earlier)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}