Skip to main content

Create and recursively fill a temporary directory

Project description

Callable modules! Indexable modules!?

Ever wanted to call a module directly, or index it? Or just sick of seeing from foo import foo in your examples?

Give your module the awesome power of an object, or maybe just save a little typing, with xmod.

xmod is a tiny library that extends a module to do things that normally only a class could do - handy for modules that “just do one thing”.

EXAMPLE: Make a module callable as a function

# In
import xmod

def a_function():
    return 'HERE!!'

# Test at the command line
>>> import your_module
>>> your_module()

EXAMPLE: Make a module look like an object

# In
import xmod

xmod(list(), __name__)

# Test at the command line
>>> import your_module
>>> assert your_module == []
>>> your_module.extend(range(3))
>>> print(your_module)
[0, 1, 2]




(, 72-180)

Extend the system module at name with any Python object.

The original module is replaced in sys.modules by a proxy class which delegates attributes to the original module, and then adds attributes from the extension.

In the most common use case, the extension is a callable and only the __call__ method is delegated, so xmod can also be used as a decorator, both with and without parameters.


The object whose methods and properties extend the namespace. This includes magic methods like __call__ and __getitem__.


The name of this symbol in sys.modules. If this is None then xmod will use extension.__module__.

This only needs to be be set if extension is _not_ a function or class defined in the module that’s being extended.

If the name argument is given, it should almost certainly be __name__.


If False, just add extension as a callable.

If True, extend the module with all members of extension.

If None, the default, add the extension if it’s a callable, otherwise extend the module with all members of extension.


If True, the attributes on the proxy are mutable and write through to the underlying module. If False, the default, attributes on the proxy cannot be changed.


A list of methods _not_ to delegate from the proxy to the extension.

If omit is None, it defaults to xmod.OMIT, which seems to work well.

(automatically generated by doks on 2020-11-16T17:28:35.769504)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmod-1.3.2.tar.gz (7.0 kB view hashes)

Uploaded source

Built Distribution

xmod-1.3.2-py3-none-any.whl (5.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page