{"id":2362,"library":"xmod","title":"Xmod: Turn any object into a module","description":"Xmod is a tiny Python library designed to transform any Python object into a module. This allows for modules to be callable, indexable, or to expose an object's methods and properties directly, reducing boilerplate code. It is currently at version 1.9.0 (released February 3, 2026) and maintains an active development status with frequent minor updates and dependency bumps.","status":"active","version":"1.9.0","language":"en","source_language":"en","source_url":"https://github.com/rec/xmod","tags":["module","dynamic","object-oriented","decorator","runtime"],"install":[{"cmd":"pip install xmod","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"xmod","correct":"import xmod"}],"quickstart":{"code":"# In your_module.py\nimport xmod\n\n@xmod\ndef greet():\n    return 'Hello from your_module!'\n\n# To test in another script or interpreter:\n# import your_module\n# print(your_module())\n# Expected output: Hello from your_module!","lang":"python","description":"The most common usage is to decorate a function within a module to make the module itself callable. This example demonstrates making the module 'your_module' callable, returning a greeting."},"warnings":[{"fix":"For typical module extension, ensure `xmod(..., name=__name__)` is used. Only deviate if you have an advanced use case requiring specific `sys.modules` manipulation.","message":"When explicitly providing the `name` argument to `xmod()`, it should almost always be set to `__name__`. Using a different string can lead to unexpected module aliasing or inconsistent behavior within `sys.modules`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If an exception related to `functools.partial` is raised, adjust your approach as indicated by the error message. Consider alternative partial application techniques or consult `xmod`'s documentation for compatible patterns.","message":"Combining `xmod` with `functools.partial` can sometimes lead to unexpected behavior. Since version `1.3.2`, `xmod` will raise a clear exception if `functools.partial` is used in a way it doesn't support, to prevent silent failures.","severity":"gotcha","affected_versions":"All versions (explicit error in >=1.3.2)"},{"fix":"Be selective about attribute exposure; prefer `full=False` and explicitly expose only what's necessary. Understand the implications of mutable module state before setting `mutable=True` and favor immutable extensions where possible.","message":"Using `xmod(..., full=True)` extends the module with *all* members of the extension object, which might unintentionally overwrite existing module attributes. Additionally, `xmod(..., mutable=True)` allows runtime modification of the module's attributes via the `xmod` proxy, potentially introducing hard-to-debug state changes.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}