Skip to main content

🌱 - clod: CLass mODule! Give your module the power of an object - 🌱

_Give your module the power of an object, with clod (and save a little typing too)._

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

clod is a tiny library that solves both these issues in one line of code, by extending a module with the methods and members of a Python object.

This is extremely handy for modules that primarily do one thing.

EXAMPLE: Make a module callable

# In your_module.py
import clod

A_CONSTANT = 23

@clod
def a_function(*args, **kwargs):
    print('a function!')
    return args, kwargs


# Test at the command line
>>> import your_module

>>> your_module(2, 3, a=5)
a function!
(2, 3), {'a': 5}

>>> assert your_module.A_CONSTANT == 23

EXAMPLE: Make a module look like an object

# In your_module.py
import clod

A_CONSTANT = 23

clod(list(), __name__)

# Test at the command line
>>> import your_module

>>> assert your_module == []

>>> assert your_module.A_CONSTANT == 23

>>> your_module.extend(range(3))

>>> print(your_module)
[0, 1, 2]

API

clod.clod(extension=None, name=None, properties=None, omit=None)

(clod.py, 96-177)

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, first to the extension, and then to the original module.

clod can also be used as a decorator, both with and without parameters.

ARGUMENTS
extension

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

name

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

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

properties

There is little need to use this argument.

Properties in this list are copied directly from the module into the custom class - they do not get overridden by the extension.

If properties is None, it defaults to clod.MODULE_PROPERTIES which seems to work well a lot of the time

omit

There is little need to use this argument.

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

(automatically generated by doks on 2020-07-18T15:46:33.018839)

Metadata

Release files for clod 0.10.0

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

Source distribution (sdist)

Source distribution for clod 0.10.0
File Size Uploaded Provenance Actions
clod-0.10.0.tar.gz 3.9 kB Without provenance Details for clod-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clod 0.10.0
File Interpreter ABI Platform Actions
clod-0.10.0-py3-none-any.whl Python 3 none any Details for clod-0.10.0-py3-none-any.whl

Total release size: 10.7 kB

Release files / clod-0.10.0.tar.gz

Download URL clod-0.10.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70c7825b4582ff2e0f4749bb80edc1ce277df5562e33f93b34c95b29aa5075da
BLAKE2b-256 checksum
How to use checksums
d72abf402d9b523543838da56f02f1f495213c7d7217ce8673097fea1c145aef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/18.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1

Release files / clod-0.10.0-py3-none-any.whl

Download URL clod-0.10.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca321cee22ed93192b3931ba84394c55649266801fd8c2fcaff665d47197d5e2
BLAKE2b-256 checksum
How to use checksums
7cf577ce76640b41db0e6987834842ec126a87f0bd92bffc1d0853191f7094ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/18.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.1

Security for clod 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files No provenance

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